fn benchmark_cache_put_mt()

in chunk_cache_bench/benches/cache_bench.rs [71:98]


fn benchmark_cache_put_mt<T: ChunkCacheExt + 'static>(c: &mut Criterion) {
    let cache_root = TempDir::new(format!("benchmark_cache_put_mt_{}", T::name()).as_str()).unwrap();
    let cache = T::_initialize(cache_root.path().to_path_buf(), CAPACITY).unwrap();
    let mut it: RandomEntryIterator<StdRng> = RandomEntryIterator::from_seed(SEED);
    let mut total_bytes = 0;
    while total_bytes < CAPACITY {
        let (key, range, chunk_byte_indices, data) = it.next().unwrap();
        cache.put(&key, &range, &chunk_byte_indices, &data).unwrap();
        total_bytes += data.len() as u64;
    }

    let rt = tokio::runtime::Runtime::new().unwrap();

    c.bench_with_input(BenchmarkId::new("cache_put_mt", T::name()), &0, |b, _| {
        b.to_async(&rt).iter(|| async {
            let mut handles = JoinSet::new();
            for _ in 0..NUM_CONCURRENT_TASKS {
                let c = cache.clone();
                handles.spawn(async move {
                    let mut it = RandomEntryIterator::new(thread_rng());
                    let (key, range, offsets, data) = it.next().unwrap();
                    c.put(&key, &range, &offsets, &data).unwrap();
                });
            }
            handles.join_all().await;
        });
    });
}