使用 Go 对 Nginx 进行性能测试(3)

# wrk -t100 -c5000 -d30s
Running 30s test @
  100 threads and 5000 connections
  Thread Stats  Avg      Stdev    Max  +/- Stdev
    Latency  425.64ms  80.53ms 925.03ms  76.88%
    Req/Sec  117.03    22.13  255.00    81.30%
  350162 requests in 30.00s, 58.77MB read
  Socket errors: connect 0, read 0, write 0, timeout 210
Requests/sec:  11670.72
Transfer/sec:      1.96MB

GOMAXPROCS = 8 Go standalone

# wrk -t100 -c5000 -d30s :8080/
Running 30s test @ :8080/
  100 threads and 5000 connections
  Thread Stats  Avg      Stdev    Max  +/- Stdev
    Latency    39.25ms    8.49ms  86.45ms  81.39%
    Req/Sec    1.29k  129.27    1.79k    69.23%
  3837995 requests in 29.89s, 644.19MB read
Requests/sec: 128402.88
Transfer/sec:    21.55MB

Nginx + Go through HTTP

# wrk -t100 -c5000 -d30s
Running 30s test @
  100 threads and 5000 connections
  Thread Stats  Avg      Stdev    Max  +/- Stdev
    Latency  336.77ms  297.88ms 632.52ms  60.16%
    Req/Sec    2.36k    2.99k  19.11k    84.83%
  2232068 requests in 29.98s, 374.64MB read
Requests/sec:  74442.91
Transfer/sec:    12.49MB

Nginx + Go through FastCGI TCP

# wrk -t100 -c5000 -d30s
Running 30s test @
  100 threads and 5000 connections
  Thread Stats  Avg      Stdev    Max  +/- Stdev
    Latency  217.69ms  121.22ms  1.80s    75.14%
    Req/Sec  263.09    102.78  629.00    62.54%
  721027 requests in 30.01s, 121.02MB read
  Socket errors: connect 0, read 0, write 176, timeout 1343
Requests/sec:  24026.50
Transfer/sec:      4.03MB

Nginx + Go through FastCGI Unix Socket

# wrk -t100 -c5000 -d30s
Running 30s test @
  100 threads and 5000 connections
  Thread Stats  Avg      Stdev    Max  +/- Stdev
    Latency  694.32ms  332.27ms  1.79s    62.13%
    Req/Sec  646.86    669.65    6.11k    87.80%
  909836 requests in 30.00s, 152.71MB read
Requests/sec:  30324.77
Transfer/sec:      5.09MB

结论

第一组基准测试时一些Nginx的设置还没有很好的优化(启用gzip,Go的后端没有使用keep-alive连接)。当改为wrk以及按建议优化Nginx后结果有较大差异。

当GOMAXPROCS=1时,Nginx的开销不是那么大,但当OMAXPROCS=8时差异就很大了。以后可能会再试一下其他设置。如果你需要使用Nginx像虚拟主机,负载均衡,缓存等特性,使用HTTP proxy,别使用FastCGI。有些人说Go的FastCGI还没有被很好优化,这也许就是测试结果中巨大差异的原因。

推荐阅读

Nginx实现反向代理和负载均衡的配置及优化

Nginx做负载均衡报:nginx: [emerg] could not build the types_hash

Nginx 负载均衡模块 ngx_http_upstream_module 详述

Nginx+Firebug 让浏览器告诉你负载均衡将请求分到了哪台服务器

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e388619cb5f9e83d19dd66ab302f7c3f.html