|
| 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 | +} |
0 commit comments