忽然想比较一下 python nodejs go 的web 响应,就简单的写了个性能对比测试。
测试目标:
1 . i5 4核 32G 同一机器 linux
2. 用python(flask线程模式) nodejs go 分别写了简单的 echo 服务
测试工具:
wrk
服务器清单:
python flask http://192.168.0.208:5050/
nodejs express http://192.168.0.208:5056/
go server http://192.168.0.208:5057/
测试脚本:
wrk -c100 -t10 -d30s http://192.168.0.208:5050/
wrk -c100 -t10 -d30s http://192.168.0.208:5056/
wrk -c100 -t10 -d30s http://192.168.0.208:5057/
wrk -c1000 -t10 -d30s http://192.168.0.208:5050/
wrk -c1000 -t10 -d30s http://192.168.0.208:5056/
wrk -c1000 -t10 -d30s http://192.168.0.208:5057/
测试结果:
100 终端10线程
Running 30s test @ http://192.168.0.208:5050/
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 85.24ms 62.29ms 447.28ms 90.54%
Req/Sec 137.84 54.19 202.00 63.72%
28723 requests in 30.03s, 6.79MB read
Socket errors: connect 100, read 0, write 0, timeout 0
Requests/sec: 956.35
Transfer/sec: 231.62KB
hylas@keras208:~$ wrk -c100 -t10 -d30s http://192.168.0.208:5056/
Running 30s test @ http://192.168.0.208:5056/
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.37ms 349.63us 17.71ms 98.57%
Req/Sec 4.25k 253.62 5.32k 97.80%
1269157 requests in 30.01s, 188.82MB read
Requests/sec: 42284.18
Transfer/sec: 6.29MB
hylas@keras208:~$ wrk -c100 -t10 -d30s http://192.168.0.208:5057/
Running 30s test @ http://192.168.0.208:5057/
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.20ms 5.19ms 105.37ms 91.89%
Req/Sec 13.93k 3.45k 46.58k 72.80%
4165034 requests in 30.07s, 647.45MB read
Requests/sec: 138501.94
Transfer/sec: 21.53MB
1000终端 10 线程
hylas@keras208:~$ wrk -c1000 -t10 -d30s http://192.168.0.208:5050/
Running 30s test @ http://192.168.0.208:5050/
10 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 124.59ms 129.37ms 1.97s 91.52%
Req/Sec 129.50 92.32 610.00 66.97%
30763 requests in 30.09s, 7.28MB read
Socket errors: connect 938, read 52, write 0, timeout 465
Requests/sec: 1022.24
Transfer/sec: 247.57KB
hylas@keras208:~$ wrk -c1000 -t10 -d30s http://192.168.0.208:5056/
Running 30s test @ http://192.168.0.208:5056/
10 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 25.00ms 9.27ms 463.53ms 96.69%
Req/Sec 4.01k 480.69 12.12k 94.63%
1189964 requests in 30.09s, 177.03MB read
Requests/sec: 39545.31
Transfer/sec: 5.88MB
hylas@keras208:~$ wrk -c1000 -t10 -d30s http://192.168.0.208:5057/
Running 30s test @ http://192.168.0.208:5057/
10 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 17.17ms 33.92ms 475.96ms 91.23%
Req/Sec 12.94k 6.57k 79.62k 70.73%
3831283 requests in 30.09s, 595.57MB read
Requests/sec: 127325.42
Transfer/sec: 19.79MB
结论:
1. 100 终端时:python 延时最大,与另外两个相差一个数量级 , nodejs go 差不多。 Req/Sec 比例分别是 0.13 : 4:13 , go能大大 13k/s
2. 1000 终端时: nodejs 和 go 的延时增加,但还是明显优与 python , Req/Sec 保持稳定 python 最低,nodejs :go 3:12 go的峰值 79k/s
3. 在高并发web服务中 首选 go , nodejs 次之 python 最弱
ps: 以上结论未考虑 开发效率,人员薪资成本等因素
————————————————————————
让科技和智能使人更便捷 --- 从我做起
————————————————————————