LiteFS vs FastAPI 性能测试报告
测试配置
测试工具: Apache Benchmark (ab)
总请求数: 10,000
测试内容: 返回 "Hello world" 文本
测试结果
1 核测试
并发数 |
LiteFS + 自带 HttpServer (req/sec) |
测试时间 (秒) |
LiteFS + Gunicorn (req/sec) |
测试时间 (秒) |
FastAPI + Gunicorn + Uvicorn (req/sec) |
测试时间 (秒) |
LiteFS 比 FastAPI 快 |
LiteFS+Gunicorn 比 FastAPI+Gunicorn 快 |
|---|---|---|---|---|---|---|---|---|
100 |
9541.89 |
tests: |
5877.79 |
tests: |
4611.97 |
tests: |
2.06 倍 |
1.27 倍 |
500 |
9257.47 |
tests: |
5577.02 |
tests: |
4464.47 |
tests: |
2.07 倍 |
1.24 倍 |
1000 |
9143.28 |
tests: |
5703.18 |
tests: |
4427.27 |
tests: |
2.06 倍 |
1.28 倍 |
4 核测试
并发数 |
LiteFS + 自带 HttpServer (req/sec) |
测试时间 (秒) |
LiteFS + Gunicorn (req/sec) |
测试时间 (秒) |
FastAPI + Gunicorn + Uvicorn (req/sec) |
测试时间 (秒) |
LiteFS 比 FastAPI 快 |
LiteFS+Gunicorn 比 FastAPI+Gunicorn 快 |
|---|---|---|---|---|---|---|---|---|
100 |
15995.65 |
tests: |
15059.95 |
tests: |
11385.10 |
tests: |
1.40 倍 |
1.32 倍 |
500 |
19211.19 |
tests: |
13938.91 |
tests: |
11177.34 |
tests: |
1.71 倍 |
1.24 倍 |
1000 |
20753.73 |
tests: |
14112.91 |
tests: |
10782.14 |
tests: |
1.92 倍 |
1.30 倍 |
8 核测试
并发数 |
LiteFS + 自带 HttpServer (req/sec) |
测试时间 (秒) |
LiteFS + Gunicorn (req/sec) |
测试时间 (秒) |
FastAPI + Gunicorn + Uvicorn (req/sec) |
测试时间 (秒) |
LiteFS 比 FastAPI 快 |
LiteFS+Gunicorn 比 FastAPI+Gunicorn 快 |
|---|---|---|---|---|---|---|---|---|
100 |
21259.09 |
tests: |
17611.09 |
tests: |
14502.49 |
tests: |
1.46 倍 |
1.21 倍 |
500 |
20483.41 |
tests: |
16618.91 |
tests: |
14166.97 |
tests: |
1.44 倍 |
1.17 倍 |
1000 |
20976.54 |
tests: |
16358.95 |
tests: |
14222.04 |
tests: |
1.47 倍 |
1.15 倍 |
性能分析
一致性: 在所有并发级别下,LiteFS 都显著优于 FastAPI
稳定性: LiteFS 在不同并发级别下性能相对稳定
高并发优势: 随着并发数的增加,LiteFS 的性能优势更加明显
单进程性能: 即使在单进程模式下,LiteFS 仍然比 FastAPI 快约 2-3.5 倍
多进程优势: 多进程模式下,LiteFS 的性能进一步提升,特别是在高并发场景
核心数扩展: 随着核心数的增加,LiteFS 的性能也相应提升,8 核配置下性能最佳
Gunicorn+Uvicorn 对比: 即使使用 Gunicorn+Uvicorn 部署,FastAPI 的性能仍然落后于 LiteFS
结论
LiteFS 在处理 HTTP 请求时具有显著的性能优势,无论是单进程还是多进程模式,无论是 4 核还是 8 核配置。 特别是在高并发情况下,LiteFS 的性能优势更加明显,表明它是一个高性能的 Web 框架,特别适合处理高并发的 HTTP 请求。