结论:Go HTTP standalone >(优于) Nginx proxy to Go HTTP >(优于) Nginx fastcgi to Go TCP FastCGI
原文链接:http://www.oschina.net/translate/benchmarking-nginx-with-go?from=20131222
英文链接:https://gist.github.com/hgfischer/7965620
目前有很多提供Go语言HTTP应用服务的方法,但其中最好的选择取决于每个应用的实际情况。目前,Nginx看起来是每个新项目的标准Web服务器,即使在有其他许多不错Web服务器的情况下。然而,在Nginx上提供Go应用服务的开销是多少呢?我们需要一些nginx的特性参数(vhosts,负载均衡,缓存,等等)或者直接使用Go提供服务?如果你需要nginx,最快的连接机制是什么?这就是在这我试图回答的问题。该基准测试的目的不是要验证Go比nginx的快或慢。那将会很愚蠢。
下面是我们要比较不同的设置:
- Go HTTP standalone (as the control group)
- Nginx proxy to Go HTTP
- Nginx fastcgi to Go TCP FastCGI
- Nginx fastcgi to Go Unix Socket FastCGI
硬件
因为我们将在相同的硬件下比较所有设置,硬件选择的是廉价的一个。这不应该是一个大问题。
- Samsung 笔记本 NP550P5C-AD1BR
- Intel Core i7 3630QM @2.4GHz (quad core, 8 threads)
- CPU caches: (L1: 256KiB, L2: 1MiB, L3: 6MiB)
- RAM 8GiB DDR3 1600MHz
软件
- Ubuntu 13.10 amd64 Saucy Salamander (updated)
- Nginx 1.4.4 (1.4.4-1~saucy0 amd64)
- Go 1.2 (linux/amd64)
- wrk 3.0.4
设置
内核
只需很小的一点调整,将内核的limits调高。如果你对这一变量有更好的想法,请在写在下面评论处:
03 |
net.core.netdev_max_backlog
4096 |
04 |
net.core.rmem_max
16777216 |
05 |
net.core.somaxconn
65535 |
06 |
net.core.wmem_max
16777216 |
08 |
net.ipv4.ip_local_port_range
1025 65535 |
09 |
net.ipv4.tcp_fin_timeout
30 |
10 |
net.ipv4.tcp_keepalive_time
30 |
11 |
net.ipv4.tcp_max_syn_backlog
20480 |
12 |
net.ipv4.tcp_max_tw_buckets
400000 |
13 |
net.ipv4.tcp_no_metrics_save
1 |
14 |
net.ipv4.tcp_syn_retries
2 |
15 |
net.ipv4.tcp_synack_retries
2 |
16 |
net.ipv4.tcp_tw_recycle
1 |
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。