Skip to content

Separate limits on number of waiting and executing queries - #61053

Merged
robot-ch-test-poll merged 4 commits into
masterfrom
async-loader-waiters-limit
Mar 22, 2024
Merged

robot-ch-test-poll merged 4 commits into
masterfrom
async-loader-waiters-limit

Conversation

@serxa

@serxa serxa commented Mar 7, 2024

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

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_queries that limits the number of queries waiting due to async_load_databases. Existing limits on number of executing queries no longer count waiting queries.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@serxa

serxa commented Mar 7, 2024

Copy link
Copy Markdown
Member Author

Testing this new setting is hard... trying to figure out what can be done. Ideas are welcome.

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-feature Pull request with new product feature label Mar 7, 2024
@robot-clickhouse-ci-1

robot-clickhouse-ci-1 commented Mar 7, 2024 •

Copy link
Copy Markdown
Contributor

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
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@serxa
serxa marked this pull request as ready for review March 11, 2024 11:28
@jkartseva jkartseva self-assigned this Mar 20, 2024
@serxa

serxa commented Mar 21, 2024

Copy link
Copy Markdown
Member Author

Let's merge with master, maybe it is better now than was:

src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o -MF src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o.d -o src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o -c /build/src/Interpreters/Aggregator.cpp
Mar 11 12:57:42 LLVM ERROR: out of memory
Mar 11 12:57:42 Allocation failed

@jkartseva jkartseva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good

Comment on lines +772 to +773
UInt64 limit = max_waiting_queries_amount.load();
UInt64 value = waiting_queries_amount.load();

@jkartseva jkartseva Mar 21, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't value acquisition happen inside the while loop?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc @serxa Please take a look at the comment (though I accepted it before that).
I think its a bug.

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.

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();

@jkartseva jkartseva Mar 21, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@robot-ch-test-poll
robot-ch-test-poll merged commit 03a4b5f into master Mar 22, 2024
@robot-ch-test-poll
robot-ch-test-poll deleted the async-loader-waiters-limit branch March 22, 2024 02:15
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 22, 2024
feiyunwill pushed a commit to feiyunwill/ClickHouse that referenced this pull request Oct 20, 2026
…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]>
feiyunwill pushed a commit to feiyunwill/ClickHouse that referenced this pull request Oct 20, 2026
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature 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