1.ab

1.1ab介绍

ab是apache自带的压力测试工具。ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx、tomcat、IIS等。

1.2安装

yum -y install httpd-tools

1.3使用方法

[root@iZ2zeahsw6g9oowlc0udckZ ~]# ab --help
ab: wrong number of arguments
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		#等待响应的最大时间,默认是30s
                    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
    -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)

for example:

[root@iZ2zeahsw6g9oowlc0udckZ ~]# ab -n1000 -c1000 http://127.0.0.1:40059/status.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx
Server Hostname:        127.0.0.1
Server Port:            40059

Document Path:          /status.html
Document Length:        99 bytes

Concurrency Level:      1000
Time taken for tests:   3.264 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      252000 bytes
HTML transferred:       99000 bytes
Requests per second:    306.33 [#/sec] (mean)
Time per request:       3264.427 [ms] (mean)
Time per request:       3.264 [ms] (mean, across all concurrent requests)
Transfer rate:          75.39 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   21   5.2     21      30
Processing:    11 1419 984.7   1023    3223
Waiting:        0 1419 984.8   1023    3223
Total:         30 1440 981.5   1045    3235

Percentage of the requests served within a certain time (ms)
  50%   1045
  66%   1236
  75%   1239
  80%   3038
  90%   3040
  95%   3041
  98%   3041
  99%   3234
 100%   3235 (longest request)

TIP:

可能遇到的问题有链接超时,被对方重置。

可以使用选项-r和-k来解决。

2.wrk

转载:https://www.cnblogs.com/quanxiaoha/p/10661650.html

2.1什么是wrk

摘自官方 GitHub 上的英文介绍:

wrk 官方说明

翻译一下:

wrk 是一款针对 Http 协议的基准测试工具,它能够在单机多核 CPU 的条件下,使用系统自带的高性能 I/O 机制,如 epoll,kqueue 等,通过多线程和事件模式,对目标机器产生大量的负载。

PS: 其实,wrk 是复用了 redis 的 ae 异步事件驱动框架,准确来说 ae 事件驱动框架并不是 redis 发明的, 它来至于 Tcl 的解释器 jim, 这个小巧高效的框架, 因为被 redis 采用而被大家所熟知。

2.2wrk的优势&劣势

2.2.1 优势

在说 wrk 的优势之前,瞅一下 wrk 的 GitHub Star 数,也能侧面反映下它的可靠性:

wrk Star 数

Wow ! 截止笔者截图为止, Star 数已经达到了 19742 !!!

再来说说 wrk 的优势:

  • 轻量级性能测试工具;
  • 安装简单(相对 Apache ab 来说);
  • 学习曲线基本为零,几分钟就能学会咋用了;
  • 基于系统自带的高性能 I/O 机制,如 epoll, kqueue, 利用异步的事件驱动框架,通过很少的线程就可以压出很大的并发量;

2.2.2 劣势

wrk 目前仅支持单机压测,后续也不太可能支持多机器对目标机压测,因为它本身的定位,并不是用来取代 JMeter, LoadRunner 等专业的测试工具,wrk 提供的功能,对我们后端开发人员来说,应付日常接口性能验证还是比较友好的。

2.2.3wrk安装

Ubuntu/Debian

依次执行如下命令:

sudo apt-get install build-essential libssl-dev git -y
git clone https://github.com/wg/wrk.git wrk
cd wrk
make
# 将可执行文件移动到 /usr/local/bin 位置
sudo cp wrk /usr/local/bin

CentOS / RedHat / Fedora

依次执行如下命令:

sudo yum groupinstall 'Development Tools'
sudo yum install -y openssl-devel git 
git clone https://github.com/wg/wrk.git wrk
cd wrk
make
# 将可执行文件移动到 /usr/local/bin 位置
sudo cp wrk /usr/local/bin

2.2.4wrk的使用

[root@iZ2zeahsw6g9oowlc0udckZ ~]# wrk --help
Usage: wrk <options> <url>                            
  Options:                                            
    -c, --connections <N>  Connections to keep open  # 设置跟服务器的连接数
    -d, --duration    <T>  Duration of test	   #压测时间    	    
    -t, --threads     <N>  Number of threads to use   #使用的线程数
                                                      
    -s, --script      <S>  Load Lua script file       #制定Lua脚本路径
    -H, --header      <H>  Add header to request      #为每一个http请求制定头
        --latency          Print latency statistics   #在压测之后打印延迟的统计信息
        --timeout     <T>  Socket/request timeout     #设置超时时间
    -v, --version          Print version details      #打印正在使用的wrk的版本信息
                                                      
  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)

for example:

wrk -t12 -c400 -d30s --latency http://www.baidu.com
[root@iZ2zeahsw6g9oowlc0udckZ ~]# wrk -t12 -c400 -d30s --latency http://www.baidu.com
Running 30s test @ http://www.baidu.com
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   250.04ms  349.43ms   1.97s    83.64%
    Req/Sec    71.34     54.03     1.08k    88.99%
  Latency Distribution
     50%   53.26ms
     75%  273.30ms
     90%  696.17ms
     99%    1.54s 
  25384 requests in 30.10s, 379.43MB read
  Socket errors: connect 0, read 648, write 0, timeout 581
Requests/sec:    843.31
Transfer/sec:     12.61MB
Logo

更多推荐