pub struct WorkloadGenerator { /* private fields */ }Expand description
A Zipfian workload generator for cache benchmarking.
This structure generates a fixed set of random keys and samples them according to a Power Law distribution. This mimics real-world scenarios where a small subset of “hot” keys receives the majority of traffic.
Implementations§
Source§impl WorkloadGenerator
impl WorkloadGenerator
Sourcepub fn new(count: usize, skew: f64) -> Self
pub fn new(count: usize, skew: f64) -> Self
Creates a new workload with a specified number of unique keys and skew.
§Arguments
count- The number of unique logical keys in the workload universe.skew- The Zipfian exponent ($s$).0.5: Approaching uniform (flatter distribution).1.0: Standard Zipfian (classic “Power Law”).1.5: Highly skewed (very few keys receive almost all traffic).
§Panics
Panics if skew is not within the statistically significant range of 0.5 to 1.5.
Sourcepub fn key<D: Rng>(&self, distribution: &mut D) -> Bytes
pub fn key<D: Rng>(&self, distribution: &mut D) -> Bytes
Samples a key from the workload using the provided random number generator.
This method is designed for high-concurrency environments; by passing a
mutable reference to a thread-local Rng, it avoids global lock contention.
§Performance
This operation is $O(1)$ relative to the size of the key strings but follows
the complexity of the rand_distr::Zipf sampling algorithm (typically rejection inversion).