Skip to content

Commit 3d61c64

Browse files
committed
✨ Added benchmark scripts
1 parent b0591a9 commit 3d61c64

File tree

5 files changed

+177
-1
lines changed

5 files changed

+177
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ sessions throughout the platform.
1616
**AUR:**
1717
`$ paru -S ffly`
1818

19+
## Performance comparison
20+
21+
| Database | ops |
22+
| ------------------------------------------------ | ---- |
23+
| Firefly | 167k |
24+
| [Skytable](https://github.com/skytable/skytable) | 143k |
25+
| [Redis](https://github.com/redis/redis) | 67k |
26+
27+
_(`push_it` scripts can be found in `ffly-rs/examples/`)_
28+
1929
## Future plans
2030

2131
- [x] Add clap-rs to make the config dynamic
32+
- [x] Make benchmarks
2233
- [ ] Automatic cargo & AUR release
2334
- [ ] Add a docker image
24-
- [ ] Make benchmarks
2535

2636
## Query Language
2737

ffly-rs/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ license = "MIT"
88

99
[dependencies]
1010
tokio = { version = "1.20.1", features = ["full"] }
11+
12+
[dev-dependencies]
13+
fastrand = "1.8.0"
14+
futures = "0.3.23"
15+
redis = "0.21.5"
16+
skytable = { version = "0.7.1", features = ["tokio", "aio"] }
17+
uuid = { version = "1.1.2", features = ["v4"] }

ffly-rs/examples/push_it.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/// Lets try to push to the limits of Firefly
2+
/// ffly -c 0 -s 300
3+
/// cargo run --release --example push_it
4+
///
5+
/// Performance on a 16gb - Intel i7-10510U (8 cores @ 4.9GHz)
6+
/// ~167k ops/sec
7+
use ffly_rs::FireflyStream;
8+
use std::{iter::repeat_with, time::Instant};
9+
use uuid::Uuid;
10+
11+
static FIREFLY_ADDR: &'static str = "127.0.0.1:46600";
12+
13+
static THREADS: usize = 10;
14+
static REQUESTS_TOTAL: usize = 1_000_000;
15+
16+
async fn add_records(amount: usize) {
17+
let firefly = FireflyStream::connect(FIREFLY_ADDR).await.unwrap();
18+
let user = Uuid::new_v4().to_string();
19+
20+
for _ in 0..amount {
21+
let key: String = repeat_with(fastrand::alphanumeric).take(64).collect();
22+
23+
firefly.new(&key, &user).await.expect("Query failed!")
24+
}
25+
}
26+
27+
#[tokio::main]
28+
async fn main() {
29+
let requests_per_thread = REQUESTS_TOTAL / THREADS;
30+
let mut futures = Vec::with_capacity(THREADS);
31+
32+
for _ in 0..THREADS {
33+
futures.push(add_records(requests_per_thread));
34+
}
35+
36+
println!(
37+
"Starting to send {} requests per thread. ({} threads, {} requests in total)",
38+
requests_per_thread, THREADS, REQUESTS_TOTAL
39+
);
40+
let start = Instant::now();
41+
futures::future::join_all(futures).await;
42+
println!(
43+
"Created {} new records by using {} connections in {:?}.",
44+
REQUESTS_TOTAL,
45+
THREADS,
46+
start.elapsed()
47+
);
48+
println!(
49+
"This comes down to {} requests per second.",
50+
REQUESTS_TOTAL / start.elapsed().as_secs() as usize
51+
);
52+
}

ffly-rs/examples/push_it_redis.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// Script to compare the results of firefly with an identical redis script.
2+
/// redis - default config from paru
3+
/// cargo run --release --example push_it_redis
4+
///
5+
/// Performance on a 16gb - Intel i7-10510U (8 cores @ 4.9GHz)
6+
/// ~67k ops/sec
7+
use std::{iter::repeat_with, time::Instant};
8+
use uuid::Uuid;
9+
10+
static THREADS: usize = 10;
11+
static REQUESTS_TOTAL: usize = 1_000_000;
12+
13+
async fn add_records(amount: usize) {
14+
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
15+
let mut con = client.get_connection().unwrap();
16+
let user = Uuid::new_v4().to_string();
17+
18+
for _ in 0..amount {
19+
let key: String = repeat_with(fastrand::alphanumeric).take(64).collect();
20+
21+
let _: () = redis::cmd("SET")
22+
.arg(&key)
23+
.arg(&user)
24+
.query(&mut con)
25+
.unwrap();
26+
}
27+
}
28+
29+
#[tokio::main]
30+
async fn main() {
31+
let requests_per_thread = REQUESTS_TOTAL / THREADS;
32+
let mut futures = Vec::with_capacity(THREADS);
33+
34+
for _ in 0..THREADS {
35+
futures.push(add_records(requests_per_thread));
36+
}
37+
38+
println!(
39+
"Starting to send {} requests per thread. ({} threads, {} requests in total)",
40+
requests_per_thread, THREADS, REQUESTS_TOTAL
41+
);
42+
let start = Instant::now();
43+
futures::future::join_all(futures).await;
44+
println!(
45+
"Created {} new records by using {} connections in {:?}.",
46+
REQUESTS_TOTAL,
47+
THREADS,
48+
start.elapsed()
49+
);
50+
println!(
51+
"This comes down to {} requests per second.",
52+
REQUESTS_TOTAL / start.elapsed().as_secs() as usize
53+
);
54+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/// Script to compare the results of firefly with an identical skytable script.
2+
/// skytable - default
3+
/// cargo run --release --example push_it_skytable
4+
///
5+
/// Performance on a 16gb - Intel i7-10510U (8 cores @ 4.9GHz)
6+
/// ~143 ops/sec
7+
use skytable::actions::AsyncActions;
8+
use std::{iter::repeat_with, time::Instant};
9+
use uuid::Uuid;
10+
11+
static THREADS: usize = 10;
12+
static REQUESTS_TOTAL: usize = 1_000_000;
13+
14+
async fn add_records(amount: usize) {
15+
let mut skytable = skytable::AsyncConnection::new("127.0.0.1", 2003)
16+
.await
17+
.unwrap();
18+
19+
let user = Uuid::new_v4().to_string();
20+
21+
for _ in 0..amount {
22+
let key: String = repeat_with(fastrand::alphanumeric).take(64).collect();
23+
24+
skytable.set(&key, &user).await.unwrap();
25+
}
26+
}
27+
28+
#[tokio::main]
29+
async fn main() {
30+
let requests_per_thread = REQUESTS_TOTAL / THREADS;
31+
let mut futures = Vec::with_capacity(THREADS);
32+
33+
for _ in 0..THREADS {
34+
futures.push(add_records(requests_per_thread));
35+
}
36+
37+
println!(
38+
"Starting to send {} requests per thread. ({} threads, {} requests in total)",
39+
requests_per_thread, THREADS, REQUESTS_TOTAL
40+
);
41+
let start = Instant::now();
42+
futures::future::join_all(futures).await;
43+
println!(
44+
"Created {} new records by using {} connections in {:?}.",
45+
REQUESTS_TOTAL,
46+
THREADS,
47+
start.elapsed()
48+
);
49+
println!(
50+
"This comes down to {} requests per second.",
51+
REQUESTS_TOTAL / start.elapsed().as_secs() as usize
52+
);
53+
}

0 commit comments

Comments
 (0)