FastAPI + SQLAlchemy 接口从 800ms 优化到 45ms:一次真实的性能调优过程
线上一个基于 FastAPI 0.110 + SQLAlchemy 2.0 + PostgreSQL 14 的订单查询接口,P95 延迟高达 820ms,QPS 一过 200 就开始大量超时。通过 cProfile + py-spy 定位到 N+1 查询和缺失索引,配合 Redis 缓存与 ORM 加载策略调整,最终 P95 降到 45ms,单机 QPS 从 210 提升到 1400+。本文完整记
