Repository navigation
fix: leave Granian backpressure at its default - #82
Merged
Merged
Conversation
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.
Same change as modern-python/fastapi-sqlalchemy-template#105. Reverts the backpressure half of #77.
Granian's
backpressurelimits open connections per worker, not requests in flight. Each worker takes a semaphore permit beforeaccept()and releases it when the TCP connection closes (granian v2.8.3,src/workers.rslines 704 and 1074). An idle keep-alive connection holds its permit, so withbackpressureset to the pool size (5 by default) a reverse proxy that keeps upstream connections open can take every slot by itself. New connections then wait in the backlog until Granian drops an idle one at--http1-header-read-timeout, 30 s by default, even when the app is doing nothing.Reproduced locally with
backpressure=2, two idle HTTP/1.1 keep-alive clients, and then a third request:--backpressure 2--backpressure 2 --http1-header-read-timeout 5000Changes
app/__main__.pyno longer passesbackpressure, so Granian uses its default (backlog / workers).test_mainasserts thatbackpressureis not passed.Overload is still bounded. A request that finds the pool empty waits for a connection, and after
DB_POOL_TIMEOUTit gets a 503 fromdatabase_unavailable_handler. The 30 s default for that timeout is unchanged here. Lowering it would shed load sooner, and that is a separate decision.Testing
just test: 87 passed, 100% coverage.ruff format --checkandruff checkare clean.ty checkruns in CI, because the dev environment does not install on macOS (pyroscope-iofails to build).