首页 > 其他分享 >ab压力测试

ab压力测试

时间:2022-12-28 16:57:17浏览次数:64  
标签:10 ab http Apache 测试 压力 attributes requests

概述

ab命令全称为 Apache bench 是Apache自带的压力测试工具。ab命令非常实用,它不仅可以对Apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试,ab命令会创建多个并发线程,模拟多个访问者同时对某一个url地址进行访问,实现压力测试

ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原理类似CC攻击,可能会造成目标服务器资源耗尽,严重时可能会导致死机,而且它没有图形化结果不能监控,所以只能用作临时紧急任务和简单的测试

官方文档:ab - Apache HTTP server benchmarking tool

我的mac不记得啥时候装了。

命令选项:

qicycledeMacBook-Pro-3:~ qicycle$ ab -h
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.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (TLS1, TLS1.1, TLS1.2 or ALL)
    -E certfile     Specify optional client certificate chain and private key
qicycledeMacBook-Pro-3:~ qicycle$ ab -V
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

 

实例

模拟10个客户端,在10秒内测试10000次压力测试,目的url是http://10.0.22.121:1180/break

qicycledeMacBook-Pro-3:~ qicycle$ ab -c 10 -t 10 -n 10000 -k  'http://10.0.22.121:1180/break'
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 10.0.22.121 (be patient)
Completed 1000 requests
Completed 2000 requests
Finished 2528 requests


Server Software:        openresty/1.15.8.2
Server Hostname:        10.0.22.121
Server Port:            1180

Document Path:          /break
Document Length:        20 bytes

Concurrency Level:      10
Time taken for tests:   10.092 seconds
Complete requests:      2528
Failed requests:        2356
   (Connect: 0, Receive: 0, Length: 2356, Exceptions: 0)
Non-2xx responses:      2356
Keep-Alive requests:    2507
Total transferred:      786151 bytes
HTML transferred:       378044 bytes
Requests per second:    250.49 [#/sec] (mean)
Time per request:       39.922 [ms] (mean)
Time per request:       3.992 [ms] (mean, across all concurrent requests)
Transfer rate:          76.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       4
Processing:     1   35 142.0      3    1001
Waiting:        1   35 142.0      3    1001
Total:          1   35 142.0      3    1001

Percentage of the requests served within a certain time (ms)
  50%      3
  66%      3
  75%      4
  80%      4
  90%      5
  95%    212
  98%    681
  99%    816
 100%   1001 (longest request)

 

标签:10,ab,http,Apache,测试,压力,attributes,requests
From: https://www.cnblogs.com/zhanchenjin/p/17010489.html

相关文章