测试时间: 2026-05-18 23:43:01
| 项目 | 值 |
|---|---|
| 测试工具 | Apache Benchmark (ab) |
| 总请求数 | 10000 |
| 预热请求数 | 1000 |
| 迭代次数 | 3 (取中位数) |
| 并发级别 | 100 500 1000 |
| 响应内容 | 纯文本 "Hello world" |
| Keep-Alive | 启用 |
为确保测试公平性,本次测试遵循以下原则:
- 响应格式一致: 所有框架均返回纯文本
Hello world,FastAPI 使用PlainTextResponse避免JSON序列化开销 - 预热阶段: 每次正式测试前执行 1000 次预热请求,消除冷启动影响
- 多次迭代: 每个测试场景执行 3 次迭代,取中位数减少波动
- 端口清理: 每次测试前后彻底清理端口占用,确保无残留进程
- 健康检查: 启动服务器后通过 HTTP 请求验证服务可用性
- 响应验证: 验证服务器返回内容正确性
- 失败过滤: 失败请求超过 100 的迭代结果自动丢弃
| 框架 | 部署模式 | Worker 类型 | 协议 | 说明 |
|---|---|---|---|---|
| LiteFS | HttpServer | 内置多进程 | HTTP/1.1 | LiteFS 自带 HTTP 服务器 |
| LiteFS | Gunicorn | gevent (WSGI) | HTTP/1.1 | 生产环境推荐部署方式 |
| FastAPI | Gunicorn + Uvicorn | UvicornWorker (ASGI) | HTTP/1.1 | FastAPI 生产环境推荐部署 |
| FastAPI | Uvicorn | uvloop (ASGI) | HTTP/1.1 | FastAPI 轻量级部署方式 |
| 并发数 | LiteFS+HttpServer | LiteFS+Gunicorn | FastAPI+Gunicorn+Uvicorn | FastAPI+Uvicorn | LiteFS/HS vs FastAPI/GU | LiteFS/Gun vs FastAPI/GU |
|---|---|---|---|---|---|---|
| 100 | 9492.61 | 9923.34 | 12407.04 | 10782.64 | .76x | .79x |
| 500 | 14014.12 | 14119.29 | 13723.56 | 13053.71 | 1.02x | 1.02x |
| 1000 | 13936.56 | 15055.28 | 14671.47 | 14693.54 | .94x | 1.02x |
| 并发数 | LiteFS+HttpServer | LiteFS+Gunicorn | FastAPI+Gunicorn+Uvicorn | FastAPI+Uvicorn | LiteFS/HS vs FastAPI/GU | LiteFS/Gun vs FastAPI/GU |
|---|---|---|---|---|---|---|
| 100 | 16392.82 | 11431.98 | 10646.41 | 13841.39 | 1.53x | 1.07x |
| 500 | 15731.83 | 12426.51 | 12965.88 | 11465.47 | 1.21x | .95x |
| 1000 | 15270.39 | 13975.34 | 15405.76 | 14783.76 | .99x | .90x |
| 并发数 | LiteFS+HttpServer | LiteFS+Gunicorn | FastAPI+Gunicorn+Uvicorn | FastAPI+Uvicorn | LiteFS/HS vs FastAPI/GU | LiteFS/Gun vs FastAPI/GU |
|---|---|---|---|---|---|---|
| 100 | 12560.72 | 10140.82 | 9724.92 | 14003.33 | 1.29x | 1.04x |
| 500 | 13172.35 | 15660.33 | 12209.51 | 12162.43 | 1.07x | 1.28x |
| 1000 | 17302.89 | 13882.35 | 12665.96 | 13943.07 | 1.36x | 1.09x |
- 单 Worker 性能: LiteFS 自带 HttpServer 在单 Worker 模式下性能优势最为显著
- 多 Worker 扩展: 随着Worker数增加,所有框架性能均有所提升,LiteFS 扩展性更优
- 高并发稳定性: 在高并发场景下,LiteFS 性能衰减更小,表现更稳定
- 部署模式对比: LiteFS 自带 HttpServer 性能优于 Gunicorn 部署,说明内置服务器经过良好优化
- ASGI vs WSGI: FastAPI 的 ASGI 模式在 I/O 密集型场景下有优势,但在简单请求处理上仍落后于 LiteFS
- Uvicorn 独立部署: FastAPI+Uvicorn 独立部署性能略优于 Gunicorn+Uvicorn 组合
- 操作系统: Linux 6.18.27-amd64-desktop-rolling
- CPU: 12 核
- Python: Python 3.10.9
- 测试日期: 2026-05-18
- 本测试仅对比简单 "Hello world" 响应场景,实际业务场景性能可能有所不同
- 测试结果受硬件、操作系统、网络等因素影响,仅供参考
- 建议在目标生产环境中进行实际业务场景的性能测试
- 原始测试数据保存在
test_results/目录中