关注互联网应用及运维技术的个人博客

golang协程和python协程对比

golang协程和python协程对比,主要是测试在生产中的并发、效率等。

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 http://x.x.x.x/ua
Running 30s test @ http://x.x.x.x/ua
  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 http://x.x.x.x/ua  
Running 30s test @ http://3.0.3.0/ua
  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 http://x.x.x.x/ca
Running 30s test @ http://x.x.x.x/ca
  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 http://x.x.x.x/ca  
Running 30s test @ http://x.x.x.x/ca
  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 http://x.x.x.x/ca  
Running 30s test @ http://x.x.x.x/ca
  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都用来处理上亿的并发.

赞(0)
未经允许不得转载:飞天狒狒 » golang协程和python协程对比

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址