Skip to content

Add web framework benchmark example (Barq)#317

Open
grandimam wants to merge 2 commits intoQuansight-Labs:mainfrom
grandimam:add-web-framework-example
Open

Add web framework benchmark example (Barq)#317
grandimam wants to merge 2 commits intoQuansight-Labs:mainfrom
grandimam:add-web-framework-example

Conversation

@grandimam
Copy link

Demonstrates free-threaded Python performance benefits for web frameworks:

  • Pure Python HTTP framework using ThreadPoolExecutor
  • 2-5x faster than FastAPI on various workloads
  • Shows thread scaling with CPU-bound handlers

Demonstrates free-threaded Python performance benefits for web frameworks:
- Pure Python HTTP framework using ThreadPoolExecutor
- 2-5x faster than FastAPI on various workloads
- Shows thread scaling with CPU-bound handlers
@ngoldbaum
Copy link
Collaborator

@nascheme would you mind giving this a look, along with barq? You know a lot more about web development than I do.

@nascheme
Copy link
Collaborator

nascheme commented Mar 4, 2026

I think this is a pretty good example of how to use free-threaded Python to build such a thing. The HTTP/1.1 protocol implementation is skeletal, let's say. The readme has an "Experimental" note and that's good. As an example for people to learn from, I think the simpler code is an advantage.

I have submitted a PR that updates it to use Python 3.14t. I think it would be a good idea even though I'm not sure how much extra performance that gives. 3.14 has been released for a while now so there should be no problem in using it.

@nascheme
Copy link
Collaborator

nascheme commented Mar 4, 2026

Oh, one additional suggestion for @grandimam, I think this statement in your readme might be misleading:

2-5x faster than FastAPI on real workloads.

How have you tested it on real workloads? If you are talking about the scripts inside benchmarks then I think it's quite a stretch to call those "real". I'd suggest re-wording that. In this PR, you say "various workloads".

@nascheme
Copy link
Collaborator

nascheme commented Mar 4, 2026

For interests sake, here are benchmark results on my 28-core i7-14700K. I'm using 10 barq workers.

The difference between 3.13t and 3.14t seems primarily noise, would need more complex benchmark tests to see if one is actually faster.

============================================================
  BARQ vs FASTAPI (optimal configs)
  2000 requests, 100 concurrent clients
============================================================
  Barq: 10 threads, blocking I/O
  FastAPI: async + aiosqlite
============================================================

Starting servers...
Servers ready.

─── JSON ───
  Barq (10 threads)
    2000/2000 ok, 12002.0 req/s
    latency: avg=2.1ms p50=1.9ms p99=7.2ms
  FastAPI (async)
    2000/2000 ok, 4975.2 req/s
    latency: avg=19.3ms p50=18.6ms p99=28.5ms
    → Barq 141.2% faster

─── DB ───
  Barq (10 threads)
    2000/2000 ok, 40472.5 req/s
    latency: avg=2.1ms p50=2.0ms p99=4.4ms
  FastAPI (async)
    2000/2000 ok, 2587.5 req/s
    latency: avg=38.2ms p50=34.7ms p99=64.6ms
    → Barq 1464.1% faster

─── CPU ───
  Barq (10 threads)
    2000/2000 ok, 3341.4 req/s
    latency: avg=29.1ms p50=29.5ms p99=32.1ms
  FastAPI (async)
    2000/2000 ok, 368.8 req/s
    latency: avg=264.5ms p50=270.0ms p99=278.1ms
    → Barq 806.0% faster

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants