Repository navigation
Support shell-script queries in performance comparison tests - #108081
Conversation
The performance comparison framework could only run SQL queries over the native protocol. Extend it to also accept shell scripts, marked with `<query type="shell">`, which are run with `bash` and timed end to end. This covers measurements the native protocol cannot express: HTTP latency, response compression, and tool startup time. `perf.py` runs each shell-script query once per server, building per-server `$CLICKHOUSE_*` environment variables (`CLICKHOUSE_BINARY`, host, TCP/HTTP ports, `CLICKHOUSE_CLIENT`, `CLICKHOUSE_LOCAL`, `CLICKHOUSE_CURL`, `CLICKHOUSE_URL`) that mirror the stateless tests in `shell_config.sh`, so the reference and the patched build are measured each on their own. The timing flows into the report as the `client_time` metric, exactly like a SQL query. Parameter substitutions and `<settings>` are not applied to shell scripts, and the server-side profiler runs are skipped for them. Both run paths pass the binary paths and HTTP ports to `perf.py`: `ci/jobs/performance_tests.py` (`CHServer`) for CI and `ci/jobs/scripts/perf/compare.sh` for local runs. The perf-comparison config removes `<http_port>`, so it is re-enabled per server on the command line (a documented config override) with distinct ports for the reference and the patched server. Fix a latent bug in `analyze_queries`: `version` and `query_id` were taken from the non-preserved (left) side of the `RIGHT JOIN` against `query_log`. For runs without a `query_log` row (shell scripts) they defaulted to `0`/`''` and collapsed both servers' runs onto version `0`. Qualify them to `query_runs`. SQL queries are unaffected because their `query_log` row always matches. Add two shell-script performance tests: - `clickhouse_local_startup.xml`: `clickhouse-local --query "SELECT 1"` startup - `http_read_gzip.xml`: reading ~1 MB over HTTP, with and without gzip Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [cef3b90] Summary: ✅
AI ReviewSummaryThis PR extends the performance comparison framework so tests can define shell-script queries, wires per-server binary/HTTP settings through both perf runners, adds two shell benchmarks, and documents the new behavior. The previously reported timeout, HTTP fail-closed, auth/TLS, and profile-collection issues are fixed in the current code; I resolved the two remaining open bot-authored threads. I found no new correctness, safety, or reporting issues that warrant inline comments. Missing context / blind spots
Final Verdict✅ No blockers or majors found in this pass. |
Address the AI review on #108081 (#108081): 1. `run_shell_query` now runs the script in its own session (`start_new_session=True`) and, on timeout, kills the whole process group with `os.killpg` instead of only the immediate `bash`. Previously `subprocess.run(..., timeout=...)` killed just `bash`, so a script blocked inside a child such as `curl` or `$CLICKHOUSE_LOCAL` kept running after `--max-query-seconds`, consuming CPU/network or holding a server-side query open and polluting later measurements. 2. The default `CLICKHOUSE_CURL` is now `curl -q -sS --fail --max-time 120`. `--fail` makes `curl` exit non-zero on an HTTP 4xx/5xx response (and `-S` prints the error under `-s`), so an HTTP benchmark fails the query instead of silently timing a server exception response as a fast successful sample. Unlike `tests/queries/shell_config.sh` (which omits `--fail` so some stateless tests can inspect error bodies), a benchmark must fail closed. Document both behaviors in `tests/performance/README.md`. Focused evidence (the two failure paths exercised in isolation): - timeout: a `bash` script whose grandchild is `sleep 60` is timed out; after `os.killpg` the grandchild is gone (`alive_after_kill=False`). - HTTP error: against a server returning HTTP 500, `curl -q -s` exits 0 (the bug — measured as success) while `curl -q -sS --fail` exits 22 (the query fails). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| # {"kind": "shell", "script": "..."} -- run as a bash script, see below. | ||
| test_queries = [] | ||
| for e in root.findall("query"): | ||
| if e.get("type") == "shell": |
There was a problem hiding this comment.
Looking at the following code, a class Query looks attractive to add. With prewarm, run, human-readable display and so on
|
@groeneai, why was the performance comparison skipped here? I wanted to validate if the new logic and new tests work. |
|
@alexey-milovidov It ran. A retry then hid it behind the digest cache. Run 27928277351 on
The single red X is So the new shell-script path works: The attempt-1 results already exist, so you can validate from there. To force a fresh, non-cached run, push a commit touching a perf file (one of the new Report (amd batch 6/6, where |
…ently A `<query type="shell">` that failed on one server was swallowed as a "partial" query: `perf.py` continued on whichever server survived and the query was dropped from the report and CIDB with no error recorded anywhere (empty `run-errors.tsv`, green job). A shell test broken on one build looked indistinguishable from one that simply produced no data. Unlike an SQL query that may legitimately use a function missing from the old server, a shell-script benchmark is expected to run on every server, so a failure on any of them makes the comparison meaningless. Now `perf.py` fails the query loudly and echoes the captured error from each failing server to stdout as a `run-error` line, which survives in the archived per-test raw `.tsv` (the per-test stderr log is not uploaded). `compare.sh` folds those `run-error` lines into `run-errors.tsv`, so the failure shows up in the report's Run Errors table and in CIDB. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Root cause of `clickhouse_local_startup` producing no comparison: the patched
("right") build was only symlinked under its subcommand names
(`clickhouse-server`, `clickhouse-local`, `clickhouse-client`,
`clickhouse-keeper`) but never as a bare `clickhouse`, because `--ch-path`
defaults to `ci/tmp` while the symlinks live in `ci/tmp/perf_wd/right`. The
reference ("left") build, by contrast, is downloaded by `wget` as a bare
`left/clickhouse`.
Shell-script queries (`<query type="shell">`) run the multi-call binary
directly through `$CLICKHOUSE_BINARY` / `$CLICKHOUSE_LOCAL` /
`$CLICKHOUSE_CLIENT`, which `compare.sh` builds from `left/clickhouse` and
`right/clickhouse` (passed via `--binary`). With `right/clickhouse` missing,
`right/clickhouse local` failed with "No such file or directory" (exit 127) on
the patched server only, so `clickhouse_local_startup` ran on the reference
server alone, was recorded as a "partial" query and dropped from the report and
CIDB. HTTP queries were unaffected because they talk to the already-running
server (`right/clickhouse-server`) over curl, not to the bare binary.
Verified by reproducing the exact failure locally: a `right/` directory with
only the subcommand symlinks makes `right/clickhouse local` exit 127, while a
`left/` with a bare `clickhouse` succeeds.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review (`perf.py:486`): the SQL path connects through `clickhouse_driver.Client` honouring `--user` / `--password` / `--secure`, but the per-server shell environment built by `shell_env_for` always uses an unauthenticated, plaintext `$CLICKHOUSE_CLIENT` and a `http://` `$CLICKHOUSE_URL`. Running a shell-script query under non-default credentials or TLS would therefore either fail during shell execution or, worse, measure a different (default plaintext) endpoint than the SQL setup/prewarm connected to, silently invalidating the comparison. Until the shell helpers carry these options, fail closed: reject a test that mixes shell-script queries with non-default `--user` / `--password` / `--secure` up front, rather than benchmarking the wrong endpoint. The check runs after the `--print-queries` / `--print-settings` early exits so those read-only paths are unaffected. No current `perf.py` caller (`compare.sh`, `performance_tests.py`, `collect_clickhouse_profiles.py`) passes these options, so the guard never fires in practice; it only documents and enforces the current limitation. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review (`perf.py:105`): `ci/jobs/collect_clickhouse_profiles.py` runs every `tests/performance/*.xml` against a single instrumented server started with only `--tcp_port` (its perf config removes `<http_port>`), and it invokes `perf.py` without `--binary` / `--http-port`. The new shell-script tests rely on exactly those: `clickhouse_local_startup` would run whatever `clickhouse` is in `PATH` (not the instrumented / BOLT binary), and `http_read_gzip` would hit an HTTP endpoint that is not listening. Shell-script queries measure tool startup and HTTP timing rather than query code paths, so they are useless for PGO/BOLT profiles. Skip them in profile collection (logged, never silently dropped). Detection parses the test XML for a `<query type="shell">`; a parse error is treated as "no shell query" so the test still runs and `perf.py` reports the real error. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Ok, I see it ( and the test is stable. I don't like the number (~100ms), so it will be a good thing to work on. |
|
@alexey-milovidov Confirmed the shell-script perf path is working ( On the ~100ms: profiled
Evidence (local debug build, but the cost is thread creation so it is build-independent):
So ~60% of startup is just spawning a thread pool that Two ways to do it; which do you prefer before I open the PR:
Session id: cron:clickhouse-worker-slot-4:20260625-190000 |
Address the AI review on ClickHouse#108081 (ClickHouse#108081): 1. `run_shell_query` now runs the script in its own session (`start_new_session=True`) and, on timeout, kills the whole process group with `os.killpg` instead of only the immediate `bash`. Previously `subprocess.run(..., timeout=...)` killed just `bash`, so a script blocked inside a child such as `curl` or `$CLICKHOUSE_LOCAL` kept running after `--max-query-seconds`, consuming CPU/network or holding a server-side query open and polluting later measurements. 2. The default `CLICKHOUSE_CURL` is now `curl -q -sS --fail --max-time 120`. `--fail` makes `curl` exit non-zero on an HTTP 4xx/5xx response (and `-S` prints the error under `-s`), so an HTTP benchmark fails the query instead of silently timing a server exception response as a fast successful sample. Unlike `tests/queries/shell_config.sh` (which omits `--fail` so some stateless tests can inspect error bodies), a benchmark must fail closed. Document both behaviors in `tests/performance/README.md`. Focused evidence (the two failure paths exercised in isolation): - timeout: a `bash` script whose grandchild is `sleep 60` is timed out; after `os.killpg` the grandchild is gone (`alive_after_kill=False`). - HTTP error: against a server returning HTTP 500, `curl -q -s` exits 0 (the bug — measured as success) while `curl -q -sS --fail` exits 22 (the query fails). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…t-tests Support shell-script queries in performance comparison tests
The performance comparison framework could only run SQL queries over the native protocol. This extends it to also accept shell scripts, marked with
<query type="shell">, which are run withbashand timed end to end. This covers measurements the native protocol cannot express: HTTP latency, response compression, and tool startup time.A shell-script query goes through the same measurement machinery as a SQL query — prewarm, the interleaved multi-run loop (alternating
L,R,R,L,…), the same stop conditions, and the samemedian/ Welch's t-test /diffstatistics, reported as theclient_timemetric. The only difference is how a single timing is obtained (abashsubprocess wall-clock measurement instead ofconnection.last_query.elapsed), and that the server-side profiler runs are skipped (there is no single query to attribute them to).Each server gets its own
$CLICKHOUSE_*environment variables, mirroring the stateless tests intests/queries/shell_config.sh, so the reference (LEFT) and the patched (RIGHT) build — which listen on different ports — are measured each on their own:CLICKHOUSE_BINARY,CLICKHOUSE_HOST,CLICKHOUSE_PORT_TCP,CLICKHOUSE_PORT_HTTP,CLICKHOUSE_DATABASE,CLICKHOUSE_CLIENT,CLICKHOUSE_LOCAL,CLICKHOUSE_CURL,CLICKHOUSE_URL. Parameter{substitutions}and<settings>are not applied to shell scripts (they would collide with${var}and brace expansion).Both run paths pass the binary paths and HTTP ports to
perf.py(new--binary/--http-portoptions):ci/jobs/performance_tests.pyfor CI andci/jobs/scripts/perf/compare.shfor local runs. The perf-comparison config removes<http_port>, so it is re-enabled per server on the command line (a documented config override) with distinct ports for the reference and the patched server.This also fixes a latent bug in
analyze_queries:versionandquery_idwere taken from the non-preserved (left) side of theRIGHT JOINagainstquery_log. For runs without aquery_logrow (shell scripts) they defaulted to0/ empty and collapsed both servers' runs onto version0. They are now qualified toquery_runs. SQL queries are unaffected, because theirquery_logrow always matches.Two shell-script performance tests are added:
clickhouse_local_startup.xml— how fastclickhouse-local --query "SELECT 1"starts up.http_read_gzip.xml— reading about a megabyte over HTTP (SELECT number FROM numbers(500000)), with and without gzip response compression.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The performance comparison test framework now accepts shell-script tests (
<query type="shell">) in addition to SQL queries, for end-to-end measurements such as HTTP latency, response compression, and tool startup time.Documentation entry for user-facing changes
Version info
26.7.1.83