对比 FastAPI Robyn Gin json 序列化返回性能 大概的性能对比如下
wrk -t10 -c 10 -d 20s http://127.0.0.1:xxxx/json
FastAPI (async)
Running 20s test @ http://127.0.0.1:8080/json
10 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 835.68us 798.76us 29.00ms 94.21%
Req/Sec 1.32k 513.33 2.51k 49.45%
262867 requests in 20.10s, 38.10MB read
Requests/sec: 13078.90
Transfer/sec: 1.90MB
Robyn (sync)
Running 20s test @ http://127.0.0.1:8111/json
10 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 358.51us 690.23us 24.51ms 96.09%
Req/Sec 3.91k 1.70k 9.80k 76.79%
781679 requests in 20.10s, 75.29MB read
Requests/sec: 38889.89
Transfer/sec: 3.75MB
Robyn (async)
Running 20s test @ http://127.0.0.1:8111/json
10 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 517.35us 795.62us 32.63ms 95.72%
Req/Sec 2.42k 0.87k 6.79k 71.78%
481576 requests in 20.10s, 46.39MB read
Requests/sec: 23959.48
Transfer/sec: 2.31MB
Gin
Running 20s test @ http://127.0.0.1:8888/json
10 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 293.92us 688.32us 27.60ms 94.13%
Req/Sec 6.87k 2.66k 13.32k 58.32%
1368505 requests in 20.10s, 195.77MB read
Requests/sec: 68090.01
Transfer/sec: 9.74MB
robyn 基准参考 https://github.com/sansyrox/robyn-comparison-benchmarks
Rust+Python Python 的下一波春天?
1
wuwukai007 2023-09-07 11:57:26 +08:00
官方文档就是个简单的 demo ,很怀疑持久性,对比之前的 litestar 文档就很齐全
|
2
rrfeng 2023-09-07 12:05:40 +08:00 via Android
不是,我看着数不是被 gin 秒杀了?
|
4
xgdgsc 2023-09-07 12:36:22 +08:00 via Android
https://discourse.julialang.org/t/julia-can-be-better-at-doing-web-a-benchmark/103300 不如优化下 julia 创造 julia 加 rust 的春天
|
5
TArysiyehua 2023-09-07 13:20:55 +08:00
这么说吧,我用 python 的那一刻就没考虑性能的问题
|
6
so1n 2023-09-07 13:54:05 +08:00
没加数据库调用的测试都是耍流氓...而这个例子的接口连 IO 处理都没...
|
7
vicalloy 2023-09-07 13:57:01 +08:00
如果是 Json 序列化性能,可以做 FastAPI 里使用 orjson 进行加速。
https://fastapi.tiangolo.com/advanced/custom-response/#orjsonresponse 如果不想改动现有代码,可以简单的做个 monkey patch 。 import orjson json.dumps = lambda obj, *args, **kwargs: orjson.dumps( obj, option=orjson.OPT_NON_STR_KEYS ).decode("utf-8") json.loads = lambda obj, *args, **kwargs: orjson.loads(obj) |
9
Oxonomy 2023-09-07 14:32:01 +08:00 via iPhone
序列化带来的提升能说明什么呢🤔
|
10
fakeshadow 2023-09-07 14:37:07 +08:00
哥们儿你那个附言我笑了,压测 404
|
11
Baloneo OP @fakeshadow 确实是错了 估计是 Robyn 框架并发的 bug
|
12
CodeCodeStudy 2023-09-07 14:43:28 +08:00
类似 Swoole 用 C++做扩展来给 PHP 做性能提升吗?
|
13
Baloneo OP |
15
fakeshadow 2023-09-07 15:06:33 +08:00
@Baloneo 如果你浏览 tfb 可以参考下 robyn 的分数,横向比较也并没有很快的感觉(我对 py 库了解不多)。https://www.techempower.com/benchmarks/#section=test&runid=074e8a70-d6fb-4f10-82f3-43e57c0965b5&test=plaintext&l=hra0hr-35r
|
16
Baloneo OP @fakeshadow 比 fastapi 还是快很多
|
17
huihuiHK 2023-09-07 17:37:38 +08:00
@app.get("/json")。 Running 20s test @ http://127.0.0.1:8111/query
|
18
lanlanye 2023-09-07 19:30:41 +08:00
一般来说,瓶颈都不会在这里……
|
19
SenLief 2023-09-07 21:14:10 +08:00
我都有 python 了,那性能就不是我考虑的东西。
|
20
shinession 2023-09-08 07:56:28 +08:00
json 序列化不是用 msgspec 吗? 试了比 orjson 快很多
|