From 5597a477c44f174d1b2bf5f8e5e9e6fae67e7055 Mon Sep 17 00:00:00 2001 From: Sendao Yan Date: Sun, 22 Nov 2026 10:01:08 +0800 Subject: [PATCH] Fix bm_fastapi benchmark failing with httpx.PoolTimeout under load --- .../data-files/benchmarks/bm_fastapi/run_benchmark.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyperformance/data-files/benchmarks/bm_fastapi/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_fastapi/run_benchmark.py index 09c7dc2c..3e6cb019 100644 --- a/pyperformance/data-files/benchmarks/bm_fastapi/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_fastapi/run_benchmark.py @@ -63,7 +63,14 @@ def setup_server(): def bench_fastapi(loops, url): async def run_benchmark(): - async with httpx.AsyncClient(trust_env=False) as client: + # Passing a Limits object replaces the AsyncClient defaults, so + # max_keepalive_connections must be set explicitly to keep the + # default idle-connection cap of 20 while raising max_connections. + limits = httpx.Limits( + max_connections=CONCURRENCY, + max_keepalive_connections=20, + ) + async with httpx.AsyncClient(limits=limits, trust_env=False) as client: t0 = pyperf.perf_counter() for i in range(loops):