Repository navigation
Issue AI function requests concurrently from a server-wide thread pool - #122484
Conversation
Requests run on `getAIRequestThreadPool` (a `StaticThreadPool`), configured by `max_ai_request_thread_pool_size`, `max_ai_request_thread_pool_free_size` and `ai_request_thread_pool_queue_size`. `ai_function_max_concurrent_requests` bounds one function call's share. Retries, API-call reservation and token accounting move into `submitAIRequest` / `submitAIEmbeddingRequest`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`AIQuotaTracker::checkQuotas` and `recordApiCall` throw on `KILL QUERY` or `max_execution_time`, so a killed query no longer finishes its current block, and queued requests and retries are not dispatched. Also doc and comment tweaks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`submitAIRequest` is overloaded for both request types over one `submit` template; `runAttempt` overloads pick `call` or `embed`. `AIEmbeddingResponse` gains an always-zero `output_tokens`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A `/v1/chat/jitter` mock endpoint answers after a random delay, so concurrent responses complete out of order. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`ai_function_max_concurrent_requests` becomes `ai_function_max_concurrent_requests_per_stream`, defaulting to 16. `max_ai_request_thread_pool_size` defaults to 1000. Token-quota tests pin the setting to 1. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Measured against the inference gateway, 8 per stream keeps a typical query within provider rate limits, and 3 retries absorb the remaining 429s. Tests that call unreachable endpoints pin one retry. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
Settings history moved into the declarations on master: the new `ai_function_max_concurrent_requests_per_stream` and the `ai_function_max_retries` default change now carry their 26.10 records there. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [8edef79] Summary: ✅
AI ReviewSummaryReviewed #122484 at Findings❌ Blockers
Missing context / blind spots
Tests
Final VerdictStatus: ❌ Block. Preserve previously valid retry configurations under older |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes89 object files changed (+329.36 KiB total), 1 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units551 translation units recompiled, 4926 s compile time in total, 549 of them have a recent master baseline. Translation units without a recent master baseline:
|
`ai_function_max_concurrent_requests_per_stream` becomes `..._per_thread`, and the pool settings become `ai_function_max_thread_pool_size`, `ai_function_max_thread_pool_free_size` and `ai_function_thread_pool_queue_size`. Regenerated reference docs for these settings. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
New `ProfileEvents`: `AIAPICallsRetried`, `AIAPICallsFailed` (including errors replaced by a default value) and `AIAPICallsThrottled` (HTTP 429). Server-wide totals and history come from `system.events` and `system.metric_log`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…me limits `ai_function_max_concurrent_requests_per_thread` records 1 -> 8 in 26.10, so `compatibility` below 26.10 keeps the previous serial behavior. Integration tests cover `max_execution_time` with both overflow modes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Adapt the request executor to 26.8's value-returning `IAIProvider::call`/`embed`, without porting #114905 or its tests. Keep 26.8's generated docs pages and `aiEmbed` row counters; add the settings changes to the `26.8` block of `SettingsChangesHistory`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #122484 to 26.8: Issue AI function requests concurrently from a server-wide thread pool
…m a server-wide thread pool
Keep 26.9's generated docs pages and `Settings.cpp` form; add the settings changes to the `26.9` block of `SettingsChangesHistory`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #122484 to 26.9: Issue AI function requests concurrently from a server-wide thread pool
…m a server-wide thread pool
Backport #122484 to 26.10: Issue AI function requests concurrently from a server-wide thread pool
Backport #122484 to 26.9: Issue AI function requests concurrently from a server-wide thread pool
Backport #122484 to 26.8: Issue AI function requests concurrently from a server-wide thread pool
…4-26.10 [26.10] Record the #122484 settings changes under 26.10
…m a server-wide thread pool
…m a server-wide thread pool
…om a server-wide thread pool
The clean backport kept master's `26.11` records, so `compatibility = '26.10'` reverted `ai_function_max_retries` and `ai_function_max_concurrent_requests_per_thread`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves #112248.
Explicit multithreading for AI functions.
Reasoning: AI funcs don't use any local compute and so the traditional concurrency in ClickHouse is not enough. In my tests I was not able to get above ~6 concurrent streams with default settings, ~12 with more parts per table. I tested up to 1m rows.
This PR implements a server-wide static thread pool (
AIRequestThreadPool), and each query thread keeps up toai_function_max_concurrent_requests_per_thread(default 8) of them in flight. Retries with backoff, API-call reservation and token accounting run on the pool workers.ai_function_max_thread_pool_size(default 1000),ai_function_max_thread_pool_free_size,ai_function_thread_pool_queue_size, changeable without restart.ai_function_max_retriesdefaults to 3 (was 1), so 429 responses from rate-limited providers under concurrent requests are retried.ProfileEventsAIAPICallsRetried,AIAPICallsFailedandAIAPICallsThrottled(HTTP 429), per query insystem.query_logand per server insystem.eventsandsystem.metric_log.Tested against a mock endpoint up to 1M rows, and against the ClickHouse inference gateway with
nova-micro,claude-haiku-4-5,gpt-oss-20bandtext-embedding-3-small. With the defaults, a typical query stays within provider rate limits;nova-microis throttled above roughly 4,300 requests per minute by the retries.Important decisions
ai_function_max_concurrent_requests_per_threadbe per query thread instead of overall for implementation simplicity. If this is too confusing (thinking about requests per thread x number of threads) it is not too difficult to make it a per-query setting that uses a semaphore to enforce the total concurrent requests per query.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
AI functions issue provider requests concurrently from a server-wide thread pool (
ai_function_max_thread_pool_size), with up toai_function_max_concurrent_requests_per_threadrequests in flight per query thread (default 8).ai_function_max_retriesdefaults to 3, and newProfileEventscount retried, failed and throttled provider requests.Workflow [PR]
Sync PR [sync-upstream/pr/122484]
Version info
26.11.1.671-master(included in26.11and later)