Repository navigation
Separate limits on number of waiting and executing queries - #61053
Conversation
|
Testing this new setting is hard... trying to figure out what can be done. Ideas are welcome. |
|
This is an automated comment for commit c31b958 with description of existing statuses. It's updated for the latest CI running ✅ Click here to open a full report in a separate page Successful checks
|
|
Let's merge with master, maybe it is better now than was: |
| UInt64 limit = max_waiting_queries_amount.load(); | ||
| UInt64 value = waiting_queries_amount.load(); |
There was a problem hiding this comment.
Shouldn't value acquisition happen inside the while loop?
There was a problem hiding this comment.
cc @serxa Please take a look at the comment (though I accepted it before that).
I think its a bug.
There was a problem hiding this comment.
it's okay. compare_exchange_strong updates the value if it fails
| std::atomic<int> waiters_total{0}; | ||
| int waiters_limit = 5; | ||
| auto waiters_inc = [&] (const LoadJobPtr &) { | ||
| int value = waiters_total.load(); |
There was a problem hiding this comment.
Same, loading value inside the while loop? Otherwise, it won't store the most recent value in the case where compare_exchange_strong has failed.
…ing_queries Restores the accounting added in ClickHouse#61053 and removed as dead code in ClickHouse#83277, with the two defects that kept it from working in the first place fixed. `limit == 0` is documented as "no limit", but the original check was `if (value >= limit) throw`, which refuses the very first waiter on a default-configured server. The limit is now consulted only when it is set. The per-query election used `waiting_threads.fetch_add(1) == 0` to decide which thread registers the query. When the limit check then threw, `waiting_threads` was left at 1 with the query never registered, so that query stayed exempt from the limit forever; rolling the counter back instead would race a second thread of the same query into a follower with no leader, which underflows the global counter. A per-query mutex makes the check run strictly before the counter moves, so a refused query is left exactly as it was. A query that the concurrency limits exempt (`KILL QUERY`, `SELECT FROM system.processes`, the introspection port) is counted but never refused: it is counted by the limits that the waiting amounts are subtracted from, and the admin needs it to work on a server that has hit the limit. Internal queries are outside both, matching `non_internal_processes` and `query_kind_amounts`. Nothing calls this yet; the load jobs are wired up in the next commit. Co-Authored-By: Claude Opus 5 <[email protected]>
`max_waiting_queries` documents that a query waiting for an asynchronously loading table is not counted when `max_concurrent_queries`, `max_concurrent_insert_queries`, `max_concurrent_select_queries`, `max_concurrent_queries_for_user` and `max_concurrent_queries_for_all_users` are checked, "to avoid hitting these limits just after server startup". That correction was added in ClickHouse#61053 and removed together with the rest of the waiting accounting in ClickHouse#83277, so the second half of the paragraph defining this setting has been false since then. It also makes the two limits compose. A waiting query holds a `max_concurrent_queries` slot without it, so with `max_concurrent_queries = 100` and `max_waiting_queries = 200` the 101st waiter is refused by the wrong limit and the configured 200 is unreachable. The discount is applied to all five checks including the `have_space` predicate, otherwise a query would be parked for `queue_max_wait_ms` and then refused despite it. The reported ", waiting: N" is emitted only when the count is non-zero, so an operator can tell why a limit did or did not fire; the existing tests that match these messages all match a prefix. In steady state all four waiting counters are zero and the behaviour is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Separate limits on number of waiting and executing queries. Added new server setting
max_waiting_queriesthat limits the number of queries waiting due toasync_load_databases. Existing limits on number of executing queries no longer count waiting queries.Documentation entry for user-facing changes