From 3d61c6495dd46e0fc8c1b3585e3f0dc2f95f1892 Mon Sep 17 00:00:00 2001 From: Arthurdw Date: Sun, 14 Aug 2022 18:13:59 +0200 Subject: [PATCH] :sparkles: Added benchmark scripts --- README.md | 12 ++++++- ffly-rs/Cargo.toml | 7 ++++ ffly-rs/examples/push_it.rs | 52 +++++++++++++++++++++++++++ ffly-rs/examples/push_it_redis.rs | 54 ++++++++++++++++++++++++++++ ffly-rs/examples/push_it_skytable.rs | 53 +++++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 ffly-rs/examples/push_it.rs create mode 100644 ffly-rs/examples/push_it_redis.rs create mode 100644 ffly-rs/examples/push_it_skytable.rs diff --git a/README.md b/README.md index 29ccd3c..519e191 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,22 @@ sessions throughout the platform. **AUR:** `$ paru -S ffly` +## Performance comparison + +| Database | ops | +| ------------------------------------------------ | ---- | +| Firefly | 167k | +| [Skytable](https://github.com/skytable/skytable) | 143k | +| [Redis](https://github.com/redis/redis) | 67k | + +_(`push_it` scripts can be found in `ffly-rs/examples/`)_ + ## Future plans - [x] Add clap-rs to make the config dynamic +- [x] Make benchmarks - [ ] Automatic cargo & AUR release - [ ] Add a docker image -- [ ] Make benchmarks ## Query Language diff --git a/ffly-rs/Cargo.toml b/ffly-rs/Cargo.toml index 5ff2c80..c75290e 100644 --- a/ffly-rs/Cargo.toml +++ b/ffly-rs/Cargo.toml @@ -8,3 +8,10 @@ license = "MIT" [dependencies] tokio = { version = "1.20.1", features = ["full"] } + +[dev-dependencies] +fastrand = "1.8.0" +futures = "0.3.23" +redis = "0.21.5" +skytable = { version = "0.7.1", features = ["tokio", "aio"] } +uuid = { version = "1.1.2", features = ["v4"] } diff --git a/ffly-rs/examples/push_it.rs b/ffly-rs/examples/push_it.rs new file mode 100644 index 0000000..b1a8ac3 --- /dev/null +++ b/ffly-rs/examples/push_it.rs @@ -0,0 +1,52 @@ +/// Lets try to push to the limits of Firefly +/// ffly -c 0 -s 300 +/// cargo run --release --example push_it +/// +/// Performance on a 16gb - Intel i7-10510U (8 cores @ 4.9GHz) +/// ~167k ops/sec +use ffly_rs::FireflyStream; +use std::{iter::repeat_with, time::Instant}; +use uuid::Uuid; + +static FIREFLY_ADDR: &'static str = "127.0.0.1:46600"; + +static THREADS: usize = 10; +static REQUESTS_TOTAL: usize = 1_000_000; + +async fn add_records(amount: usize) { + let firefly = FireflyStream::connect(FIREFLY_ADDR).await.unwrap(); + let user = Uuid::new_v4().to_string(); + + for _ in 0..amount { + let key: String = repeat_with(fastrand::alphanumeric).take(64).collect(); + + firefly.new(&key, &user).await.expect("Query failed!") + } +} + +#[tokio::main] +async fn main() { + let requests_per_thread = REQUESTS_TOTAL / THREADS; + let mut futures = Vec::with_capacity(THREADS); + + for _ in 0..THREADS { + futures.push(add_records(requests_per_thread)); + } + + println!( + "Starting to send {} requests per thread. ({} threads, {} requests in total)", + requests_per_thread, THREADS, REQUESTS_TOTAL + ); + let start = Instant::now(); + futures::future::join_all(futures).await; + println!( + "Created {} new records by using {} connections in {:?}.", + REQUESTS_TOTAL, + THREADS, + start.elapsed() + ); + println!( + "This comes down to {} requests per second.", + REQUESTS_TOTAL / start.elapsed().as_secs() as usize + ); +} diff --git a/ffly-rs/examples/push_it_redis.rs b/ffly-rs/examples/push_it_redis.rs new file mode 100644 index 0000000..2fa891c --- /dev/null +++ b/ffly-rs/examples/push_it_redis.rs @@ -0,0 +1,54 @@ +/// Script to compare the results of firefly with an identical redis script. +/// redis - default config from paru +/// cargo run --release --example push_it_redis +/// +/// Performance on a 16gb - Intel i7-10510U (8 cores @ 4.9GHz) +/// ~67k ops/sec +use std::{iter::repeat_with, time::Instant}; +use uuid::Uuid; + +static THREADS: usize = 10; +static REQUESTS_TOTAL: usize = 1_000_000; + +async fn add_records(amount: usize) { + let client = redis::Client::open("redis://127.0.0.1/").unwrap(); + let mut con = client.get_connection().unwrap(); + let user = Uuid::new_v4().to_string(); + + for _ in 0..amount { + let key: String = repeat_with(fastrand::alphanumeric).take(64).collect(); + + let _: () = redis::cmd("SET") + .arg(&key) + .arg(&user) + .query(&mut con) + .unwrap(); + } +} + +#[tokio::main] +async fn main() { + let requests_per_thread = REQUESTS_TOTAL / THREADS; + let mut futures = Vec::with_capacity(THREADS); + + for _ in 0..THREADS { + futures.push(add_records(requests_per_thread)); + } + + println!( + "Starting to send {} requests per thread. ({} threads, {} requests in total)", + requests_per_thread, THREADS, REQUESTS_TOTAL + ); + let start = Instant::now(); + futures::future::join_all(futures).await; + println!( + "Created {} new records by using {} connections in {:?}.", + REQUESTS_TOTAL, + THREADS, + start.elapsed() + ); + println!( + "This comes down to {} requests per second.", + REQUESTS_TOTAL / start.elapsed().as_secs() as usize + ); +} diff --git a/ffly-rs/examples/push_it_skytable.rs b/ffly-rs/examples/push_it_skytable.rs new file mode 100644 index 0000000..a10632e --- /dev/null +++ b/ffly-rs/examples/push_it_skytable.rs @@ -0,0 +1,53 @@ +/// Script to compare the results of firefly with an identical skytable script. +/// skytable - default +/// cargo run --release --example push_it_skytable +/// +/// Performance on a 16gb - Intel i7-10510U (8 cores @ 4.9GHz) +/// ~143 ops/sec +use skytable::actions::AsyncActions; +use std::{iter::repeat_with, time::Instant}; +use uuid::Uuid; + +static THREADS: usize = 10; +static REQUESTS_TOTAL: usize = 1_000_000; + +async fn add_records(amount: usize) { + let mut skytable = skytable::AsyncConnection::new("127.0.0.1", 2003) + .await + .unwrap(); + + let user = Uuid::new_v4().to_string(); + + for _ in 0..amount { + let key: String = repeat_with(fastrand::alphanumeric).take(64).collect(); + + skytable.set(&key, &user).await.unwrap(); + } +} + +#[tokio::main] +async fn main() { + let requests_per_thread = REQUESTS_TOTAL / THREADS; + let mut futures = Vec::with_capacity(THREADS); + + for _ in 0..THREADS { + futures.push(add_records(requests_per_thread)); + } + + println!( + "Starting to send {} requests per thread. ({} threads, {} requests in total)", + requests_per_thread, THREADS, REQUESTS_TOTAL + ); + let start = Instant::now(); + futures::future::join_all(futures).await; + println!( + "Created {} new records by using {} connections in {:?}.", + REQUESTS_TOTAL, + THREADS, + start.elapsed() + ); + println!( + "This comes down to {} requests per second.", + REQUESTS_TOTAL / start.elapsed().as_secs() as usize + ); +}