ab压力测试学习笔记

示例

$:ab -c 10 -n 10 http://wdm.life/
This is ApacheBench, Version 2.3 <$Revision: 1874286 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking wdm.life (be patient).....done


Server Software:        GitHub.com
Server Hostname:        wdm.life
Server Port:            80

Document Path:          /
Document Length:        4978 bytes

Concurrency Level:      10
Time taken for tests:   5.076 seconds
Complete requests:      10
Failed requests:        0
Total transferred:      56162 bytes
HTML transferred:       49780 bytes
Requests per second:    1.97 [#/sec] (mean)
Time per request:       5075.852 [ms] (mean)
Time per request:       507.585 [ms] (mean, across all concurrent requests)
Transfer rate:          10.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       26  239 421.2     47    1039
Processing:    28  587 1111.9    126    3625
Waiting:       26   67  85.0     46     305
Total:         58  825 1187.6    340    3654

Percentage of the requests served within a certain time (ms)
  50%    340
  66%    487
  75%   1161
  80%   2096
  90%   3654
  95%   3654
  98%   3654
  99%   3654
 100%   3654 (longest request)

参数说明

-c concurrency,并发数默认最大数256。

-n requests,总共执行次数。

-t timelimit,等待响应的最大时间(s)。

-b windowsseze,TCP缓冲大小(byte)。

-B address,建立传出连接时要绑定的地址。

-p postfile,post上传文件,加外要设置-T参数。

-u putfile,put上传文件,加外要设置-T参数。

-T content-type,post/put请求的设置。

-v verbosity,打印信息。

-w 在HTML表格中打印出结果。

-i 使用HEAD而不是GET。

-x attributes,插入为表格属性的字符串。

-y attributes,作为tr属性插入的字符串。

-z attributes,作为td或th属性插入的字符串。

-C attribute,添加cookie,例如。 'Apache = 1234'。 (可重复)。

-H attribute,添加任意标题行,例如。 'Accept-Encoding:gzip'插入所有普通标题行之后。 (可重复)。

-A attribute,添加基本的WWW身份验证,属性是用冒号分隔的用户名和密码。

-P attribute,添加基本代理身份验证,属性是用冒号分隔的用户名和密码。

-X proxy:port,代理服务器和要使用的端口号。

-V 打印版本号并退出。

-k 使用HTTP KeepAlive功能。

-d 不显示百分号。

-S 不要显示置信度估计器和警告。

-q 执行超过150个请求时不显示进度。

-L 接受可变的文档长度(用于动态页面)。

-g filename,将收集的数据输出到gnuplot格式文件。

-e filename,输出CSV文件并提供百分比。

-r 不要退出套接字接收错误。

-m method,方法名称。

-h 显示用法信息(此消息)。

-I 禁用TLS服务器名称指示(SNI)扩展。

-Z ciphersuite,指定SSL / TLS密码套件(请参阅openssl密码)。

-f protocol,指定SSL / TLS协议(TLS1,TLS1.1,TLS1.2或ALL)

-E certfile,指定可选的客户端证书链和私钥

错误解决方案(mac)

  1. socket: Too many open files (24)

    查看

    $:ulimit -a
        -t: cpu time (seconds)              unlimited
        -f: file size (blocks)              unlimited
        -d: data seg size (kbytes)          unlimited
        -s: stack size (kbytes)             8192
        -c: core file size (blocks)         0
        -v: address space (kbytes)          unlimited
        -l: locked-in-memory size (kbytes)  unlimited
        -u: processes                       2784
        -n: file descriptors                256
    

    临时修改

    $:ulimit -n 1024
    

    确认查看

    $:ulimit -a
        -t: cpu time (seconds)              unlimited
        -f: file size (blocks)              unlimited
        -d: data seg size (kbytes)          unlimited
        -s: stack size (kbytes)             8192
        -c: core file size (blocks)         0
        -v: address space (kbytes)          unlimited
        -l: locked-in-memory size (kbytes)  unlimited
        -u: processes                       2784
        -n: file descriptors                1024
    

    如查还不ok就进行以下操作

    # 如果还不行就执行以下命令 永久生效就添加到 ~/.zshrc 文件下
    $:sudo launchctl limit maxfiles 100000 500000
    $:sudo ulimit -n 100000
    

    再不行就修改aparoche 的配置文件吧

    $:sudo vim /private/etc/apache2/extra/httpd-default.conf
    # 修改这个它  MaxKeepAliveRequests 1000
    MaxKeepAliveRequests 1000