golang协程和 python 协程对比,主要是测试在生产中的并发、效率等。
因为机器配置较弱(没钱开机器:smile:),均在 load15 负载约降为 0 的时候开启下次测试,避免机器负载影响。 同时程序无复杂逻辑处理,仅做返回。
go协程和python协程测试环境
压测环境
AWS 1核1G CPU为 E5-2676 v3 @ 2.40GHz,压测工具:wrk
目标环境
AWS 1核1G CPU为 E5-2676 v3 @ 2.40GHz,机器无弹性扩容性能,固死频率
前段均用 nginx 做反向代理
- golang环境:nginx->docker->golang->gin
- python环境:nginx->docker->python3.7->flask+gevent单进程模式
go协程测试结果
root@aws1:~# wrk -t6 -c200 -d30s
Running 30s test @
6 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 94.19ms 128.56ms 1. 12s 96.09%
Req/Sec 448.99 81.79 680.00 70.00%
80543 requests in 30.04s, 13.67MB read
Requests/sec: 2681.19
Transfer /sec: 465.95KB
root@aws1:~# wrk -t3 -c100 -d30s
Running 30s test @
3 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 34.64ms 5.17ms 65.64ms 94.30%
Req/Sec 0.96k 69.42 1.05k 87.78%
85742 requests in 30.03s, 14.55MB read
Requests/sec: 2854.81
Transfer/sec: 496.12KB
golang在机器负载高的时候响应很慢,约为100ms左右,机器负载低的时候响应很快34ms。平均水平 QPS约为2800(1核1G内存,2.4GHZ 处理器 )
python协程测试结果
root@aws1:~# wrk -t6 -c200 -d30s
Running 30s test @
6 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 186.31ms 38.63ms 1.21s 98.70%
Req/Sec 182.58 93.09 333.00 56.87%
32052 requests in 30.05s, 6.85MB read
Requests/sec: 1066.56
Transfer/sec: 233.28KB
root@aws1:~# wrk -t3 -c100 -d30s
Running 30s test @
3 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 94.45ms 7.26ms 127.97ms 92.59%
Req/Sec 350.32 42.29 450.00 77.56%
31425 requests in 30.04s, 6.71MB read
Requests/sec: 1046.22
Transfer/sec: 228.81KB
root@aws1:~# wrk -t3 -c50 -d30s
Running 30s test @
3 threads and 50 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 45.89ms 4.44ms 78.93ms 95.25%
Req/Sec 349.89 41.41 454.00 80.67%
31381 requests in 30.03s, 6.70MB read
Requests/sec: 1044.85
Transfer/sec: 228.51KB
可以看出python在并发和机器负载低情况下跟golang响应方面差别不大,平均水平 QPS约为1000(1核1G内存,2.4GHZ处理器)。 不过并发能力确实弱很多,而且随着负载增高,越来越慢(还是动态语言解释的原因),不过话说instagram都用来处理上亿的并发,这点量算什么:smile:,Refer: 《Flask gevent 多进程WSGI,每秒1w5 QPS》 。