Repository navigation
Measure CLI tools startup time in CI - #112496
thevar1able wants to merge 4 commits into
Conversation
`clickhouse local --query "SELECT 1"` spent most of its time before the query: the query itself took 1ms of a 45ms run. Three sources of unnecessary startup work, measured with `perf` and with an interposed `__libc_start_main` to separate static initialisation from `main`: * `TimezoneMixin` resolved the UTC time zone in its constructor, in addition to the named or default one. Building a `DateLUTImpl` walks ~146k days through cctz (~70M instructions), and `DataTypeDateTime` / `DataTypeDateTime64` are constructed just to name a column type - for example when building the schemas of the system tables - without ever touching UTC. Only the serializations need it, for ISO output and the `best_effort` parsers, so they declare their own `utc_time_zone` and pay for it once per formatter. * `clickhouse local` attached all ~164 system tables and both spellings of `information_schema` up front. The latter alone parses 20 embedded `CREATE VIEW` statements and builds 40 view storages. Now `DatabaseWithOwnTablesBase::setDeferredPopulation` fills the table list on first access instead. `system.one` is the exception and stays eager: every `FROM`-less query resolves it during analysis, so deferring it along with the rest would just move the whole cost into the first query. Accordingly the table lookups check the already attached tables before triggering population. * `ClientInfo::fillOSUserHostNameAndVersionInfo` resolved the local FQDN through `getFQDNOrHostName`, a blocking `getaddrinfo` (also dlopening the NSS modules). `getClientHostName` resolves it on demand instead, so a process that never reports the name does not pay for it, and a slow resolver no longer sits on the startup path. Also stop copying every system table's `StorageInMemoryMetadata` - which carries the full `ColumnsDescription` - twice just to fill in its comment. `clickhouse local --query "SELECT 1"`, mean of 500 sequential runs: 44.65ms -> 27.80ms, and 513.8M -> 272.3M instructions. `clickhouse client` and `clickhouse local --version` improve by about 1.5ms. The server keeps attaching its system tables eagerly. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The performance-comparison job cannot see start-up cost. It runs its queries over
a persistent client connection against servers that are already up, so process
start-up falls entirely outside its measurement window, and `clickhouse local` is
never exercised at all. The only existing coverage is the canary
`03321_clickhouse_local_initialization_not_too_slow_even_under_sanitizers`, which
asserts that at least 5 invocations complete in 10 seconds - about 2s per run, far
too coarse to notice anything short of a catastrophe.
This job measures whole short-lived invocations of both `local` and `client` and
compares them against the latest master build, the same way the performance
comparison picks up its reference binary. Four scenarios need nothing but the
binary (`local --version`, `client --version`, `local -q "SELECT 1"`, and a query
that forces the whole `system` database to be built, so that the laziness there
cannot be silently undone). A fifth runs a real `client` query against a server
started from the build under test, which is the only way to cover connecting and
the handshake - where a client pays for `ClientInfo`, including resolving its own
hostname. That server is held fixed while the two client binaries are swapped, so
its cost cancels in the ratio.
Metrics come from `getrusage(RUSAGE_CHILDREN)`, which needs neither `perf` (not
installed in any CI image) nor elevated `perf_event_paranoid`. Both of these gate
the result, because they fail in opposite directions:
* Minor page faults (`ru_minflt`) are the trustworthy metric: they count work
done rather than time taken, so a busy neighbour cannot move them. Measured
against itself the ratio stays within 0.4%, so the threshold is a tight 1.05x -
and this is the gate that catches the usual shape of a start-up regression
(more static initialisation, more objects built, more relocations), all of which
touch more memory.
* CPU time (`ru_utime + ru_stime`) is the noisy one. It beats wall clock, since it
excludes time spent waiting to be scheduled, but on a shared runner cache and
memory-bandwidth contention still make the same work burn more cycles. So it
gets a loose 1.15x threshold and exists only to catch what faults cannot: a
regression that burns CPU without touching new memory.
Wall clock is reported for context and never gates.
Each scenario spawns the binary 330 times per build (11 rounds of 30), alternating
between the two builds and swapping which goes first, then takes a median of the
per-round ratios so that a round which lost its CPU to a neighbour is discarded
rather than averaged in.
`ci/jobs/scripts/cli_startup/measure.py` also runs standalone for local work:
python3 ci/jobs/scripts/cli_startup/measure.py --left old/clickhouse --right new/clickhouse
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [fcce434] Summary: ✅
AI ReviewSummaryThis PR speeds up short-lived CLI invocations by deferring most Findings
Final VerdictChanges requested: the new benchmark should reschedule when its own shared harness and container change, not only when the binary inputs change. |
| runs_on=["#from param"], | ||
| command="python3 ./ci/jobs/cli_startup_benchmark.py", | ||
| digest_config=Job.CacheDigestConfig( | ||
| include_paths=[ |
There was a problem hiding this comment.
The digest only tracks the benchmark harness itself, but the client_select_1 scenario also depends on the shared server-start path in ci/jobs/scripts/clickhouse_service.py and ci/jobs/scripts/server_cleanup.py. On a CI-only PR that changes either helper, build artifacts stay unaffected and this job is treated as unaffected too, so the startup benchmark never reruns even though one of its measured code paths changed. ClickBench already includes those shared helpers in its digest for this reason; this job should do the same.
There was a problem hiding this comment.
build_digest_config.include_paths fixes reruns on binary changes, but the benchmark still calls ClickHouseService for client_select_1 (ci/jobs/cli_startup_benchmark.py), and that shared start path depends on ci/jobs/scripts/clickhouse_service.py plus ci/jobs/scripts/server_cleanup.py (ci/jobs/scripts/clickhouse_service.py). Neither of those, nor ./ci/docker/performance-comparison, is in cli_startup_jobs.digest_config at ci/defs/job_configs.py, so a PR that changes only the shared start path or the benchmark container is still served from cache and skips this job.
CI release artifacts arrive without the executable bit, so spawning the build under test failed with `PermissionError: [Errno 13] Permission denied` on both architectures. The reference build was already chmod-ed after download; do the same for the artifact, as `performance_tests.py` and `ClickHouseService` both do. While here, self-extract both binaries up front. They are self-extracting archives whose first run replaces the wrapper in place with the real ELF, and doing that explicitly keeps decompression out of every measured round rather than relying on the warmup runs to absorb it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…anges Two ways the new job would have been silently omitted. `should_skip_job` keeps only jobs whose name contains `performance`, plus an explicit allowlist, so `ci-performance` - the label used to request perf-only coverage - filtered the benchmark out. Match it by prefix rather than adding it to the allowlist tuple: the name carries a build-type parameter, so the tuple would have needed both `CLI startup benchmark (amd_release)` and `(arm_release)` spelled out, as the `Build` entries already are. The job digest covered only the job's own script, and `requires` is dropped from the digest (see `drop_fields` in `praktika/digest.py`), so depending on the build artifact does not make the digest move. Once the job had succeeded once, every later pull request that did not touch the script itself would have been served from cache - skipping the measurement on exactly the changes worth measuring. Include the build inputs, so the digest tracks whatever can change the binary; a docs-only pull request still gets a cache hit and pays nothing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 168/172 (97.67%) · Uncovered code |
|
I like the different improvements. Maybe we can send them as separate small PRs? |
|
@rschu1ze yes, I'll split it when I get back to this PR. |
CLI startup benchmarkjob that spawnsclickhouse localandclickhouse clientand compares CPU time and minor page faults against the latest master build.systemandinformation_schematables inclickhouse localon first access rather than at startup, keepingsystem.oneeager because everyFROM-less query resolves it during analysis.TimezoneMixin, so that naming aDateTimetype no longer builds a lookup table nothing reads; the serializations that do need it hold their own.ClientInfoon first use instead of through a blockinggetaddrinfoon every invocation.StorageInMemoryMetadatatwice.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up
clickhouse localstartup: system tables andinformation_schemaare now attached on first access, naming aDateTimetype no longer builds an unused UTC lookup table, and the client hostname is resolved only when it is actually reported instead of on every invocation.