【WEB】Web性能压力测试工具

webbench

原理

webbench首先fork出多个子进程,每个子进程都循环做web访问测试。子进程把访问的结果通过pipe告诉父进程,父进程做最终的统计结果(转至百度百科)

安装

[root@VM_114_93_centos local]# wget  http://home.tiscali.cz/cz210552/distfiles/webbench-1.5.tar.gz

[root@VM_114_93_centos local]# tar -zxvf webbench-1.5.tar.gz webbench-1.5        
webbench-1.5/
webbench-1.5/webbench.1
webbench-1.5/socket.c
webbench-1.5/webbench.c
webbench-1.5/Makefile
webbench-1.5/debian/
webbench-1.5/debian/rules
webbench-1.5/debian/dirs
webbench-1.5/debian/copyright
webbench-1.5/debian/control
webbench-1.5/debian/changelog
webbench-1.5/COPYRIGHT
webbench-1.5/ChangeLog

[root@VM_114_93_centos local]# cd webbench-1.5/

[root@VM_114_93_centos webbench-1.5]# make && make install

安装过程中报错总结

  • /bin/sh: ctags: command not found,解决方法:yum install ctags
  • install: cannot create regular file ‘/usr/local/man/man1’: No such file or directory 解决方法:mkdir /usr/local/man

然后在输出 make && make install

使用

安装完成后输出webbench,出现help界面

[root@VM_114_93_centos webbench-1.5]# webbench                                                                   
webbench [option]... URL
  -f|--force               Don't wait for reply from server.
  -r|--reload              Send reload request - Pragma: no-cache.
  -t|--time           Run benchmark for  seconds. Default 30.
  -p|--proxy <server:port> Use proxy server for request.
  -c|--clients          Run  HTTP clients at once. Default one.
  -9|--http09              Use HTTP/0.9 style requests.
  -1|--http10              Use HTTP/1.0 protocol.
  -2|--http11              Use HTTP/1.1 protocol.
  --get                    Use GET request method.
  --head                   Use HEAD request method.
  --options                Use OPTIONS request method.
  --trace                  Use TRACE request method.
  -?|-h|--help             This information.
  -V|--version             Display program version.

使用

[root@VM_114_93_centos swoole]# webbench -c 1000 -t 10 http://www.baidu.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://www.baidu.com/
1000 clients, running 10 sec.

Speed=5766 pages/min, 11568162 bytes/sec.
Requests: 958 susceed, 3 failed.

速度:每秒钟响应请求数:5766 pages/min,每秒钟传输数据量11568162 bytes/sec.
返回数:958 次返回成功,3次返回失败

ab

ab(apache bench)是apache下的一个工具,主要用于对web站点做压力测试,

安装

可以值安装Apache的tools

yum -y install httpd-tools

使用

-n在测试会话中所执行的请求个数。默认时,仅执行一个请求。
-c一次产生的请求个数。默认是一次一个。

[dev@web ~]$ ab -c 20 -n 50000 http://192.168.1.210/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.210 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests
Server Software: nginx/1.6.2
Server Hostname: 192.168.1.210
Server Port: 80
Document Path: /
Document Length: 41005 bytes # 请求的页面大小
Concurrency Level: 20 # 并发量
Time taken for tests: 1180.733 seconds # 测试总共耗时
Complete requests: 50000 # 完成的请求
Failed requests: 0 # 失败的请求
Write errors: 0 # 错误
Total transferred: 2067550000 bytes # 总共传输数据量
HTML transferred: 2050250000 bytes
Requests per second: 42.35 [#/sec] (mean) # 每秒钟的请求量。(仅仅是测试页面的响应速度)
Time per request: 472.293 [ms] (mean) # 等于 Time taken for tests/(complete requests/concurrency level) 即平均请求等待时间(用户等待的时间)
Time per request: 23.615 [ms] (mean, across all concurrent requests) # 等于 Time taken for tests/Complete requests 即服务器平均请求响应时间 在并发量为1时 用户等待时间相同
Transfer rate: 1710.03 [Kbytes/sec] received # 平均每秒多少K,即带宽速率
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 18.5 0 1001
Processing: 38 471 534.1 155 9269
Waiting: 37 456 524.6 147 9259
Total: 40 472 534.5 155 9269
Percentage of the requests served within a certain time (ms)
50% 155
66% 571
75% 783
80% 871
90% 1211
95% 1603
98% 1839
99% 2003
100% 9269 (longest request)

剩余参数可以用ap --help 查看

siege

安装

下载:wget http://www.joedog.org/pub/siege/siege-latest.tar.gz
解压: tar -zxvf siege-latest.tar.gz
cd siege-*.*.*
./configure --prefix=/usr/local/siege --mandir=/usr/local/man --with-ssl=/usr/local/ssl
mkdir -p /usr/local/siege/etc
mkdir -p /usr/local/siege/var
make
make install

查看配置文件
/usr/local/siege/bin/siege -C

siege的使用

举例说明:

50个用户(每次并发量)重复100次 共产生 50*100 个请求
/usr/local/siege/bin/siege -c 50 -r 100 www.baidu.com

50个用户 重复100次 发送GET参数
/usr/local/siege/bin/siege -c 50 -r 100 http://www.baidu.com/s?wd=siege&rsv_spt=1&issp=1&rsv_bp=0&ie=utf-8&tn=baiduhome_pg&rsv_sug3=4&rsv_sug=2&rsv_sug1=4&rsv_sug4=60

50个用户 重复100次 发送POST参数 (注意引号)
/usr/local/siege/bin/siege -c 50 -r 100 “https://www.abc.com/a.php POST name=zhangsan”

50个用户 重复100次 发送POST参数(从文件中读取)
/usr/local/siege/bin/siege -c 50 -r 100 “https://www.abc.com/a.php POST < /root/ab_test/post.xml”

另外还有挺多参数
详情请man 或 siege -h

Transactions:                     10 hits    :服务器接收的请求数
Availability:                 100.00 %       :有效情况的比例
Elapsed time:                   1.06 secs    :  测试所用的时间
Data transferred:               0.04 MB    :每个模拟用户的数据传输量
Response time:                  0.03 secs    :响应每个模拟用户请求的平均时间
Transaction rate:               9.43 trans/sec    :服务器每秒处理事务的平均数
Throughput:                     0.04 MB/sec    :服务器每秒跟所有模拟用户的数据传输量
Concurrency:                    0.25    :每秒的模拟连接
Successful transactions:          10    :处理成功的事务数(code<400)
Failed transactions:               0    : 处理失败的事务数(code>400)
Longest transaction:            0.04    :最长的事务处理时间
Shortest transaction:           0.02    :最短的事务处理时间

https://www.joedog.org/siege-faq/

你可能感兴趣的:(综合,PHP学习历程)