Repository navigation
Conversation
c1b86d6 to
1863b12
Compare
|
All 19 checks are green now — this is ready for review. Note the diff is on top Also, is a 1.14.1 patch release planned for these two |
| def bench_fastapi(loops, url): | ||
| async def run_benchmark(): | ||
| async with httpx.AsyncClient(trust_env=False) as client: | ||
| limits = httpx.Limits(max_connections=CONCURRENCY) |
There was a problem hiding this comment.
Could we set max_keepalive_connections=20 here? Passing a new Limits object replaces AsyncClient’s default limits, so this also raises the effective idle cap from 20 to 150. That more than doubled the time per batch in my local spot checks.
There was a problem hiding this comment.
You're right — thanks for catching that. AsyncClient(limits=...) replaces DEFAULT_LIMITS (100/20) entirely, and httpcore resolves max_keepalive_connections=None to max_connections, so my version really did keep up to 150 idle connections.
I've set it explicitly now, which keeps the previous idle-connection behavior while only raising the ceiling:
limits = httpx.Limits(
max_connections=CONCURRENCY,
max_keepalive_connections=20,
)Re-verified: the resolved pool limits are max_connections=150 max_keepalive_connections=20 keepalive_expiry=5.0, and the PoolTimeout repro (150 concurrent requests against a ~6s endpoint) still completes.
I pushed this as an amended commit, so the PR diff now includes the keepalive cap.
1863b12 to
5597a47
Compare
Fixes #508
Problem
The
fastapibenchmark (bm_fastapi) intermittently fails withhttpx.PoolTimeoutwhen the machine running the benchmark is under heavy load.The benchmark fires
CONCURRENCY = 150concurrent requests, but thehttpx.AsyncClientuses httpx's defaultmax_connections = 100. The 50 requeststhat exceed the pool size wait in the pool's queue for a connection to free up.
httpx's default pool timeout is 5 seconds, so when the in-flight requests take
longer than 5 seconds (which is exactly what happens under load), those 50 queued
requests exceed the pool timeout and the benchmark dies:
Fix
Size the connection pool to the benchmark's concurrency so that no request ever
queues:
With the pool sized to
CONCURRENCY, all 150 requests acquire a connectionimmediately, so the pool timeout can never be hit regardless of server latency.
This builds on the trust_env=False change from #505 and keeps it
Testing
Reproduced deterministically by serving the endpoint with an artificial ~6s
per-request delay and firing 150 concurrent requests:
httpx.PoolTimeoutafter ~5.1smax_connections=150→ completes successfully (~7.1s)No behavior change in the common case: the benchmark's concurrency is a fixed
constant, so the pool is simply sized to match it.