Web性能压测

http_load压测工具

  这个工具不适合跑并发量太大的测试,个人机子上最大并发数为4095,由于该程序主要使用的是select进行性能压测,select可载入的文件描述符是有上限的,具体大小为 sizeof(fd_set)*8。还有一个缺点是只支持Get请求
  优势是单进程跑压测,不占用系统资源html

http_load使用方法
[yutian@localhost wwwbenchmark]$ ./http_load -help
usage:  ./http_load [-checksum] [-throttle] [-proxy host:port] [-verbose] [-timeout secs] 
[-sip sip_file]  -parallel N | -rate N [-jitter] -fetches N | -seconds N url_file
One start specifier, either -parallel or -rate, is required.
One end specifier, either -fetches or -seconds, is required.
  • 参数说明
    • p : 最高的并发数
    • r : 指的是每秒的访问频率
    • f : 访问次数
    • s: 访问时间

从上面help手册能够看出来, p 与 r 选项只能选一个,f与s选项只能选一个。url文件里面是一个个网址必须以http或者https开头,好比http://127.0.0.1:80/web

结果说明
1647471 fetches, 50 max parallel, 1.00825e+09 bytes, in 60 seconds
共请求了1647471次,最高并发50,请求了1.00825 * 10^9 次方字节 大概1个G,在60s中
612 mean bytes/connection
平均每一个链接612字节
27457.8 fetches/sec, 1.68042e+07 bytes/sec
每秒 发出 27457.8 请求 , 1.6 * 10^7 大概16MB 
msecs/connect: 0.106233 mean, 18.943 max, 0.008 min
平均每一个链接0.1 毫秒 最大18 最小0.008
msecs/first-response: 0.854746 mean, 49.819 max, 0.037 min
每一个链接的第一次响应时间平均 0.8毫秒 ,最大49 最小 0.037
HTTP response codes:
code 200 -- 1647471

Apache bench (ab)

  由于ab 的安装比较麻烦,因此本文也介绍下ab的安装方法apache

安装apr

  若是https链接失效,咱们能够去到https://mirrors.cnnic.cn/apache/apr/ 去看最新的版本进行下载便可服务器

cd /usr/local/src/
wget https://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz 
tar zxvf apr-1.6.3.tar.gz 
cd /usr/local/src/apr-1.6.3
./configure --prefix=/usr/local/apr
make && make install
安装Apr-util
cd /usr/local/src/
wget https://mirrors.cnnic.cn/apache/apr/apr-util-1.6.3.tar.gz 
tar zxvf apr-util-1.6.3.tar.gz 
cd /usr/local/src/apr-util-1.6.3
./configure --prefix=/usr/local/apr
make && make install
编译安装apache
cd /usr/local/src/
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.16.tar.gz 
tar zxvf httpd-2.4.16.tar.gz 
cd /usr/local/src/httpd-2.4.16
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr/ --with-apr-util=
/usr/local/apr-util/
make && make install

  若是遇到/usr/local/lib/libz.a: could not read symbols: Bad value错误。须要去从新安装zlib,使用 CFLAGS=”-O3 -fPIC” ./configure –prefix=/usr/local/lib/zlib/ 配置后从新安装便可cookie

使用Apachen bench
参数
格式:ab [options] [http://]hostname[:port]/path
参数说明:
-n requests Number of requests to perform
//在测试会话中所执行的请求个数(本次测试总共要访问页面的次数)。默认时,仅执行一个请求。
-c concurrency Number of multiple requests to make
//一次产生的请求个数(并发数)。默认是一次一个。
-t timelimit Seconds to max. wait for responses
//测试所进行的最大秒数。其内部隐含值是-n 50000。它可使对服务器的测试限制在一个固定的总时间之内。默认时,没有时间限制。
-p postfile File containing data to POST
//包含了须要POST的数据的文件,文件格式如“p1=1&p2=2”.使用方法是 -p 111.txt 。 (配合-T)
-T content-type Content-type header for POSTing
//POST数据所使用的Content-type头信息,如 -T “application/x-www-form-urlencoded” 。 (配合-p)
-v verbosity How much troubleshooting info to print
//设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值能够显示响应代码(404, 200等), 2或更大值能够显示警告和其余信息。 -V 显示版本号并退出。
-w Print out results in HTML tables
//以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
-i Use HEAD instead of GET
// 执行HEAD请求,而不是GET。
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. -C “c1=1234,c2=2,c3=3” (repeatable)
//-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数能够重复,用逗号分割。
提示:能够借助session实现原理传递 JSESSIONID参数, 实现保持会话的功能,如
-C ” c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
//-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。不管服务器是否须要(即, 是否发送了401认证需求代码),此字符串都会被发送。
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
//-attributes 设置属性的字符串. 缺陷程序中有各类静态声明的固定长度的缓冲区。另外,对命令行参数、服务器的响应头和其余外部输入的解析也很简单,这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些’预想’的响应格式。 strstr(3)的频繁使用可能会带来性能问题,即你多是在测试ab而不是服务器的性能。
一般

一般上咱们只须要使用俩个选项,n与c,n 表明链接数 c 表明并发数 后面是域名。session

./ab -n 1000000 -c 100  http://127.0.0.1:80/
从上到下的含义

这里写图片描述

  • 请求路径
  • 请求文件大小
  • 测试消耗的时间
  • 完成的请求数
  • 失败的请求数
  • 总共接受了多少字节
  • 多少是html字节
  • 平均每秒多少请求
  • 平均下来每一个请求的响应速度
  • 平均下来每一个请求的执行速度
  • 平均接收到的每秒的流量
  • 接下来的表是每一个链接的发生、处理、等待接受的时间
  • 平均请求时间的百分比
webbench

  这个测压工具是真真的会去fork你须要的并发数而后去请求http服务器
 &emp;webbench -c 并发数 -t 运行测试时间 域名并发