Skip to content

Commit

Permalink
test(benches/select): measure fetch_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Feb 19, 2025
1 parent 8f24563 commit 878791a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
3 changes: 1 addition & 2 deletions benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Then upload the `perf.script` file to [Firefox Profiler](https://profiler.firefo

These benchmarks are run against a real ClickHouse server, so it must be started:
```bash
docker run -d -p 8123:8123 -p 9000:9000 --name ch clickhouse/clickhouse-server

docker compose up -d
cargo bench --bench <case>
```

Expand Down
47 changes: 42 additions & 5 deletions benches/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn select(c: &mut Criterion) {
d: u32,
}

async fn run(client: Client, iters: u64) -> Result<Duration> {
async fn select_rows(client: Client, iters: u64) -> Result<Duration> {
let start = Instant::now();
let mut cursor = client
.query("SELECT ?fields FROM some")
Expand All @@ -74,14 +74,51 @@ fn select(c: &mut Criterion) {
Ok(start.elapsed())
}

let mut group = c.benchmark_group("select");
async fn select_bytes(client: Client, min_size: u64) -> Result<Duration> {
let start = Instant::now();
let mut cursor = client
.query("SELECT value FROM some")
.fetch_bytes("RowBinary")?;

let mut size = 0;
while size < min_size {
let buf = black_box(cursor.next().await?);
size += buf.unwrap().len() as u64;
}

Ok(start.elapsed())
}

let mut group = c.benchmark_group("rows");
group.throughput(Throughput::Bytes(mem::size_of::<SomeRow>() as u64));
group.bench_function("no compression", |b| {
group.bench_function("uncompressed", |b| {
b.iter_custom(|iters| {
let client = Client::default()
.with_url(format!("http://{addr}"))
.with_compression(Compression::None);
runner.run(select_rows(client, iters))
})
});
#[cfg(feature = "lz4")]
group.bench_function("lz4", |b| {
b.iter_custom(|iters| {
let client = Client::default()
.with_url(format!("http://{addr}"))
.with_compression(Compression::Lz4);
runner.run(select_rows(client, iters))
})
});
group.finish();

const MIB: u64 = 1024 * 1024;
let mut group = c.benchmark_group("mbytes");
group.throughput(Throughput::Bytes(MIB));
group.bench_function("uncompressed", |b| {
b.iter_custom(|iters| {
let client = Client::default()
.with_url(format!("http://{addr}"))
.with_compression(Compression::None);
runner.run(run(client, iters))
runner.run(select_bytes(client, iters * MIB))
})
});
#[cfg(feature = "lz4")]
Expand All @@ -90,7 +127,7 @@ fn select(c: &mut Criterion) {
let client = Client::default()
.with_url(format!("http://{addr}"))
.with_compression(Compression::Lz4);
runner.run(run(client, iters))
runner.run(select_bytes(client, iters * MIB))
})
});
group.finish();
Expand Down

0 comments on commit 878791a

Please sign in to comment.