Skip to content

Shrink idle thread pools of the distributed query infrastructure - #106978

Merged
davenger merged 2 commits into
masterfrom
distributed-plan-shrink-idle-thread-pools
Jun 10, 2026
Merged

davenger merged 2 commits into
masterfrom
distributed-plan-shrink-idle-thread-pools

Conversation

@davenger

@davenger davenger commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

Related: #106020

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Since the stateless worker endpoint and streaming exchange server were enabled in every stateless CI run, sanitizer jobs idle closer to their memory cap and OOM more often. The infrastructure retains idle threads for the server's lifetime, and under ASan each parked thread is expensive (instrumented stack pages, fake stack, allocator cache, shadow memory), none of it visible to the memory tracker.

Three sources of retained threads, addressed individually:

  • StatelessTaskExecutor kept up to 100 idle pool threads (observed: 35 parked for the whole run at ~0.1% utilization). The pool parameters are now configurable via stateless_worker_server.max_threads/max_free_threads/queue_size, and idle threads are not retained by default. Since ThreadPool spawns threads on demand, this has no startup or steady-state cost.
  • The ExchangeServer handshake pool kept 8 idle threads; handshakes are short-lived, so it now retains none.
  • The global thread pool only trims when idle threads exceed max_thread_pool_free_size (default 1000). Idle counts in stateless runs peak at ~400-500, so the pool never shrank and every concurrency burst permanently ratcheted up the thread count and resident stack memory. Sanitizer test configs now set the threshold to 128.

Verified locally: after running the 03394_distributed_* worker-path tests, StatelessWorkerThreads and ExchangeServerThreads drain to 0 instead of parking at their high-water marks.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.6.1.607

@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4d5062f]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, sequential) FAIL
03567_json_with_progress ERROR cidb IGNORED
Server died FAIL cidb IGNORED
Segmentation fault (STID: 1367-2eb9) FAIL cidb IGNORED
Unit tests (asan_ubsan, function_prop_fuzzer) FAIL
FunctionsStress.stress FAIL cidb, issue ISSUE EXISTS
AllTests FAIL cidb IGNORED

AI Review

Summary

This PR reduces retained idle threads in the distributed query test infrastructure by making StatelessTaskExecutor pool sizing configurable, retaining no idle ExchangeServer handshake threads, and installing a sanitizer-only max_thread_pool_free_size override for stateless tests. The current code also rejects stateless_worker_server.max_threads = 0, which addresses the prior review finding. I found no remaining correctness, safety, or rollout blockers in the changed lines.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 10, 2026
@Algunenano Algunenano self-assigned this Jun 10, 2026
Comment thread programs/server/Server.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.20% -0.10%

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

Full report · Diff report

@davenger
davenger enabled auto-merge June 10, 2026 19:03
@davenger
davenger added this pull request to the merge queue Jun 10, 2026
Merged via the queue into master with commit 4f2c879 Jun 10, 2026
163 of 166 checks passed
@davenger
davenger deleted the distributed-plan-shrink-idle-thread-pools branch June 10, 2026 19:19
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 10, 2026
pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Jun 11, 2026
…ted-plan-shrink-idle-thread-pools"

This reverts commit 4f2c879, reversing
changes made to 56d78b5.
ianton-ru pushed a commit to Altinity/ClickHouse that referenced this pull request Jul 13, 2026
…-shrink-idle-thread-pools

Shrink idle thread pools of the distributed query infrastructure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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