pub struct StressRun { /* private fields */ }Expand description
Configuration for a stress run.
§Example
use dev_stress::StressRun;
let run = StressRun::new("hot_path").iterations(1_000).threads(4);
assert_eq!(run.iterations_planned(), 1_000);
assert_eq!(run.threads_planned(), 4);Implementations§
Source§impl StressRun
impl StressRun
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Begin building a stress run with a stable name.
Examples found in repository?
26fn main() {
27 let run = StressRun::new("trivial_add").iterations(100_000).threads(4);
28
29 println!(
30 "configured: {} iterations across {} threads",
31 run.iterations_planned(),
32 run.threads_planned()
33 );
34
35 let result = run.execute(&TrivialAdd);
36
37 println!("name: {}", result.name);
38 println!("iterations: {}", result.iterations);
39 println!("threads: {}", result.threads);
40 println!("total_elapsed: {:?}", result.total_elapsed);
41 println!("ops_per_sec: {:.0}", result.ops_per_sec());
42 println!("thread_time_cv: {:.4}", result.thread_time_cv());
43}Sourcepub fn iterations(self, n: usize) -> Self
pub fn iterations(self, n: usize) -> Self
Total iterations across all threads.
Examples found in repository?
26fn main() {
27 let run = StressRun::new("trivial_add").iterations(100_000).threads(4);
28
29 println!(
30 "configured: {} iterations across {} threads",
31 run.iterations_planned(),
32 run.threads_planned()
33 );
34
35 let result = run.execute(&TrivialAdd);
36
37 println!("name: {}", result.name);
38 println!("iterations: {}", result.iterations);
39 println!("threads: {}", result.threads);
40 println!("total_elapsed: {:?}", result.total_elapsed);
41 println!("ops_per_sec: {:.0}", result.ops_per_sec());
42 println!("thread_time_cv: {:.4}", result.thread_time_cv());
43}Sourcepub fn threads(self, n: usize) -> Self
pub fn threads(self, n: usize) -> Self
Number of OS threads to run concurrently. Minimum is 1.
Examples found in repository?
26fn main() {
27 let run = StressRun::new("trivial_add").iterations(100_000).threads(4);
28
29 println!(
30 "configured: {} iterations across {} threads",
31 run.iterations_planned(),
32 run.threads_planned()
33 );
34
35 let result = run.execute(&TrivialAdd);
36
37 println!("name: {}", result.name);
38 println!("iterations: {}", result.iterations);
39 println!("threads: {}", result.threads);
40 println!("total_elapsed: {:?}", result.total_elapsed);
41 println!("ops_per_sec: {:.0}", result.ops_per_sec());
42 println!("thread_time_cv: {:.4}", result.thread_time_cv());
43}Sourcepub fn track_latency(self, rate: usize) -> Self
pub fn track_latency(self, rate: usize) -> Self
Track per-operation latency, sampling 1 of every rate iterations.
rate = 1 records every iteration; rate = 100 records 1% of
iterations. Lower rates lower memory and overhead at the cost
of percentile precision.
§Example
use dev_stress::StressRun;
let run = StressRun::new("hot").iterations(10_000).threads(2)
.track_latency(10); // 10% sample rate
assert_eq!(run.iterations_planned(), 10_000);Sourcepub fn target_ops_per_sec(self, total_rate: f64) -> Self
pub fn target_ops_per_sec(self, total_rate: f64) -> Self
Cap the workload at approximately total_rate ops per second
(across all threads).
Implemented as a per-thread sleep based on observed elapsed time vs. ideal scheduling. Sleep precision varies by OS; for very high target rates (e.g. > 10k ops/sec/thread) the actual rate may be lower than the target due to sleep granularity.
§Example
use dev_stress::StressRun;
// Cap to ~1000 ops/sec total across 4 threads = 250 per thread.
let run = StressRun::new("rate-limited")
.iterations(500)
.threads(4)
.target_ops_per_sec(1000.0);
assert_eq!(run.threads_planned(), 4);Sourcepub fn iterations_planned(&self) -> usize
pub fn iterations_planned(&self) -> usize
The configured iteration count.
Examples found in repository?
26fn main() {
27 let run = StressRun::new("trivial_add").iterations(100_000).threads(4);
28
29 println!(
30 "configured: {} iterations across {} threads",
31 run.iterations_planned(),
32 run.threads_planned()
33 );
34
35 let result = run.execute(&TrivialAdd);
36
37 println!("name: {}", result.name);
38 println!("iterations: {}", result.iterations);
39 println!("threads: {}", result.threads);
40 println!("total_elapsed: {:?}", result.total_elapsed);
41 println!("ops_per_sec: {:.0}", result.ops_per_sec());
42 println!("thread_time_cv: {:.4}", result.thread_time_cv());
43}Sourcepub fn threads_planned(&self) -> usize
pub fn threads_planned(&self) -> usize
The configured thread count.
Examples found in repository?
26fn main() {
27 let run = StressRun::new("trivial_add").iterations(100_000).threads(4);
28
29 println!(
30 "configured: {} iterations across {} threads",
31 run.iterations_planned(),
32 run.threads_planned()
33 );
34
35 let result = run.execute(&TrivialAdd);
36
37 println!("name: {}", result.name);
38 println!("iterations: {}", result.iterations);
39 println!("threads: {}", result.threads);
40 println!("total_elapsed: {:?}", result.total_elapsed);
41 println!("ops_per_sec: {:.0}", result.ops_per_sec());
42 println!("thread_time_cv: {:.4}", result.thread_time_cv());
43}Sourcepub fn target_ops_per_sec_per_thread(&self) -> Option<f64>
pub fn target_ops_per_sec_per_thread(&self) -> Option<f64>
The configured per-thread target rate, if any.
Sourcepub fn execute<W>(&self, workload: &W) -> StressResult
pub fn execute<W>(&self, workload: &W) -> StressResult
Execute the run. Returns a result with timing statistics.
Examples found in repository?
26fn main() {
27 let run = StressRun::new("trivial_add").iterations(100_000).threads(4);
28
29 println!(
30 "configured: {} iterations across {} threads",
31 run.iterations_planned(),
32 run.threads_planned()
33 );
34
35 let result = run.execute(&TrivialAdd);
36
37 println!("name: {}", result.name);
38 println!("iterations: {}", result.iterations);
39 println!("threads: {}", result.threads);
40 println!("total_elapsed: {:?}", result.total_elapsed);
41 println!("ops_per_sec: {:.0}", result.ops_per_sec());
42 println!("thread_time_cv: {:.4}", result.thread_time_cv());
43}