GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix `bm_fastapi` benchmark failing with `httpx.PoolTimeout` under load by sendaoYan · Pull Request #509 · python/pyperformance

Conversation

@sendaoYan

@sendaoYan sendaoYan commented Nov 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #508

Problem

The fastapi benchmark (bm_fastapi) intermittently fails with
httpx.PoolTimeout when the machine running the benchmark is under heavy load.

The benchmark fires CONCURRENCY = 150 concurrent requests, 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, 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:

httpx.PoolTimeout
RuntimeError: Benchmark died
ERROR: Benchmark fastapi failed: Benchmark died

Fix

Size the connection pool to the benchmark's concurrency so that no request ever
queues:

-        async with httpx.AsyncClient(trust_env=False) as client:
+        limits = httpx.Limits(max_connections=CONCURRENCY)
+        async with httpx.AsyncClient(limits=limits, trust_env=False) as client:

With the pool sized to CONCURRENCY, all 150 requests acquire a connection
immediately, 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:

  • Before: default pool (100 connections) → httpx.PoolTimeout after ~5.1s
  • After: max_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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sendaoYan

sendaoYan commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Note: this touches the same httpx.AsyncClient(...) line as #505. Once #505 is
merged, the resolved form should be:

async with httpx.AsyncClient(
    trust_env=False,
    limits=httpx.Limits(max_connections=CONCURRENCY),
) as client:
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sendaoYan
Fix bm_fastapi benchmark failing with httpx.PoolTimeout under load
1863b12
@sendaoYan
sendaoYan force-pushed the fix-fastapi-pool-timeout branch from c1b86d6 to 1863b12 Compare November 10, 2026 02:07
@sendaoYan

sendaoYan commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

All 19 checks are green now — this is ready for review. Note the diff is on top
of #505, so the trust_env=False fix is preserved and extended.

Also, is a 1.14.1 patch release planned for these two bm_fastapi fixes? Anyone
still on the current PyPI release (1.14.0) hits both bugs — and 1.14.0 is the
last release that still supports Python 3.10.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bm_fastapi intermittently fails with httpx.PoolTimeout under load

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@sendaoYan
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.