忽然想比较一下 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/
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 0Requests/sec: 956.35Transfer/sec: 231.62KBhylas@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 readRequests/sec: 42284.18Transfer/sec: 6.29MBhylas@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 readRequests/sec: 138501.94Transfer/sec: 21.53MB
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 465Requests/sec: 1022.24Transfer/sec: 247.57KBhylas@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 readRequests/sec: 39545.31Transfer/sec: 5.88MBhylas@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 readRequests/sec: 127325.42Transfer/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/s3. 在高并发web服务中 首选 go , nodejs 次之 python 最弱ps: 以上结论未考虑 开发效率,人员薪资成本等因素