. - #1104
Closed
mgraczyk wants to merge 1 commit into
Closed
Conversation
_assign_requests_to_connections rebuilt the list of available connections
and the list of idle connections from scratch for every queued request, so
one pass cost O(queued requests x open connections). A pass runs on every
request arrival and every response close while holding the pool lock, so
a saturated pool (all connections busy, many requests waiting) spent most
of its time re-scanning: with 1,000 connections and 1,000-2,000 queued
requests a single pass took 0.5-1.0 seconds of pure Python.
Which connections are available or idle does not depend on the request
being assigned, and assigning a request does not change any connection's
state, so the per-request scans always produced the same lists apart from
the connections the loop itself created or closed. Compute both lists once
per pass, filter the available list by origin for each request, keep both
lists up to date as connections are created and closed, and stop early
once the pool is full with nothing idle or available. Assignment and close
decisions are identical to before.
Median time per pass with 1,000 open connections (CPython 3.13):
queued requests before after
100 49 ms 0.8 ms
1,000 497 ms 1.2 ms
2,000 1,001 ms 1.0 ms
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.
No description provided.