[auto-perf-opt] Cap pk_index_parallel_compaction threads at num_cores#72428
Closed
luohaha wants to merge 1 commit into
Closed
[auto-perf-opt] Cap pk_index_parallel_compaction threads at num_cores#72428luohaha wants to merge 1 commit into
luohaha wants to merge 1 commit into
Conversation
PK index compaction is CPU-bound (in-memory SST byte-merge in KeyValueMerger::merge). When pk_index_parallel_compaction_threadpool_max_threads is configured higher than the number of cores, the extra threads add only context-switch overhead and starve co-tenant thread pools (publish_version, async_delta_writer, cloud_native_pk_index_execution) that share the same CPU. Observed on the 999_1gb_1_1tb realtime benchmark (32-core CN, configured value = 128, actual active = ~100/CN): cluster CPU pinned at 100%, load1 of 108-162 on 32 cores, every slow publish trace shows parallel_upsert_wait_us = 2.5-2.9s out of 3.1s total -- the publish thread blocked behind PK-index-execution workers that could not get scheduled past the compaction threads. Upsert p99 = 3621ms, max = 20s versus the goal of <=3s. Apply min(configured, num_cores) in both calc_max_threads (init path) and update_max_threads (ADMIN SET path) so the cap cannot be bypassed at runtime. When configured value <= num_cores, behaviour is unchanged.
|
luohaha seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
3 tasks
Contributor
Author
|
Superseded by #72434 — profile (perf -F 99 60s on the hottest CN) shows the actual hotspot is per-key protobuf allocator churn inside KeyValueMerger::merge/flush (38.6% self-time in my_free); throttling the compaction thread pool would have made things worse by letting SSTs accumulate. Closing in favor of the perf-driven fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PK index compaction is CPU-bound (in-memory SST byte-merge in
KeyValueMerger::merge). Whenpk_index_parallel_compaction_threadpool_max_threadsis configured higher than the number of cores, the extra threads add only context-switch overhead and starve co-tenant thread pools (publish_version,async_delta_writer,cloud_native_pk_index_execution) that share the same CPU.This patch caps the effective thread count at
CpuInfo::num_cores()in bothcalc_max_threads(init path) andupdate_max_threads(ADMIN SET path) so the bound cannot be bypassed at runtime. When the configured value is ≤num_cores, behaviour is unchanged.Bottleneck evidence (auto-perf-opt iteration 001, branch-4.1 + commit
7af3ba7, template999_1gb_1_1tbon 6 × 32-core CN)cloud_native_pk_index_compactthread pool: cluster size 768 (= 128/CN × 6 CN, set by the benchmark template), 605 active threads, avg per-task execute time 46.6 s, queue 124. No other pool comes close.parallel_upsert_wait_us = 2.5-2.9 sof a 3.1 s total — the publish thread is blocked waiting oncloud_native_pk_index_executionworkers, which themselves cannot be scheduled past the compaction threads.Code change
be/src/storage/lake/lake_persistent_index_parallel_compact_mgr.cpp:Expected impact
With the benchmark's configured value of 128 on a 32-core CN:
publish_version,async_delta_writer,put_aggregate_metadata,cloud_native_pk_index_execution→ publish wait drops → upsert max should fall well below the 20 s observed.Risks
If SST queue grows monotonically under the lower compaction concurrency, PK-index lookup amplification could slow the read/publish path differently. Iteration 002 of the auto-perf-opt run will measure this; if SST count grows unbounded we will revert and try a different angle (e.g. tune
pk_index_early_sst_compaction_threshold).Test plan
999_1gb_1_1tbworkload; expected: cluster CPU drops below 100 %, upsert max < 20 s, freshness P99 lower.cloud_native_pk_index_compactqueue_countover the test window — must not grow unbounded.