-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsimple_stateless.rs
39 lines (32 loc) · 1.04 KB
/
simple_stateless.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use rlt::{
cli::BenchCli,
IterReport, Status, {IterInfo, StatelessBenchSuite},
};
use tokio::time::{Duration, Instant};
#[derive(Clone)]
struct SimpleBench;
#[async_trait]
impl StatelessBenchSuite for SimpleBench {
async fn bench(&mut self, info: &IterInfo) -> Result<IterReport> {
let t = Instant::now();
// simulate some work
tokio::time::sleep(Duration::from_micros(info.runner_seq % 30)).await;
let duration = t.elapsed();
// simulate status code
let status = match info.worker_seq % 10 {
8..=10 => Status::server_error(500),
6..=7 => Status::client_error(400),
_ => Status::success(200),
};
// simulate items processed in current iteration
let items = info.worker_seq % 100;
Ok(IterReport { duration, status, bytes: items * 1024, items })
}
}
#[tokio::main]
async fn main() -> Result<()> {
rlt::cli::run(BenchCli::parse(), SimpleBench).await
}