摘要: ab命令会建立不少的并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,所以,既能够用来测试Apache的负载压力,也能够测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。 ab命令对发出负载的计算机要求很低,既不会占用很高CPU,也不会占用不少内存,但却会给目标服务器形成巨大的负载,其原理相似CC攻击。本身测试使用也须注意,不然一次上太多的负载,可能形成目标服务器因资源耗完,严重时甚至致使死机。html
Apache服务自带了应该用于压力测试的工具ab(ApacheBench),对应作一些简单的压力测试,它彻底可以胜任,本文主要介绍,在centos中不安装Apache的状况下,安装abios
1,ab运行的时候须要依赖包,咱们先安装依赖包,直接yum安装就能够了nginx
yum install apr-utilapache
2, 下载apache的rpm包,分离abcentos
[root@Tomcat ~]# mkdir ab [root@Tomcat ~]# cd ab [root@Tomcat ab]# yum -y install yum-utils [root@Tomcat ab]# yumdownloader httpd #yumdownloader 须要安装yum-utils才能使用,默认是没有的安装的 [root@Tomcat ab]# rpm2cpio httpd-2.2.3-91.el5.centos.i386.rpm |cpio -idmv [root@Tomcat ab]# \cp -pa usr/bin/ab /usr/bin/ #复制到系统PATH就可使用了
3,ab简单用法tomcat
参数不少,通常咱们用 -c 和 -n 参数就能够了。服务器
#ab -c 1000 -n 4000 http://www.yousite.com/index.html #具体到某页面网络
-n后面的4000表明总共发出4000个请求;-c后面的1000表示采用1000个并发(模拟1000我的同时访问),后面的网址表示测试的目标URL。并发
[root@Tomcat ab]# ab -c 1000 -n 4000 http://192.168.0.222/docs/manager-howto.html This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.0.222 (be patient) Completed 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Finished 4000 requests Server Software: nginx/1.4.3 Server Hostname: 192.168.0.222 Server Port: 80 Document Path: /docs/manager-howto.html Document Length: 73924 bytes Concurrency Level: 1000 Time taken for tests: 0.875928 seconds Complete requests: 4000 Failed requests: 0 Write errors: 0 Total transferred: 296732000 bytes HTML transferred: 295696000 bytes Requests per second: 4566.59 [#/sec] (mean) #最重要的指标之一,至关于LR中的每秒事务数,后面括号中的mean表示这是一个平均值,越大抗压越强 Time per request: 218.982 [ms] (mean) #最重要的指标之二,至关于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值 Time per request: 0.219 [ms] (mean, across all concurrent requests) Transfer rate: 330822.86 [Kbytes/sec] received #平均每秒网络上的流量,吞吐量,越大抗压越强 Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 4.5 0 29 Processing: 1 17 14.5 17 653 Waiting: 0 17 14.5 17 653 Total: 15 18 15.2 17 674 Percentage of the requests served within a certain time (ms) 50% 17 66% 18 75% 18 80% 18 90% 20 95% 22 98% 37 99% 40 100% 674 (longest request)
主要介绍里面的几个指标,我基本也就看这几个指标,简单测试足够了,若是要全面的监控nginx,须要用到专业的监控程序,如nagios工具
参考:https://my.oschina.net/harlanblog/blog/395420
yum install apr-util
yum install yum-utils
cd /opt
mkdir /opt/ab
yum install yum-utils.noarch
yumdownloader httpd-tools*
rpm2cpio httpd-*.rpm | cpio -idmv
cp /opt/ab/usr/bin/ab /usr/bin/
参考:
http://blog.csdn.net/fyqaccpt96/article/details/43272001
http://www.cnblogs.com/terryguan/p/6681055.html