Reduce lock contention in QueryConditionCache#80247
Merged
rschu1ze merged 2 commits intoClickHouse:masterfrom May 18, 2025
Merged
Reduce lock contention in QueryConditionCache#80247rschu1ze merged 2 commits intoClickHouse:masterfrom
rschu1ze merged 2 commits intoClickHouse:masterfrom
Conversation
…ached query conditions need to be updated based on changes to underlying data or configuration. This improves query performance by avoiding unnecessary cache rebuilds while ensuring data consistency when conditions change. The method also helps reduce unnecessary lock contention, improving concurrency in multi-threaded query environments. Performance improvements: - Reduces the "native_queued_spin_lock_slowpath" hotspot of entry->mutex from 76% to 1% with Clickbench Q10 on a 2 x 240 vCPUs system - Increases QPS for Q10 and Q11 by 85% and 89% respectively - Improves overall performance across 43 queries with a geometric mean gain of 8.1% Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com>
Member
|
@jiebinn Could you please cherry-pick the topmost commit from here into this PR? I cleaned this PR a bit up but then couldn't push: |
Contributor
Author
|
@rschu1ze , thanks. I have cherry-picked the first commit to this PR. The code now appears more organized and tidy. |
Contributor
Merged
via the queue into
ClickHouse:master
with commit May 18, 2025
63058b4
117 of 121 checks passed
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jun 14, 2025
Cherry pick #80247 to 25.4: Reduce lock contention in QueryConditionCache
robot-clickhouse
added a commit
that referenced
this pull request
Jun 14, 2025
This was referenced Jun 14, 2025
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jun 14, 2025
Cherry pick #80247 to 25.5: Reduce lock contention in QueryConditionCache
robot-clickhouse
added a commit
that referenced
this pull request
Jun 14, 2025
robot-ch-test-poll4
added a commit
that referenced
this pull request
Jun 14, 2025
Cherry pick #80247 to 25.3: Reduce lock contention in QueryConditionCache
robot-clickhouse
added a commit
that referenced
this pull request
Jun 14, 2025
rschu1ze
added a commit
that referenced
this pull request
Jun 14, 2025
Backport #80247 to 25.4: Reduce lock contention in QueryConditionCache
rschu1ze
added a commit
that referenced
this pull request
Jun 14, 2025
Backport #80247 to 25.5: Reduce lock contention in QueryConditionCache
rschu1ze
added a commit
that referenced
this pull request
Jun 14, 2025
Backport #80247 to 25.3: Reduce lock contention in QueryConditionCache
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.
Key Findings:
With the previous bottleneck high page faults resolved in jemalloc (#80245), we have identified a 76% hotspot in performance cycles
native_queued_spin_lock_slowpathfromQueryConditionCache::writein the latest build on the 2 x 240 vCPUs system. And we have discovered the absence of checks formark_rangesandhas_final_mark, causing all threads to attempt lockingentry->mutexunnecessarily.Solution:
Introduced a new method to QueryConditionCache to determine if cached query conditions need updating based on changes to underlying data or configuration.
This method avoids unnecessary cache rebuilds, ensuring data consistency and reducing lock contention, thereby improving concurrency in multi-threaded query environments.
Performance improvements:
native_queued_spin_lock_slowpathhotspot of entry->mutex from 76% to 1% with Clickbench Q10 on a 2 x 240 vCPUs systemChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Avoid unnecessary update and reduce lock contention in QueryConditionCache
Documentation entry for user-facing changes