web服务器并发压力测试
1、测试环境
系统:Centos6.4_x86_64
工具:webbench_1.5
2、工具安装
wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz
tar zxvf webbench-1.5.tar.gz
cd webbench-1.5
make && make install
3、压力测试操作
进行压力测试,并发200时。
# webbench-c 200-t 60 http://down.chinaz.com/index.php
参数解释:-c为并发数,-t为时间(秒)
Webbench - Simple Web Benchmark 1.5Copyright(c) Radim Kolar 1997-2004, GPL Open SourceSoftware. Benchmarking:GEThttp://down.chinaz.com/index.php200 clients, running 60 sec. Speed=1454 pages/min,2153340 bytes/sec. Requests:1454 susceed,0 failed.
当并发200时,网站访问速度正常
并发800时
#webbench-c 800-t 60 http://down.chinaz.com/index.php Webbench - Simple Web Benchmark 1.5Copyright(c) Radim Kolar 1997-2004, GPL Open SourceSoftware. Benchmarking:GEThttp://down.chinaz.com/index.php800 clients, running 60 sec. Speed=1194 pages/min,2057881 bytes/sec. Requests:1185 susceed,9 failed.
当并发连接为800时,网站访问速度稍慢
并发1600时
#webbench-c 1600-t 60 http://down.chinaz.com/index.php Webbench - Simple Web Benchmark 1.5Copyright(c) Radim Kolar 1997-2004, GPL Open SourceSoftware. Benchmarking:GEThttp://down.chinaz.com/index.php1600 clients, running 60 sec. Speed=1256 pages/min,1983506 bytes/sec. Requests:1183 susceed,73 failed.
当并发连接为1600时,网站访问速度便非常慢了
并发2000时
#webbench-c 2000-t 60 http://down.chinaz.com/index.php Webbench - Simple Web Benchmark 1.5Copyright(c) Radim Kolar 1997-2004, GPL Open SourceSoftware. Benchmarking:GEThttp://down.chinaz.com/index.php2000 clients, running 60 sec. Speed=2154 pages/min,1968292 bytes/sec. Requests:2076 susceed,78 failed.
当并发2000时,网站便出现"502 Bad Gateway",由此可见web服务器已无法再处理用户访问请求
总结:
1、压力测试工作应该放到产品上线之前,而不是上线以后
2、测试时尽量跨公网进行,而不是内网
3、测试时并发应当由小逐渐加大,比如并发100时观察一下网站负载是多少、打开是否流程,并发200时又是多少、网站打开缓慢时并发是多少、网站打不开时并发又是多少
4、 应尽量进行单元测试,如B2C网站可以着重测试购物车、推广页面等,因为这些页面占整个网站访问量比重较大