Repository navigation
TimeSeries: use 256 KiB granules and ALP, ZSTD(4) for the values of the samples table by default - #131678
Conversation
A row of the samples table holds one hour of one series (ClickHouse#117344), so with `index_granularity_bytes = 524288` a granule is about 135 hours of one 15 s series and a short PromQL window older than the recent samples table reads whole granules. Change the default of `samples_index_granularity_bytes` to 262144 and update its documentation and the tests that check the default. Measured on the CI amd_release binary of 9b41283 with the data set of ClickHouse#131459 (19,800 series, 14 days, byte counters with random decimals), max_threads = 4, 15 interleaved reps, ratio = 262144 / 524288: - O19 rate(node_cpu_seconds_total[5m]), 1 h range 5 days back: 0.670 - O23b sum(count_over_time(node_cpu_seconds_total[6h])): 0.696 - W1 / W3 / F4 / F6 long scans: 1.170 / 1.140 / 1.181 / 1.266 - marks 49,282 -> 99,299, samples table on disk +1.0% Existing tables keep their stored `index_granularity_bytes`. The setting exists only on master, so no compatibility handling is needed. Adds the perf test promql_selector_old_short_window.xml. Closes: ClickHouse#131459 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261114-195500 |
|
cc @nikitamikhaylov, could you review this? TimeSeries: default samples_index_granularity_bytes 524288 -> 262144 (short PromQL windows older than the recent samples table about 30% faster, long random-decimal counter scans 14-27% slower) |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261114-185800 |
|
Workflow [PR], commit [1d8b351] Summary: ✅
AI ReviewSummaryThe PR changes new bucketed Tests
Final VerdictStatus: |
…h ALP, ZSTD(4) With 262144-byte granules, a granule of the samples table gives ZSTD about 100 KB of ALP output instead of about 200 KB. zstd picks the parameters of a level by input size: at level 3, inputs up to 128 KiB use a minimum match of 5 bytes (4 bytes between 128 and 256 KiB), so more repeated bytes of values with random decimal digits stay literals, and zstd Huffman-codes them, which decodes much slower. Level 4 uses a minimum match of 4 at this size. The generated `samples.value` codec of tables with buckets of samples (version 11, both the samples and the recent samples table) becomes `ALP, ZSTD(4)`. Versions 10 and earlier keep `ALP, ZSTD(3)`, and so do existing tables: their stored definitions declare the codecs. Measured on the CI amd_release binary of 9b41283 (identical rows, 15 interleaved reps, max_threads = 4, ratio to 524288 + ZSTD(3)): 7/14-day random-decimal counter scans {W1, W3, F4, F6} 1.144 -> 0.993; O19/O23b 0.671 -> 0.676; samples table on disk +1.0% -> +0.15%; INSERT +3.8% wall / +5.9% user CPU and OPTIMIZE FINAL +2% vs ZSTD(3) at the same granularity. Results identical up to float summation order. Proposed and measured on x86 and Graviton 3 in ClickHouse#131459. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 27 s compile time in total, 9 of them have a recent master baseline. |
CI finish ledger - b9603e0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261115-040014 |
|
Fixing PR for the |
… settings Review feedback: instead of a separate getDefaultBucketedValueCodec(), getDefaultValueCodec() takes the TimeSeries settings and returns ALP, ZSTD(4) for tables with buckets of samples and ALP, ZSTD(3) otherwise. No behaviour change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Will do. Once #131766 is merged I'll push here to re-run CI (it builds the merge with master) and post the |
CI builds the merge commit with master, which now contains ClickHouse#131766, so the performance comparisons measure this PR's defaults with the selector fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…shorter than a bucket The selector of a table with buckets of samples wrapped every read in `WHERE notEmpty(samples)` over `timeSeriesSliceSortedArray(samples, a, b)`. Filter push-down moves that condition into PREWHERE, which reads the raw `samples`, computes the slice and drops the raw column, so the raw column is PREWHERE-only. Since ClickHouse#122919 `MergeTreeBlockSizePredictor` counts such a column at its part estimate on top of the measured slice copy: for a long window (the slice is the whole array) bytes per row double, and with granules under 512 KiB a block holds about one granule instead of two or three. Whole-metric selectors then process about twice as many blocks (`promql_selector_id_range_row_cost` #0/ClickHouse#1 1.3x slower with 262144-byte granules, ClickHouse#131678). The filter is a no-op unless the range is shorter than a bucket: every sample of a row lies in [bucket, bucket + step), `min_time`/`max_time` are the smallest/largest of them, and the inner query keeps a row only if `max_time >= a AND min_time <= b`. If `min_time >= a` the sample at `min_time` is in the range, if `max_time <= b` the sample at `max_time` is, so an empty slice needs `min_time < a AND b < max_time`, i.e. `b - a < max_time - min_time < step`. With a bound absent the same holds for the other bound. So the filter is now emitted only when both bounds are set and `b - a < step` in the units of the table being read (the samples table or the recent samples table, each with its own step). The difference is computed in Int128: the bounds of a DateTime64 table can be anywhere in [INT64_MIN, INT64_MAX]. For long windows nothing on `samples` goes to PREWHERE, the raw column is read by the main step and measured once, and the slice is computed after it. The bucket step at the table scale is moved into `getBucketStep`, shared with `makeBucketedSamplesTimeRangeConditions`. Measured (release build, master vs this change concurrently on identical parts, 2 x 25 interleaved runs, max_threads = 4): row_cost #0 0.81/0.76 at 262144, 0.86/0.81 at 131072, 0.93/0.84 at 524288; ClickHouse#1 0.79/0.73, 0.88/0.83, 0.99/0.91; promql_selector_old_short_window 0.94-0.97. Results identical. Edge: a row written directly with `min_time`/`max_time` looser than its samples (against the documented contract) can now be returned as an empty array by `timeSeriesSelector(..., 'samples')` for a long range. PromQL drops series whose merged array is empty, as it does for rows emptied by the stale-marker filter. Tests: 05770_time_series_selector_empty_slice_filter checks both sides of the bucket boundary and the plan shape (no-parallel-replicas: without a local plan the initiator's EXPLAIN does not show the replicas' filters). New perf test promql_selector_small_granules: the row_cost shape at 131072-byte granules, the default of the recent samples table. Related: ClickHouse#131678 Related: ClickHouse#122919 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The regression is gone. ARM perf comparison of 1d8b351 (merged with master f3a76d3, which contains #131766): CI ran only the ARM perf comparison, so I also measured x86 locally (master CI |
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Note: Prometheus compliance score is unchanged vs baseline. |
f6f46e6
Closes: #131459
Related: #117344
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Since #117344 a row of the TimeSeries samples table holds one hour of one series, so the default
index_granularity_bytes = 524288makes a granule about 135 hours of one 15 s series, and a short PromQL window older than the recent samples table reads whole granules. This changes the default ofsamples_index_granularity_bytesto 262144, and the generatedsamples.valuecodec of tables with buckets of samples fromALP, ZSTD(3)toALP, ZSTD(4): for blocks under 128 KiB, level 3 decodes random decimal digits slower (#131459). Existing tables keep their definitions. Adds the perf testpromql_selector_old_short_window.Data set of #131459, CI
amd_releaseof 9b41283 (before #122919), 15 interleaved repetitions,max_threads = 4; ratio to master, geometric mean, 95% CI:rate(node_cpu_seconds_total[5m]), 1 h, 5 days backsum(count_over_time(node_cpu_seconds_total[6h])), 5 days backrate(node_disk_written_bytes_total[5m])by instance, 7 daysCosts: marks double, the samples table grows by 0.15%; INSERT takes 13% more CPU and OPTIMIZE FINAL 14% (
ZSTD(4)accounts for 6 and 2 points). Whole-metric scans (promql_selector_id_range_row_cost#0, #1) at 262144 vs 524288, on master with #131766: 1.01x in the ARM CI perf comparison, 1.04-1.07x on x86 (1.2-1.3x since #122919, before #131766); the short windows ofpromql_selector_old_short_windoware 0.64-0.69x.Not for changelog: version 11 and the setting (#117344) are only on master.
Workflow [PR]
Sync PR [sync-upstream/pr/131678]
Version info
26.11.1.2419-master(included in26.11and later)