crows_shared/
lib.rs

1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5pub trait ExecutorConfig {
6    fn split(&self, times: usize) -> Config;
7}
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
10pub enum Config {
11    ConstantArrivalRate(ConstantArrivalRateConfig),
12}
13
14impl Config {
15    pub fn split(&self, times: usize) -> Config {
16        match self {
17            Config::ConstantArrivalRate(config) => config.split(times),
18        }
19    }
20}
21
22#[derive(Serialize, Deserialize, Debug, Clone)]
23pub struct ConstantArrivalRateConfig {
24    pub duration: Duration,
25    pub rate: usize,
26    pub time_unit: Duration,
27    pub allocated_vus: usize,
28}
29
30impl ExecutorConfig for ConstantArrivalRateConfig {
31    fn split(&self, times: usize) -> Config {
32        let mut new_config = self.clone();
33
34        new_config.rate /= times;
35        // if someone uses low rate and a lot of workers we could end up
36        // with rate equal to zero
37        // TODO: should we worn that it's maybe not what someone wanted?
38        // rate of 1 per worker may make sense if someone is just trying to test
39        // requests from a lot of different locations, but if there is more workers
40        // than the value of rate it feels like a mistake not a deliberate thing
41        if new_config.rate == 0 {
42            new_config.rate = 1;
43        }
44
45        Config::ConstantArrivalRate(new_config)
46    }
47}
48
49impl Default for ConstantArrivalRateConfig {
50    fn default() -> Self {
51        Self {
52            duration: Default::default(),
53            rate: Default::default(),
54            time_unit: Duration::from_secs(1),
55            allocated_vus: Default::default(),
56        }
57    }
58}