压力测试工具

2016-07-04

JMeter

下载地址:https://jmeter.apache.org/download_jmeter.cgi

启动前需要配置Java环境:把JDK的bin路径加入系统PATH环境变量

如果需全局使用jmeter命令,把jmeter的bin路径加入系统PATH环境变量

命令参数说明:

    --?
            打印命令行选项并退出
    -h, --help
            打印使用信息并退出
    -v, --版本
            打印版本信息并退出
    -p, --propfile <参数>。
            要使用的jmeter属性文件
    -q, --addprop <参数>。
            附加的JMeter属性文件
    -t, --testfile <参数>。
            要运行的jmeter test(.jmx)文件。"-t LAST "将加载最后一个
            旧文件
    -l, --logfile <参数>。
            要记录样本的文件
    -i, --jmeterlogconf <参数>。
            jmeter日志配置文件(log4j2.xml)
    -j, --jmeterlogfile <参数>。
            jmeter运行日志文件(jmeter.log)
    -n,-nongui
            在非gui模式下运行JMeter
    -s, -server
            运行JMeter服务器
    -E, --proxyScheme <参数>。
            设置代理服务器要使用的代理方案。
    -H, --proxyHost <参数>。
            为JMeter设置一个代理服务器,以便使用
    -P, --proxyPort <参数>。
            设置JMeter使用的代理服务器端口
    -N, --nonProxyHosts <参数>。
            设置非代理主机列表(如*.apache.org|localhost)
    -u, --username <参数>。
            设置JMeter要使用的代理服务器的用户名。
    -a, --password <参数>。
            设置JMeter要使用的代理服务器的密码。
    -J, --jmeterproperty <argument>=<value>。
            定义其他JMeter属性
    -G, --globalproperty <argument>=<value>。
            定义全局属性(发送至服务器
            例如:-Gport=123
             或-Gglobal.properties
    -D, --systemproperty <argument>=<value>。
            定义额外的系统属性
    -S, --systemPropertyFile <参数>。
            附加的系统属性文件
    -f, --forceDeleteResultFile。
            强行删除现有的结果文件和网络报告文件夹,如果
             临阵磨枪
    -L, --loglevel <参数>=<值>。
            [category=]级别,如jorphan=INFO,jmeter.util=DEBUG或com.meter.util=DEBUG。
            .example.foo=WARN
    -r, --runremote
            启动远程服务器(定义在 remote_hosts 中)。
    -R, --remotestart <参数>。
            启动这些远程服务器(覆盖 remote_hosts)。
    -d, --homedir <参数>。
            使用jmeter主目录
    -X, --remoteexit
            测试结束后退出远程服务器(非GUI)。
    -g, --reportonly <参数>。
            只从测试结果文件中生成报告仪表板。
    -e, --reportatendofloadtests.
            负载测试后生成报告仪表板
    -o, --reportoutputfolder <参数>。
            报告仪表盘的输出文件夹 命令行测试,并生成报告:
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]

例:

jmeter -n -t 测试计划.jmx -l results.log -e -o out

如何双击直接打开jmx文件?

双击 jmx 文件后, 选择bin下的文件 jmeter-t.cmd

webbench

webbench是Linux下的一个网站压力测试工具,最多可以模拟3万个并发连接去测试网站的负载能力。

下载地址:http://soft.vpser.net/test/webbench/webbench-1.5.tar.gz 解压后不到50K

安装

#tar zxvf webbench-1.5.tar.gz
#cd webbench-1.5
#make && make install

会在当前目录生成webbench可执行文件,直接可以使用了

用法:

webbench -c 并发数 -t 运行测试时间 URL

如:

webbench -c 5000 -t 120 http://www.163.com

AB

1.安装

apt-get install apache2-utils

2.使用

ab -n10000 -c9000 http://malu.me/

说明:

-n 代表请求数,-c 代表并发数

返回结果说明:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>       #apache的版本信息 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests

​ ​ Server Software:
​ Server Hostname: 127.0.0.1 ​ Server Port: 80 ​ Document Path: / Document Length: 0 bytes #页面长度

Concurrency Level:      1000      #并发数 
Time taken for tests:   37.545 seconds   #共使用了多少时间 
Complete requests:      100000           #请求数 
Failed requests:        100000           #失败请求 
   (Connect: 0, Receive: 0, Length: 99712, Exceptions: 288)
Non-2xx responses:      99712
Total transferred:      33403520 bytes   #总共传输字节数,包含http的头信息等 
HTML transferred:       17649024 bytes   #html字节数,实际的页面传递字节数 
Requests per second:    2663.46 [#/sec] (mean)  #每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量 
Time per request:       375.451 [ms] (mean)     #用户平均请求等待时间 
Time per request:       0.375 [ms] (mean, across all concurrent requests) #服务器平均处理时间,也就是服务器吞吐量的倒数 
Transfer rate:          868.84 [Kbytes/sec] received  #每秒获取的数据长度

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       12  178 109.6    184    1185
Processing:    21  196  44.4    196     315
Waiting:        0  146  41.9    136     274
Total:         87  374 116.6    382    1448

Percentage of the requests served within a certain time (ms)
  50%    382    # 50%的请求在382ms内返回 
  66%    388    # 66%的请求在388ms内返回 
  75%    395
  80%    400
  90%    409
  95%    452
  98%    474
  99%   1187
 100%   1448 (longest request)

3.参数使用说明

Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of 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. 'Apache=1234'. (repeatable)
    -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.
    -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.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -h              Display usage information (this message)
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)