Skip to content

Latest commit

 

History

History
86 lines (64 loc) · 4.15 KB

File metadata and controls

86 lines (64 loc) · 4.15 KB

LiteFS vs FastAPI 性能基准测试报告

测试时间: 2026-05-18 23:43:01

测试配置

项目
测试工具 Apache Benchmark (ab)
总请求数 10000
预热请求数 1000
迭代次数 3 (取中位数)
并发级别 100 500 1000
响应内容 纯文本 "Hello world"
Keep-Alive 启用

公平性说明

为确保测试公平性,本次测试遵循以下原则:

  1. 响应格式一致: 所有框架均返回纯文本 Hello world,FastAPI 使用 PlainTextResponse 避免JSON序列化开销
  2. 预热阶段: 每次正式测试前执行 1000 次预热请求,消除冷启动影响
  3. 多次迭代: 每个测试场景执行 3 次迭代,取中位数减少波动
  4. 端口清理: 每次测试前后彻底清理端口占用,确保无残留进程
  5. 健康检查: 启动服务器后通过 HTTP 请求验证服务可用性
  6. 响应验证: 验证服务器返回内容正确性
  7. 失败过滤: 失败请求超过 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 轻量级部署方式

测试结果

1 Worker 测试

并发数 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

4 Worker 测试

并发数 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

8 Worker 测试

并发数 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

性能分析

  1. 单 Worker 性能: LiteFS 自带 HttpServer 在单 Worker 模式下性能优势最为显著
  2. 多 Worker 扩展: 随着Worker数增加,所有框架性能均有所提升,LiteFS 扩展性更优
  3. 高并发稳定性: 在高并发场景下,LiteFS 性能衰减更小,表现更稳定
  4. 部署模式对比: LiteFS 自带 HttpServer 性能优于 Gunicorn 部署,说明内置服务器经过良好优化
  5. ASGI vs WSGI: FastAPI 的 ASGI 模式在 I/O 密集型场景下有优势,但在简单请求处理上仍落后于 LiteFS
  6. Uvicorn 独立部署: FastAPI+Uvicorn 独立部署性能略优于 Gunicorn+Uvicorn 组合

测试环境

  • 操作系统: Linux 6.18.27-amd64-desktop-rolling
  • CPU: 12 核
  • Python: Python 3.10.9
  • 测试日期: 2026-05-18

注意事项

  1. 本测试仅对比简单 "Hello world" 响应场景,实际业务场景性能可能有所不同
  2. 测试结果受硬件、操作系统、网络等因素影响,仅供参考
  3. 建议在目标生产环境中进行实际业务场景的性能测试
  4. 原始测试数据保存在 test_results/ 目录中