Repository navigation
Silk fibers integration - #112667
Silk fibers integration#112667
Conversation
|
Workflow [PR], commit [807db50] Summary: ✅
AI ReviewSummaryThis PR adds the initial Findings❌ Blockers
Tests
Final VerdictNot ready for merge. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 720/748 (96.26%) · Uncovered code |
Conflicts: * `src/Client/ConnectionPool.cpp`: master fixed `ConnectionPool::getUnchecked` to translate `connection_pool_max_wait_ms == 0` into the negative "infinite" timeout that `PoolBase::get` expects; this branch had moved `get`/`getUnchecked` into the `ConnectionPoolImpl` template in the header, so the fix now lives in `connectionPoolMaxWaitMilliseconds`, its only caller. * `src/Common/Fiber.h`: this branch replaced `Fiber` with `StackfulCoroutine`; master moved `Fiber::getCurrentFiber` into a new `Fiber.cpp` to fix a `-Wunique-object-duplication` site. Both `Fiber.h` and `Fiber.cpp` are dropped and the same fix is applied to `StackfulCoroutine::getCurrentCoroutine` via a new `src/Common/StackfulCoroutine.cpp`. Co-Authored-By: Claude Opus 5 <[email protected]>
…e_silk_runtime` Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The `std::optional<ThreadName>` parameter had no caller in this branch; the fiber job that attaches to a thread group without renaming its carrier OS thread lands with the silk `QueryRunner` work instead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| { | ||
| enum : size_t | ||
| { | ||
| CurrentThread, |
There was a problem hiding this comment.
I find it confusing that this enum fields have the same names as already existed classes.
Should we name enums values with capitals letters?
|
|
||
| static void swap(FiberLocalStorage & saved) noexcept | ||
| { | ||
| thread_storage.slots.swap(saved.slots); |
There was a problem hiding this comment.
this takes linear time O(slot::Count).
It is ok if its count is not huge and each type is moved fast and easy.
Do we have constrains that no one would store heavy type in such slot?
There was a problem hiding this comment.
One slot is always 64 bits.
If the type is scalar (i.e. pointers, ints, floats), we store it inline in the slot (https://github.com/ClickHouse/ClickHouse/pull/112667/changes#diff-ecac0157c8d879585589db3b2d73420ebe6fb7640c3561b7eb015fb3d788b209R224).
If the type is non-scalar (e.g. any struct), we allocate on the heap and only store the pointer in the slot (https://github.com/ClickHouse/ClickHouse/pull/112667/changes#diff-ecac0157c8d879585589db3b2d73420ebe6fb7640c3561b7eb015fb3d788b209R234).
So expect that the whole slots arena is 2 cache lines max. I'll add a static assert for that.
There was a problem hiding this comment.
If we ever need more than 2 cache lines, we can optimize. For example, by storing bools more efficiently.
But I doubt it will ever come to that.
CheSema
left a comment
There was a problem hiding this comment.
Ok in general, fix the tests and go
| { | ||
| return silk::FiberScheduler::run( | ||
| &FiberContext::main, | ||
| FiberContext{ .fiber_local_storage = FiberLocalStorage::create(), .task = std::move(task) }, |
There was a problem hiding this comment.
This starts every silk fiber from a zeroed FiberLocalStorage, and main() then creates a detached ThreadStatus. A fiber spawned under a live query therefore loses the caller's TRACE_CONTEXT, blocker state, query-group attachment, and cancellation/memory-tracking context: CurrentThread::checkIfNotCancelled() becomes a no-op, and the first flush in CurrentMemoryTracker goes only to the new thread tracker/total_memory_tracker instead of the caller's query/user trackers.
The first subsystem that runs real query work under Silk::runBlocking will therefore bypass query limits, tracing, and cancellation. Please seed the fiber from the caller's execution context (or explicitly capture the caller's ThreadGroup / trace context and attach the new ThreadStatus to it) instead of always using FiberLocalStorage::create().
| )", 0) \ | ||
| DECLARE(String, keeper_hosts, "", R"(Dynamic setting. Contains a set of [Zoo]Keeper hosts ClickHouse can potentially connect to. Doesn't expose information from `<auxiliary_zookeepers>`)", 0) \ | ||
| DECLARE(Bool, allow_experimental_webassembly_udf, false, R"(Enable experimental support for WebAssembly UDFs)", EXPERIMENTAL) \ | ||
| DECLARE(Bool, enable_silk_runtime, false, R"(Enable experimental support for the silk fiber runtime: initialize the silk fiber scheduler at server startup, so that subsystems supporting it can run their jobs on fibers)", EXPERIMENTAL) \ |
There was a problem hiding this comment.
This setting is declared on every build, but its only side effect is compiled out under #if USE_SILK in programs/server/Server.cpp, and checkUnknownSettings also whitelists the <silk> subtree unconditionally. On unsupported builds (USE_SILK=0), enable_silk_runtime=1 therefore starts successfully and silently does nothing.
That violates the setting's contract and makes misconfigured deployments look enabled when the runtime is unavailable. Please reject the setting at startup (or hide it when USE_SILK=0) instead of turning it into a no-op.
# Conflicts: # src/Client/Connection.cpp # src/IO/tests/gtest_silk_fiber_stream_socket.cpp
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes61 object files changed (+299.54 KiB total), 6 added.
739 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 units1537 translation units recompiled, 10109 s compile time in total, 1531 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
📊 Cloud Performance Report ✅ AI verdict: Release-transition baseline: compared against the last 26.8 master because no 26.9 master baseline exists at or before the trusted base-commit anchor. This change introduces a Silk fiber runtime (gated behind a server setting that is off by default) along with build-system, TLS-sanitizer, and client-side connection plumbing (socket factory, coroutine rename, distributed connection-pool cleanup). None of that touches the single-node query-execution path that ClickBench and TPC-H exercise. All four flagged queries remain not_sure: Q18 and Q28 are borderline improvements with mixed signals, and Q30/Q31 are small regressions that fall inside master's normal variance band. The envelope suppressions look correct, and every delta here is best read as run-to-run noise rather than a real effect of this PR. clickbenchFlagged queries (4 of 43)
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
|
|
|
||
| ln -sf $SRC_PATH/config.d/transactions_info_log.xml $DEST_SERVER_PATH/config.d/ | ||
| ln -sf $SRC_PATH/config.d/transactions.xml $DEST_SERVER_PATH/config.d/ | ||
| ln -sf $SRC_PATH/config.d/silk.xml $DEST_SERVER_PATH/config.d/ |
There was a problem hiding this comment.
install.sh is reused by the --previous-release and --bugfix-validation paths, but this new symlink is unconditional. Older release binaries do not know enable_silk_runtime / <silk> yet, so they will fail to start just from loading [tests/config/config.d/silk.xml].
Please gate this the same way the script already gates other new configs: at least by the first released version that contains the setting, and ideally also by system.build_options reporting USE_SILK=1.
| return; | ||
|
|
||
| #if USE_SILK | ||
| if (silk::FiberScheduler::getCurrentFiberId().raw) |
There was a problem hiding this comment.
checkStackSize is the existing boundary that turns user-controlled recursion into a TOO_DEEP_RECURSION exception. Returning early for every silk fiber removes that guard entirely, and the new runtime's default stack is only 320 KiB.
The first parser/analyzer/format path moved onto Silk::runBlocking will therefore stop failing with TOO_DEEP_RECURSION and instead exhaust the fiber stack. Please either implement the equivalent bound check for fiber stacks, or keep recursive query work off silk fibers until that exists.
`src/Common/Fiber.h` is deleted on this branch in favour of `src/Common/StackfulCoroutine.h`, and master grew `~Fiber` plus a move assignment that unwind a suspended fiber's stack with the fiber installed as the current one. That unwinding now matters: master also puts an `OpenTelemetry::TracingContextHolder` on the coroutine stack in `AsyncTaskExecutor::Routine`, and its destructor writes the tracing context while the stack is being unwound. Port `unwind` to `StackfulCoroutine`, swapping the coroutine-local slots in around the destruction so that write lands in the coroutine's slots instead of the thread's. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Conflict carrier: src/Common/PoolBase.h. The silk integration (ClickHouse#112667) moved Entry out of PoolBase into a standalone PoolEntry<TObject>, gave PoolBase the TLocker/TWaiter template parameters, replaced PoolEntryHelper's PooledObject back-reference with an on_destroy callback built by a new makeEntry(), dropped Entry::getPool() and with it the LOGICAL_ERROR declaration and the Common/Exception.h include. All of that is kept verbatim; only the wait itself is re-applied on top, so the resolved file differs from master by exactly this branch's change. The master side of the wait block could not be taken: it is a single wait_for() with no deadline re-check, which is the defect this branch fixes. Two consequences of the refactor for this branch: - Common/Exception.h and an ErrorCodes declaration come back, now for NO_FREE_CONNECTION alone. LOGICAL_ERROR stays deleted, since getPool() was its only user. - The wait uses the two-argument wait_for() and tests the predicate itself. TWaiter is no longer always std::condition_variable: Silk::FiberCondVarAdapter (src/Client/SilkConnectionPool.h) offers wait(), notify_one(), notify_all() and a two-argument wait_for() only, and is instantiated through Silk::ConnectionPool, so the predicate overload would not compile. The clamped millisecond value is now computed once and used for the deadline, the log line and the NO_FREE_CONNECTION message. Master already logged the clamped value; this keeps that and makes the message state the wait that actually applied rather than an unclamped request.
…previous release `tests/config/install.sh` applies the current-master test configs to the previous-release server, which is the point of the `Upgrade check` job (`tests/docker_scripts/upgrade_runner.sh:91` installs the previous-release packages, `:131` then runs `configure ... --previous-release`). Line 148 symlinked `config.d/silk.xml` unconditionally, and that file declares two top-level elements, `enable_silk_runtime` and `silk`, which first exist in 26.9. A server that does not know a top-level config key rejects it with `UNKNOWN_ELEMENT_IN_CONFIG` and refuses to start, so `Upgrade check (amd_release)` failed on every PR run from 2026-08-30 13:48Z: every start attempt failed and the job reported `Cannot start clickhouse-server` with no test having run. A comment at the top of `install.sh` already states the rule the line broke: a new config must check the ClickHouse version so it does not break validations that run a previous ClickHouse version. The line was written in `c3f40eb660cf` and reached master with PR #112667 on 2026-08-26, but only bit four days later, because the previous release changed under it. Measured on `src/Core/ServerSettings.cpp` per ref: ref "found in config" enable_silk_runtime 26.7 0 0 26.8 1 0 master 1 1 26.7 tolerated both elements because it validates no unknown top-level keys at all; 26.8 added `ServerSettings::checkUnknownSettings` and does not know them. Publishing `v26.8.1.2041-lts` at 2026-08-30T13:47:42Z moved what `tests/ci/get_previous_release_tag.py` resolves to from 26.7 to 26.8. A passing and a failing run seven minutes apart build the same master package `clickhouse-client_26.9.1.1_amd64.deb` and differ only in `previous_release_tag`. Gate the symlink on the installed server's version. `check_clickhouse_version` reads `clickhouse --version` from `PATH`, i.e. the version of the very binary that will read the config being written, so the gate protects any invocation with an old binary rather than only the one that passes `--previous-release`. The literal is 26.9 because `cmake/autogenerated_versions.txt` was already at `VERSION_STRING 26.9.1.1` two days before silk merged, `config.d/silk.xml` does not exist on ref 26.8, and 26.8's `ServerSettings.cpp` has no `enable_silk_runtime`. This mirrors the way the same file already gates `http_url_prefix.xml` on 26.8 for this defect class. No release branch installs the drop-in, so no backport is needed. Servers that can parse the drop-in still receive it, including the post-upgrade phase at `upgrade_runner.sh:175`, so no coverage is lost. Validated locally against the `v26.8.1.2041-lts` packages CI itself downloads, with no build required. Before the change the drop-in is installed and the 26.8 server reproduces `Code: 137 ... Unknown elements 'enable_silk_runtime', 'silk' ... (UNKNOWN_ELEMENT_IN_CONFIG)`. After it the drop-in is skipped and the server reaches `Starting ClickHouse 26.8.1.2041` and the executable integrity check before dying on an absent local MinIO with an unrelated `Code: 499`, on both of the flag branches `configure` can take. A 26.9 binary still installs it. `checkUnknownSettings` accumulates every unknown key before throwing, so the pre-fix exception is an exhaustive list of what 26.8 rejects in the real config set, and it names only these two keys.
Splits the silk runtime integration out of #111275, so that it can be reviewed on its own. This adds the plumbing that lets ClickHouse run work on silk fibers, without yet putting any subsystem on them.
Silk::initializeFiberScheduler/Silk::destroyFiberScheduler, called by the server when theenable_silk_runtimeserver setting is enabled. The fiber stack size is configurable through thesilk.fiber_stack_sizeconfiguration key (320 KiB by default, which leaves enough room for OpenSSL handshakes).FiberLocal- fiber-local storage. A fiber can migrate between operating-system threads, so it must not observe another fiber'sthread_localstate; the values of the registered slots are swapped in and out on every fiber switch instead.current_thread(ThreadStatus), the OpenTelemetry tracing context, and the memory-tracker and exception blockers are moved to it.utils/silk-thread-local-storage-sanitizerthat instruments everythread_localaccess and aborts when a fiber touches raw thread-local storage. Without it, a variable that was not migrated toFiberLocalproduces silent corruption rather than a diagnostic. It is enabled in the debug and ASan CI builds.Silk::ConnectionPoolandSilk::streamSocketFactory- aConnectionpool and a socket factory that suspend the calling fiber instead of blocking the operating-system thread.PoolBaseandConnectionPoolare templated on the lock and the condition variable to make that possible, andConnectionPoolstays an alias of thestd::mutexinstantiation, so the existing call sites are unchanged.io_uringrings - is charged tototal_memory_trackerthrough silk's mmap accounting hooks.system.asynchronous_metricsunder aSilkprefix.Common/Fiber.handCommon/FiberStack.hare renamed toCommon/StackfulCoroutine.handCommon/CoroutineStack.h. They implement the boost-context coroutines used byAsyncTaskExecutor, which are unrelated to silk fibers, and having two different things called "fiber" in the same codebase is confusing.Related: #111275
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added experimental support for the silk fiber runtime, enabled with the
enable_silk_runtimeserver setting. When it is enabled, the server initializes the silk fiber scheduler at startup, so that subsystems supporting it can run their jobs on fibers instead of occupying an operating-system thread while waiting for I/O.Workflow [PR]
Sync PR [sync-upstream/pr/112667]
Version info
26.9.1.156(included in26.9and later)