- 论坛徽章:
- 11
|
回复 29# tomtesla
楼主的精神值得肯定,不过我觉得进入误区了。
首先。淘宝的实验是nginx维持2M HTTP长连接不断,无需返回数据,需要开发一个nginx module,而不是你理解的每秒接入2M个HTTP短连接的同时还要回传静态文件!前者有一台牛X服务器和调整内核TCP参数就搞定了,后者得用服务器集群才能完成。文章链接http://ehealth-aussie.blogspot.c ... of-nginx-for-2.html和http://www.itzk.com/thread-583354-52-1.shtml
其次。要考虑ab本身的性能问题,因为TCP有流控,ab性能不行,也会拖累nginx回包和关闭链接的延迟,最终就影响整体并发,尝试同时开多个ab发包。
最后。改进方向可以从网络中断处理入手。并附上我PC虚拟机测试结果(fedora 20, 四核2.3GHz, 2GB内存)
内核参数调整:- $ echo 1024 > /proc/sys/net/ipv4/tcp_max_syn_backlog
- $ echo 1024 > /proc/sys/net/core/somaxconn
复制代码 nginx配置:- worker_processes 1;
- worker_rlimit_nofile 81920;
- events {
- multi_accept on;
- worker_connections 8192;
- }
复制代码 启动两个ab- $ (ab -c 100 -n 100000 http://10.211.55.5:8080/ &) && ab -c 100 -n 100000 http://10.211.55.5:8080/
复制代码 统计access.log看总请求数,能稳定在每秒28K:- [root@localhost nginx]# tail -200000 access.log | awk '{ print $4 }' | sort | uniq -c
- 22401 [12/Apr/2014:19:05:57
- 27752 [12/Apr/2014:19:05:58
- 28119 [12/Apr/2014:19:05:59
- 28301 [12/Apr/2014:19:06:00
- 28291 [12/Apr/2014:19:06:01
- 28424 [12/Apr/2014:19:06:02
- 27378 [12/Apr/2014:19:06:03
- 9334 [12/Apr/2014:19:06:04
复制代码 网络中断处理,一个worker,两个ab,不过中断处理占用大量系统CPU而且只压一个core,也试了更多的worker或ab,性能甚至会下降。
当前单worker的性能接近极限了,strace统计下上述过程系统调用延时,虽然attach后进程整体效率下降很大,但系统调用的统计还是比较准确:- [root@localhost nginx]# strace -cT -tt -p 3158 -o strace.sum.$(date '+%H%M%S').log
- [root@localhost nginx]# more strace.sum.193623.log
- % time seconds usecs/call calls errors syscall
- ------ ----------- ----------- --------- --------- ----------------
- 12.67 0.366589 4 100000 writev
- 12.38 0.358369 2 200000 close
- 12.36 0.357587 4 100000 sendfile64
- 11.73 0.339572 2 200223 223 recv
- 10.79 0.312281 3 100000 shutdown
- 7.60 0.220087 2 101000 1000 accept4
- 7.13 0.206290 2 100000 epoll_ctl
- 7.03 0.203432 2 100000 write
- 6.41 0.185492 2 100000 open
- 6.35 0.183873 2 100000 stat64
- 5.21 0.150814 2 100000 fstat64
- 0.21 0.005944 3 2000 epoll_wait
- 0.13 0.003857 2 2001 gettimeofday
- ------ ----------- ----------- --------- --------- ----------------
- 100.00 2.894187 1305224 1223 total
复制代码 理顺上面的表格逻辑,可能还要单独strace一次nginx worker的处理流程。总之一次请求处理仅系统调用占用接近30us,加上少量用户CPU和进程上下文切换,每秒处理极限就在30k左右。vmstat查看,系统CPU时间占绝对多数,系统(网络)中断和上下文切换比较高,在虚拟机下也很难改善了。- bash-4.2 $vmstat 3
- procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
- r b swpd free buff cache si so bi bo in cs us sy id wa
- 4 0 0 1021204 27220 884724 0 0 2 9 117 165 0 2 98 0
- 4 0 0 1009984 27220 892592 0 0 0 0 5661 2000 3 34 63 0
- 3 0 0 999672 27228 900604 0 0 0 4 5644 1975 3 34 63 0
- 3 0 0 989224 27228 908496 0 0 0 0 5608 1826 3 34 63 0
- 3 0 0 979460 27236 916464 0 0 0 13200 5598 1812 3 34 62 0
- 3 0 0 969080 27248 924144 0 0 0 4433 5728 2105 3 34 62 0
- 3 0 0 958652 27248 932280 0 0 0 0 5606 1905 3 34 63 0
- 3 0 0 946404 27256 940240 0 0 0 9 5734 2074 4 33 63 0
- 3 0 0 936268 27256 948088 0 0 0 0 5607 1790 4 34 63 0
复制代码 |
评分
-
查看全部评分
|