You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bm_fastapi intermittently fails with httpx.PoolTimeout under load #508
The fastapi benchmark (bm_fastapi) intermittently fails with httpx.PoolTimeout when the machine running the benchmark is under heavy load.
This is a separate problem from the proxy-related 503 (issue #504).
Environment
pyperformance 1.14.0
Python 3.10
fastapi==0.121.0, httpx==0.28.1, uvicorn==0.38.0
No proxy involved (trust_env=False / no HTTP_PROXY)
How to reproduce
The benchmark fires CONCURRENCY = 150 concurrent requests against its own
uvicorn server. Reproduce deterministically by adding an artificial per-request
delay (simulating a slow server) and running 150 concurrent requests through an httpx.AsyncClient with the default pool:
RuntimeError: Benchmark died
ERROR: Benchmark fastapi failed: Benchmark died
Root cause
CONCURRENCY = 150, but the httpx.AsyncClient uses httpx's default max_connections = 100. The 50 requests that exceed the pool size wait in the
pool's queue for a connection to free up. httpx's default pool timeout is 5
seconds (httpx.Timeout(timeout=5.0)), so when the in-flight requests take
longer than 5 seconds (which is exactly when the machine is under load), the 50
queued requests exceed the pool timeout and raise httpx.PoolTimeout.
Expected behavior
The benchmark should complete regardless of how loaded the machine is, because
its own concurrency is a fixed constant: the connection pool should be sized to
match it.
Suggested fix
Size the connection pool to the benchmark's concurrency:
This removes the queuing entirely, so no request can exceed the pool timeout.
Scope
Only bm_fastapi is affected: it is the benchmark that combines a fixed CONCURRENCY (150) larger than httpx's default pool (100) with a httpx.AsyncClient created without explicit pool limits.
Activity