Skip to content

Filesystem cache: let listing threads help load after listing finishes - #107416

Merged
kssenii merged 1 commit into
masterfrom
filecache-load-thread-utilization
Jun 15, 2026
Merged

kssenii merged 1 commit into
masterfrom
filecache-load-thread-utilization

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Startup metadata loading splits load_metadata_threads into listing threads (walk key-prefix directories, enqueue individual key directories) and loading threads (drain the queue, build in-memory metadata per key). Listing threads previously exited as soon as all prefixes were listed, leaving only the loading threads (half of load_metadata_threads) to process the — usually dominant — remaining keys. Up to half the threads sat idle for the bulk of the work.

Now, once a listing thread runs out of prefixes to list, it joins the loading threads in draining the queue (the shared drain_queue helper), so all load_metadata_threads threads load keys during the tail of the operation.

The listing/loading split and the startup log line are unchanged. Behavior is otherwise identical; covered by the existing test_parallel_cache_loading_on_startup integration test.

Related: #107414
Related: #107415

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Speed up filesystem cache loading on startup by letting directory-listing threads help load cache metadata once listing is finished, instead of leaving half the threads idle.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.806

Startup metadata loading splits `load_metadata_threads` into listing
threads (which walk key-prefix directories and enqueue individual key
directories) and loading threads (which drain the queue and build the
in-memory metadata for each key). The listing threads previously exited as
soon as all prefixes were listed, leaving only the loading threads to
process the - usually dominant - remaining keys, so up to half the threads
sat idle for the bulk of the work.

Once a listing thread runs out of prefixes to list, it now joins the
loading threads in draining the queue (the shared `drain_queue` helper),
so all `load_metadata_threads` threads load keys during the tail of the
operation. This matters more now that loading a key no longer needs a
`stat` per file, which made the loading phase relatively cheaper per key
but still the larger share of total work.

Behavior is unchanged; covered by the existing
`test_parallel_cache_loading_on_startup` integration test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov force-pushed the filecache-size-in-filename branch from f2ed23b to 34b3567 Compare June 13, 2026 20:16
@alexey-milovidov
alexey-milovidov force-pushed the filecache-load-thread-utilization branch from 65283d4 to e8e2572 Compare June 13, 2026 20:21
@alexey-milovidov
alexey-milovidov changed the base branch from filecache-size-in-filename to master June 13, 2026 20:21
@clickhouse-gh

clickhouse-gh Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e8e2572]

Summary: ✅


AI Review

Summary

The PR lets filesystem-cache listing threads switch to draining queued key directories after listing is done, so startup metadata loading can use all configured load_metadata_threads during the tail of the work. The queue handoff and exception path look coherent, and the PR metadata is aligned with the change, but I am requesting changes because the Performance Improvement claim is not backed by before/after evidence.

Tests
  • ⚠️ [src/Interpreters/FileCache/FileCache.cpp:1873] The PR is categorized as Performance Improvement, but there is no measurement showing the startup metadata load path is faster. The existing test_parallel_cache_loading_on_startup checks correctness and the logged thread split, but it would still pass if the added drain_queue call were removed. Please add or link focused before/after evidence, such as elapsed FilesystemCacheLoadMetadataMicroseconds or startup wall time for a populated cache where queued-key loading dominates.
  • ⚠️ The available PR CI report for commit e8e25722aa9aa92caeb30431aeda4aaf0ce622c5 currently reports 0 test results, so completed CI results were not available as supporting evidence.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: provide focused before/after performance evidence for the changed startup metadata loading path.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jun 13, 2026
key_dirs_queue.finish();

/// Listing is done for this thread; help load the remaining enqueued keys.
drain_queue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR is categorized as a Performance Improvement, but I do not see before/after evidence for the startup metadata load path this changes. The existing test_parallel_cache_loading_on_startup validates correctness and that the configured listing/loading split is logged, but it would still pass if this helper call were removed, so it does not prove the promised speedup.

Please include a focused measurement for the same cache layout with and without this change, for example elapsed FilesystemCacheLoadMetadataMicroseconds or startup wall time for a populated filesystem cache where the queue tail dominates.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a pure work-sharing change, not a new algorithm: the listing threads are already spawned and, once they run out of key-prefix directories to enumerate, they previously returned and sat idle while only the loading threads (half of load_metadata_threads) drained the — usually dominant — queue of key directories. Now they call the same drain_queue helper, so all load_metadata_threads threads load keys during the tail. The listing/loading split, the queue, and the startup log line are unchanged, which is exactly why test_parallel_cache_loading_on_startup still passes either way — the test asserts correctness of the result, and the result is identical.

A deterministic before/after measurement in CI isn't really attainable here: the win equals the fraction of total startup-load time spent in the tail where half the threads were idle, which is a function of the cache layout (key-prefix count vs. key count), filesystem latency, and load_metadata_threads. On a small/fast cache it's in the noise; it shows up on populated caches where keys dominate prefixes. The cloud performance report on this PR confirms there is no query-path effect (the change only touches FileCache::loadMetadataImpl, called at startup).

I'll leave the call on whether to attach a focused startup-wall-time microbenchmark to @alexey-milovidov; this is consistent with the sibling startup-load PRs #107414 and #107415.

@alexey-milovidov
alexey-milovidov requested a review from kssenii June 13, 2026 21:54
@clickhouse-gh

clickhouse-gh Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 3 query(s) improved out of 38 analysed

This PR only parallelizes file-cache metadata loading at server startup (FileCache::loadMetadataImpl); it does not touch any query-execution code path, and the cache contents and hit rates during the benchmark are unchanged. Because the change is off-path, the flagged ClickBench and TPC-H deltas — moving in both directions — are downgraded as run-to-run variance rather than real PR effects. Three queries (ClickBench Q23, TPC-H Q7 and Q20) show large, consistent shifts that clear the automatic trust threshold and are reported as-is, but given the startup-only diff they most likely reflect baseline/environment differences and are worth re-running to confirm.

clickbench

🟢 1 improved · ⚠️ 5 inconclusive

Flagged queries (6 of 43)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
🟢 23 improvement 297 199 -33.0% <0.0001 cache: Large consistent -33% exceeds auto-trust bar, but PR only touches startup cache-metadata load; likely env, re-run
⚠️ 4 not_sure 264 218 -17.4% <0.0001 cache: PR only parallelizes startup file-cache metadata load; query exec path untouched, so this delta is variance
⚠️ 15 not_sure 246 200 -18.7% <0.0001 cache: Startup-only file-cache metadata loading change cannot touch this query's exec path; treat -18.7% as variance
⚠️ 22 not_sure 334 258 -22.6% <0.0001 cache: Off-path: PR changes only startup cache-metadata loading; high-variance query (CV>50), delta is noise
⚠️ 24 not_sure 212 237 +11.8% <0.0001 cache: PR only touches startup file-cache metadata loading, not query execution; +11.8% is run-to-run variance
⚠️ 26 not_sure 214 238 +11.2% <0.0001 cache: Off-path startup-only diff cannot regress this query's exec path; +11.2% is run-to-run variance

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 2 improved · ⚠️ 1 inconclusive

Flagged queries (3 of 22)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
🟢 7 improvement 113 75 -33.6% <0.0001 cache: Clear -33.6% shift exceeds auto-trust bar, but PR only changes startup cache-metadata load; likely env, re-run
🟢 20 improvement 248 133 -46.4% <0.0001 cache: Large -46% but query is intrinsically noisy and PR is startup-cache-only; off-path, verify with re-run
⚠️ 8 not_sure 156 190 +22.2% <0.0001 cache: PR only parallelizes startup file-cache metadata loading; query exec path untouched, +22% is variance

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: aae807a2-7f67-48fe-99be-8c5a634b1a0d
  • MIRAI run: 7bbdc12a-d5e3-4241-bc78-a2bd74df505f
  • PR check IDs:
    • clickbench_54203_1781390003
    • clickbench_54217_1781390003
    • clickbench_54223_1781390003
    • tpch_adapted_1_official_54229_1781390003
    • tpch_adapted_1_official_54235_1781390003
    • tpch_adapted_1_official_54248_1781390003

@clickhouse-gh

clickhouse-gh Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.70% +0.00%
Functions 92.40% 92.30% -0.10%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 17/21 (80.95%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 3 line(s) · Uncovered code

Full report · Diff report

@kssenii kssenii self-assigned this Jun 14, 2026
@kssenii
kssenii added this pull request to the merge queue Jun 15, 2026
Merged via the queue into master with commit 0150351 Jun 15, 2026
166 checks passed
@kssenii
kssenii deleted the filecache-load-thread-utilization branch June 15, 2026 10:17
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants