ubuntu中安装apache ab命令进行简单压力测试

吞吐率(Requests per second)
概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
计算公式:总请求数 / 处理完成这些请求数所花费的时间,即
Request per second = Complete requests / Time taken for tests

并发连接数(The number of concurrent connections)
概念:某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。

并发用户数(The number of concurrent users,Concurrency Level)
概念:要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。

用户平均请求等待时间(Time per request)
计算公式:处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即
Time per request = Time taken for tests /( Complete requests / Concurrency Level)

服务器平均请求等待时间(Time per request: across all concurrent requests)
计算公式:处理完成所有请求数所花费的时间 / 总请求数,即
Time taken for / testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也=用户平均请求等待时间/并发用户数,即
Time per request / Concurrency Level

1.安裝ab命令

sudo apt-get install apache2-utils
ab -V # 确认安装成功

2.ab命令参数说明

shylin@shylin:~/Desktop/sky_server$ 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
                    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) ext

3.运行 ab -n 2000 -c 100 进行2000次请求,100个并发请求压力测试结果。

shylin@shylin:~/Desktop/sky_server$ ab -n 2000 -c 100 http://10.234.7.131:4478/api/sky_server_data_app/a/get?id=1
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 10.234.7.131 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests


Server Software:        gunicorn/19.1.0
Server Hostname:        10.234.7.131
Server Port:            4478

Document Path:          /api/sky_server_data_app/a/get?id=1
Document Length:        105 bytes

Concurrency Level:      100       //并发请求数
Time taken for tests:   4.438 seconds  //整个测试持续的时间
Complete requests:      2000   //完成的请求数
Failed requests:        0   //失败的请求数
Total transferred:      516000 bytes   //整个场景中的网络传输量
HTML transferred:       210000 bytes  //整个场景中的HTML内容传输量
Requests per second:    450.64 [#/sec] (mean)   # //吞吐率,每秒服务器处理的请求数
Time per request:       221.908 [ms] (mean)  // 用户平均请求等待时间 
Time per request:       2.219 [ms] (mean, across all concurrent requests) 服务器平均请求等待时间
Transfer rate:          113.54 [Kbytes/sec] received   //平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

Connection Times (ms)     // 这段表示网络上消耗的时间的分解
              min  mean[+/-sd] median   max
Connect:       60   67   4.4     68      84
Processing:   107  150  45.3    132     407
Waiting:      107  149  45.3    132     407
Total:        175  217  46.2    200     489

// 每个请求处理时间的分布情况,50%的处理时间在4930ms内,66%的处理时间在5008ms内...,重要的是看90%的处理时间。
Percentage of the requests served within a certain time (ms)
  50%    200
  66%    217
  75%    222
  80%    227
  90%    269
  95%    315
  98%    378
  99%    424
 100%    489 (longest request)

Shylin

猜你喜欢

转载自blog.csdn.net/Shyllin/article/details/80944974
今日推荐