sapling/eden/mononoke/cmds/benchmark_storage_config/single_puts.rs
Simon Farnsworth b1c85aaf4b Switch Blobstore to new-style futures
Summary:
Eventually, we want everything to be `async`/`await`; as a stepping stone in that direction, switch the remaining lobstore traits to new-style futures.

This just pushes the `.compat()` out to old-style futures, but it makes the move to non-'static lifetimes easier, as all the compile errors will relate to lifetime issues.

Reviewed By: krallin

Differential Revision: D22183228

fbshipit-source-id: 3fe3977f4469626f55cbf5636d17fff905039827
2020-06-26 03:54:42 -07:00

48 lines
1.4 KiB
Rust

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
use std::sync::Arc;
use criterion::{BenchmarkId, Criterion, Throughput};
use rand::{thread_rng, Rng, RngCore};
use tokio_compat::runtime::Runtime;
use blobstore::{Blobstore, BlobstoreBytes};
use context::CoreContext;
use crate::{KB, MB};
pub fn benchmark(
c: &mut Criterion,
ctx: CoreContext,
blobstore: Arc<dyn Blobstore>,
runtime: &mut Runtime,
) {
let mut group = c.benchmark_group("single_puts");
for size in [128, 16 * KB, 512 * KB, 8 * MB].iter() {
group.throughput(Throughput::Bytes(*size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let mut block = vec![0; size];
thread_rng().fill(&mut block as &mut [u8]);
let block = BlobstoreBytes::from_bytes(block);
let test = |ctx, blobstore: Arc<dyn Blobstore>| {
let block = block.clone();
async move {
let key = format!("benchmark.{:x}", thread_rng().next_u64());
blobstore.put(ctx, key, block).await.expect("Put failed");
}
};
b.iter(|| {
runtime.block_on_std(async { test(ctx.clone(), Arc::clone(&blobstore)).await })
});
});
}
group.finish();
}