FastAPI 是最快的 Python 框架之一,因为它建立在 Starlette(一个轻量级 ASGI 框架)之上,并且是 async-native 的,能够有效地处理许多并发的 I/O 绑定请求。但是要保持它的速度,需要正确使用 async — 最常见的错误是阻塞事件循环。
为什么这很重要
text
✓ ASGI + Starlette — a modern async foundation (vs older WSGI sync frameworks)
✓ Async-native — one process handles thousands of concurrent I/O-bound requests
by overlapping wait times, instead of one-at-a-time
✓ Pydantic v2 — validation/serialization core is now in Rust (very fast)
✓ Minimal overhead per request
Async 模型是关键:当一个请求等待数据库查询或 API 调用时,服务器处理其他请求 — 为 I/O 绑定工作负载提供高吞吐量。
