Skip to content

Isolate streaming queries background jobs into the dedicated pool - #105981

Merged
Michicosun merged 12 commits into
masterfrom
streaming-task-scheduling-settings
Jul 12, 2026
Merged

Michicosun merged 12 commits into
masterfrom
streaming-task-scheduling-settings

Conversation

@Michicosun

@Michicosun Michicosun commented May 27, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

This patch moves the background streaming queries jobs to a dedicated pool.

Version info

  • Merged into: 26.7.1.827 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [62ca38e]

Summary: ✅


AI Review

Summary

This PR moves BackgroundJobsAssignee:Streaming work onto a dedicated BackgroundStreamingSchedulePool and adds a dedicated size setting plus metrics. The system table wiring is mostly there, but the implementation still makes the new pool mandatory even when enable_streaming_queries = 0 and no subscriptions exist, so the split is not pay-as-you-go and can increase idle thread usage or even block startup on servers that never use streaming queries.

Findings

❌ Blockers

  • [programs/server/Server.cpp:2703] The config-reload callback now unconditionally calls getStreamingSchedulePool().increaseThreadsCount(...), and ConfigReloader runs that callback during the initial load. Context::getStreamingSchedulePool constructs BackgroundSchedulePool, whose constructor eagerly spawns min(background_streaming_schedule_pool_size, background_schedule_pool_initial_size) workers plus the delayed thread and abort()s on thread-pool exhaustion. That means a server with enable_streaming_queries = 0 and no subscriptions now allocates about 17 extra threads by default and can fail startup under previously valid max_thread_pool_size configurations. Keep this pool lazy on initial load, for example by resizing it only if it already exists or by creating it only once streaming is actually enabled or used.
  • [src/Storages/MergeTree/BackgroundJobsAssignee.cpp:128] [dismissed by author -- https://github.com/Isolate streaming queries background jobs into the dedicated pool #105981#discussion_r3531433853] background_streaming_assignee.start() still runs unconditionally for every MergeTree / ReplicatedMergeTree table, and after this patch that always creates a task in the dedicated streaming pool even when subscription_manager.isEmpty(). scheduleStreamingJob then just re-arms the no-op task forever, so the new pool becomes unavoidable on any server with MergeTree tables and system.background_schedule_pool now shows a streaming task for ordinary tables with no active STREAM consumers. Starting the assignee only when the first streaming subscription is registered or needs wakeup would preserve isolation without turning the dedicated pool into permanent per-table overhead.

💡 Nits

  • [src/Storages/System/StorageSystemBackgroundSchedulePool.cpp:58] The pool column description still enumerates only schedule, buffer_flush, distributed, and message_broker. Now that the table can emit streaming, the structured docs exposed by system.documentation / DESCRIBE TABLE are stale; please add streaming to that description.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: keep BackgroundStreamingSchedulePool lazy so enable_streaming_queries = 0 and no subscriptions do not allocate extra threads or fail startup; stop starting background_streaming_assignee for every MergeTree table until streaming work actually exists; update the system.background_schedule_pool pool description to mention streaming.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 27, 2026
Comment thread src/Interpreters/Context.cpp Resolved
Comment thread src/Core/ServerSettings.cpp Resolved
@yariks5s yariks5s self-assigned this Jun 16, 2026
global_context->getSchedulePool().increaseThreadsCount(new_server_settings[ServerSetting::background_schedule_pool_size]);
global_context->getMessageBrokerSchedulePool().increaseThreadsCount(new_server_settings[ServerSetting::background_message_broker_schedule_pool_size]);
global_context->getDistributedSchedulePool().increaseThreadsCount(new_server_settings[ServerSetting::background_distributed_schedule_pool_size]);
global_context->getStreamingSchedulePool().increaseThreadsCount(new_server_settings[ServerSetting::background_streaming_schedule_pool_size]);

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 call sits inside the main ConfigReloader callback, so it runs during the initial config load as well, not only on later reloads. That means every server startup now constructs BackgroundStreamingSchedulePool even when enable_streaming_queries = 0 (the default experimental gate).

BackgroundSchedulePool::BackgroundSchedulePool eagerly spawns min(background_streaming_schedule_pool_size, background_schedule_pool_initial_size) workers plus the delayed thread and abort()s if the global thread pool cannot provide them. So this split is no longer pay-as-you-go: it adds ~17 threads by default and can turn previously valid max_thread_pool_size configurations into startup failures on installations that never use streaming queries.

Please keep the streaming pool lazy on initial load (for example, only resize it here if it was already created, or otherwise gate eager creation on the feature actually being enabled/used).

@alexey-milovidov

Copy link
Copy Markdown
Member

Updating the branch to fix the 04001_join_reorder_through_expression test, which was broken today in master.

@Michicosun
Michicosun enabled auto-merge July 6, 2026 21:10
fill_from_pool(context->getBufferFlushSchedulePool(), "buffer_flush");
fill_from_pool(context->getDistributedSchedulePool(), "distributed");
fill_from_pool(context->getMessageBrokerSchedulePool(), "message_broker");
fill_from_pool(context->getStreamingSchedulePool(), "streaming");

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.

The table can now emit pool = 'streaming', but the pool column description above still lists only schedule, buffer_flush, distributed, and message_broker. That leaves system.documentation / DESCRIBE TABLE system.background_schedule_pool inaccurate after this change. Please add streaming to the documented set of values.

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.

@groeneai, submit a PR with the documentation update after this PR is merged. Ping me in the new pr.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Will do. I'll open the documentation-update PR once this merges and ping you there.

@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR moves streaming background jobs into a dedicated BackgroundStreamingSchedulePool and wires up its settings and metrics — pure background task-scheduling plumbing that does not touch the query-execution path exercised by ClickBench SELECTs. All three flagged queries (Q4, Q18, Q28) showed apparent improvements, but they are off-path and fully consistent with the deterministic verdicts: Q4's -11.4% falls inside master's normal variance band (no_change), and Q18/Q28 remain not_sure with borderline, mixed signals (Q28 is also intrinsically noisy). No real performance change is attributable to this PR.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 18 not_sure 1292 1226 -5.1% 0.0055 Borderline with mixed signals from the two tests. The streaming schedule-pool split cannot touch this SELECT, so the ~5% gap is not a PR effect.
⚠️ 28 not_sure 1088 1034 -5.0% <0.0001 History is noisy for this query and the background-scheduling change is off-path, so the borderline ~5% delta is run-to-run variance, not a PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. 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

🟢 No significant changes

Debug info
  • StressHouse run: 14898608-b13a-4fbe-b967-3257aa5b9bff
  • MIRAI run: 8a761376-8f4c-45c4-a5dd-25e583b8feb8
  • PR check IDs:
    • clickbench_333957_1783864797
    • clickbench_333971_1783864797
    • clickbench_333976_1783864797
    • tpch_adapted_1_official_333982_1783864797
    • tpch_adapted_1_official_333986_1783864797
    • tpch_adapted_1_official_333996_1783864797

@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 83/84 (98.81%) · Uncovered code

Full report · Diff report

@Michicosun
Michicosun added this pull request to the merge queue Jul 12, 2026
Merged via the queue into master with commit b36641e Jul 12, 2026
176 checks passed
@Michicosun
Michicosun deleted the streaming-task-scheduling-settings branch July 12, 2026 17:49
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 12, 2026
subkanthi pushed a commit to subkanthi/ClickHouse that referenced this pull request Jul 13, 2026
PR ClickHouse#105981 added a dedicated 'streaming' background schedule pool for
streaming queries background jobs, so system.background_schedule_pool can
now emit pool = 'streaming'. Update the pool column description (source of
truth in StorageSystemBackgroundSchedulePool.cpp, mirrored in the
autogenerated docs page) and the table description accordingly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…cheduling-settings

Isolate streaming queries background jobs into the dedicated pool
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
PR ClickHouse#105981 added a dedicated 'streaming' background schedule pool for
streaming queries background jobs, so system.background_schedule_pool can
now emit pool = 'streaming'. Update the pool column description (source of
truth in StorageSystemBackgroundSchedulePool.cpp, mirrored in the
autogenerated docs page) and the table description accordingly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.

5 participants