-
-
Notifications
You must be signed in to change notification settings - Fork 200
Add FastAPI HTTP request benchmark #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi! Just passing by and wanted to put my two cents in. I’m a bit unsure about adding this to the benchmark suite though. pyperformance already have an async HTTP benchmark with Tornado (bm_tornado_http) that covers Python async request handling. FastAPI, by contrast, pulls in extra layers: especially Pydantic, which does validation in Rust. I worry it could add noise rather than useful data about Python performance, if there’s ever a regression in this benchmark, it might be hard to tell what caused it. Maybe this fits better as an external benchmark rather than part of the core suite? Not trying to nitpick, just genuinely curious what’s the goal to measure here? For a real-world minimal FastAPI app, this example lacks database or business logic and only serves semi-static responses, so I’m not sure what Python-side behavior it’s meant to represent |
|
I think there are a couple things to consider here:
|
pyperformance/data-files/benchmarks/bm_fastapi/run_benchmark.py
Outdated
Show resolved
Hide resolved
pyperformance/data-files/benchmarks/bm_fastapi/run_benchmark.py
Outdated
Show resolved
Hide resolved
|
Just curious, do you have benchmark numbers for this benchmark? |
|
I mean, running it locally: Unfortunately, many of the I/O heavy benchmarks are unstable (e.g. Tornado is as well). Diego and I spent a bunch of time going back and forth trying to make this more stable. |
|
I meant a comparison between like 3.10 and 3.14. |
|
Sure, looks like ~73% faster (with 3.10: fastapi_http: Mean +- std dev: 215 ms +- 15 ms 3.14: fastapi_http: Mean +- std dev: 124 ms +- 2 ms Update: with more processes this looks more like a ~57% speedup...so not quite as good but still a solid improvement. |
|
Nice! asyncio benchmarks show similar ~80% improvement between 3.10 and 3.14. A significant part of speedup would be from python/cpython#107803 in 3.14, either way happy to see that FastAPI performance has improved similar to asyncio :) |
|
Just for transparency (with |
diegorusso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for adding FastAPI to pyperformance.
|
Thanks for all the feedback/reviews @diegorusso! |
I discovered that we didn't have a benchmark in here for FastAPI so I figured I'd add one in to start. This is a pretty basic example of canonical FastAPI request handling.