Repository navigation
fix: give Crow a floor of 8 threads so a stalled instance still answers (#120) - #121
Merged
Merged
Conversation
…rs (#120) Crow runs a request handler on the server thread that owns its connection, and dedicates one thread to accepting - so `concurrency` threads give `concurrency - 1` usable ones. flAPI used `hardware_concurrency()`, which on a 1- or 2-vCPU container (Cloud Run's default) leaves a SINGLE thread. One slow synchronous query then blocks every other connection on the instance, `/health` included. Measured, one ~5s query in flight, 40 CONCURRENT health probes: 1 server thread: 40/40 blocked, 0/40 reported the stall 7 server threads: 5/40 blocked, 35/40 reported the stall The first row is the one that matters. On a small instance readiness does not merely miss the stall sometimes - it NEVER reports it. Every probe waits out the query and then answers 200 ready, so the stall detection shipped in v26.09.20 does nothing there. The floor makes that unlikely rather than impossible; the honest fix is running handlers off the server threads, which #120 stays open for. These threads wait on sockets, so over-providing them costs stacks, not CPU. Two measurement notes, both of which cost time here: - This must be measured with CONCURRENT probes. Sequential ones cannot see it: the first probe to block waits out the query and every later one runs after it finished, so at most one can ever block, whatever the thread count. An earlier sequential run reported a flat "1/40" for every configuration and meant nothing. - `taskset` does not change `std::thread::hardware_concurrency()` on glibc - it kept reporting 32 - so pinning CPUs does not simulate a small instance. The numbers above come from binaries with the count forced. - Add APIServer::serverThreadCount(), unit-tested at the floor, above it, at 0 (which hardware_concurrency() may legally return) and at the uint16_t cap - Document the behaviour in CONFIG_REFERENCE next to stall-timeout-s, with the measurements and the pointer to #120
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Crow runs a request handler on the server thread that owns its connection, and dedicates one thread to accepting — so
concurrencythreads giveconcurrency - 1usable ones. flAPI usedhardware_concurrency(), which on a 1- or 2-vCPU container — Cloud Run's default — leaves a single thread. One slow synchronous query then blocks every other connection on the instance,/healthincluded.That means the stall detection shipped in v26.09.20 does nothing on a small instance: the probe never gets to answer.
Measured
One ~5s query in flight, 40 concurrent
GET /healthprobes:503 stalledConsistent with roughly 1-in-threads. The first row is the point: readiness does not merely miss the stall occasionally, it never reports it — every probe waits out the query and then answers
200 ready.What
max(hardware_concurrency, 8), capped at 64. Not configurable. These threads wait on sockets, so over-providing them costs thread stacks, not CPU.This makes the failure unlikely, not impossible — 5 of 40 probes still blocked at 7 threads. The honest fix is running handlers off the server threads, and #120 stays open for it.
Two measurement traps, both hit here
1/40for every configuration and carried no information.tasksetdoes not changestd::thread::hardware_concurrency()on glibc — it kept reporting 32, so pinning CPUs does not simulate a small instance. The numbers above come from binaries with the count forced.Both are recorded in the test file so the next person does not repeat them.
Testing
serverThreadCount()unit-tested at the floor, above it, at0(whichhardware_concurrency()may legally return), and at theuint16_tcap. 765 unit tests, 334 standalone integration tests.Part of #120, which stays open for the real fix.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.