性能测试工具 wrk,ab 压测结果比较

wrk,ab,locust,jmeter 压测结果比较

准备

wrk

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

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
brew install wrk

wrk -v
wrk [kqueue] Copyright (C) 2012 Will Glozer
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
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details

Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)

ab (Apache Bench)

ab是Apache超文本传输协议(HTTP)的性能测试工具。其设计意图是描绘当前所安装的Apache的执行性能,主要是显示你安装的Apache每秒可以处理多少个请求。

安装

1
2
3
4
5
6
7
8
9
进入httpd目录
./configure
sudo make
sudo make install

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

wrk

参数说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
% wrk -v
wrk [kqueue] Copyright (C) 2012 Will Glozer
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
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details

Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)
1
2
3
4
5
6
7
-c:总的连接数(每个线程处理的连接数=总连接数/线程数)
-d:测试的持续时间,如2s(2second),2m(2minute),2h(hour),默认为s
-t:需要执行的线程总数,默认为2,一般线程数不宜过多. 核数的24倍足够了. 多了反而因为线程切换过多造成效率降低
-s:执行Lua脚本,这里写lua脚本的路径和名称,后面会给出案例
-H:需要添加的头信息,注意header的语法,举例,-H “token: abcdef”
—timeout:超时的时间
—latency:显示延迟统计信息

运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
% wrk -t 5 -c 300 -d 60 --latency http://localhost:9801/                                         1
Running 1m test @ http://localhost:9801/
5 threads and 300 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 288.03ms 140.21ms 1.34s 87.31%
Req/Sec 221.94 86.65 560.00 70.71%
Latency Distribution
50% 257.29ms
75% 312.34ms
90% 411.33ms
99% 920.93ms
64748 requests in 1.00m, 11.73MB read
Socket errors: connect 0, read 173, write 15, timeout 0
Requests/sec: 1078.37
Transfer/sec: 200.09KB

返回结果说明

1
2
3
4
5
6
7
8
Latency:响应时间
Req/Sec:每个线程每秒钟的执行的连接数
Avg:平均
Max:最大
Stdev:标准差
+/- Stdev: 正负一个标准差占比
Requests/sec:每秒请求数(也就是QPS),等于总请求数/测试总耗时
Latency Distribution,如果命名中添加了—latency就会出现相关信息

300 个连接数跑 60 秒:Request/sec(每秒请求数):1078.37

ab

参数说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
% 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
-t timelimit Seconds to max. wait for responses
-b windowsize Size of TCP send/receive buffer, in bytes
-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 for POSTing, 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.
-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
(SSL2, SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
1
2
3
4
5
-n 表示请求总数(与-t参数可任选其一)
-c 表示并发数
-t 标识请求时间
-p:模拟post请求,文件格式为gid=2&status=1,配合-T使用
-T:post数据所使用的Content-Type头信息,如-T 'application/x-www-form-urlencoded'

运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
% ab -c 300 -t 60 https://hexo.lilis.xin/                                                       54
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking hexo.lilis.xin (be patient)
Finished 1803 requests


Server Software: GitHub.com # 测试服务器的名字
Server Hostname: hexo.lilis.xin # 请求的URL主机名
Server Port: 443 # web服务器监听的端口
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128

Document Path: / # 请求的URL中的根绝对路径
Document Length: 31290 bytes # HTTP响应数据的正文长度

Concurrency Level: 300 # 并发用户数, 这是我们设置的参数之一
Time taken for tests: 60.023 seconds # 所有这些请求被处理完成所花费的总时间
Complete requests: 1803 # 总请求数量, 这是我们设置的参数之一
Failed requests: 0 # 表示失败的请求数量, 这里的失败是指的请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况
Write errors: 0
Total transferred: 60468718 bytes # 所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度
HTML transferred: 59089320 bytes # 所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
Requests per second: 30.04 [#/sec] (mean) # 吞吐率, 计算公式: Complete requests/Time taken for tests 总请求数/处理完成这些请求数所花费的时间
Time per request: 9987.262 [ms] (mean) # 用户平均请求等待时间, 计算公式: Time token for tests/(Complete requests/Concurrency Level)。处理完成所有请求数所花费的时间/(总请求数/并发用户数)
Time per request: 33.291 [ms] (mean, across all concurrent requests) # 服务器平均请求等待时间, 计算公式: Time taken for tests/Complete requests,正好是吞吐率的倒数
Transfer rate: 983.81 [Kbytes/sec] received # 表示这些请求在单位时间内从服务器获取的数据长度

Connection Times (ms)
min mean[+/-sd] median max
Connect: 486 3009 3112.2 2212 33168
Processing: 220 5512 4516.1 4517 47154
Waiting: 115 503 883.0 183 18372
Total: 745 8521 5710.0 7448 47759

Percentage of the requests served within a certain time (ms)
50% 7447
66% 9253
75% 10799
80% 11569
90% 15143
95% 19453
98% 25129
99% 29527
100% 47759 (longest request)

Powered by Hexo and Hexo-theme-hiker

Copyright © 2017 - 2023 Keep It Simple And Stupid All Rights Reserved.

访客数 : | 访问量 :