Skip to content

Capture clickhouse profile events in query summaries.#10172

Open
jmcarp wants to merge 1 commit intomainfrom
jmcarp/clickhouse-profile
Open

Capture clickhouse profile events in query summaries.#10172
jmcarp wants to merge 1 commit intomainfrom
jmcarp/clickhouse-profile

Conversation

@jmcarp
Copy link
Copy Markdown
Contributor

@jmcarp jmcarp commented Mar 27, 2026

ClickHouse includes a collection of profile events by default when using the native tcp client. This patch captures those events, aggregating them by type and including aggregated profile events in the optional query profile section. We also make use of these profile summaries in the oxql benchmark, adding a new benchmark type that measures query cpu usage rather than latency.

Context: I wanted to evaluate #10110 more rigorously, and Claude noticed that we had access to clickhouse profiling events already. Looking at cpu profiles for that patch actually showed that latency improvements came at the cost of higher cpu use, which is annoying but useful to know.

ClickHouse includes a collection of profile events by default when using
the native tcp client. This patch captures those events, aggregating
them by type and including aggregated profile events in the optional
query profile section. We also make use of these profile summaries in
the oxql benchmark, adding a new benchmark type that measures query cpu
usage rather than latency.
@jmcarp jmcarp requested a review from bnaecker March 27, 2026 03:14
Copy link
Copy Markdown
Collaborator

@bnaecker bnaecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I completely forgot that we already received and parsed these event messages.

I have a few suggestions, but they're fairly minor. Thanks!

fn bench_metric() -> BenchMetric {
match std::env::var("BENCH_METRIC").as_deref() {
Ok("cpu") => BenchMetric::CpuTime,
_ => BenchMetric::Latency,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably match explicitly here, rather than the _ wildcard, and fail if the benchmark isn't a supported one.


fn bench_metric() -> BenchMetric {
match std::env::var("BENCH_METRIC").as_deref() {
Ok("cpu") => BenchMetric::CpuTime,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the string match the variant name? E.g. "cpu_time"?

s.profile_summary
.get("UserTimeMicroseconds")
.copied()
.unwrap_or(0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little suspect of the unwrap_or(0). If the key isn't there, e.g., because of a change when we upgrade ClickHouse, I would want to know. Maybe at least an eprintln!() would help? Same note below too.

/// Wall clock latency.
Latency,
/// Total cpu time.
CpuTime,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a note that this is user + system time as reported by the DB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants