1、ab压测工具安装及使用
# 安装
dnf install httpd-tools -y
# 使用帮助
# 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) extension
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL2, TLS1, TLS1.1, TLS1.2, TLS1.3 or ALL)
-E certfile Specify optional client certificate chain and private key
# 压测(-c 100表示并发数为100,-n 1000表示请求数为1000,-t 10表示测试时间为10秒)
# ab -c 100 -n 1000 -t 10 http://10.32.161.129:8080/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.32.161.129 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests
Server Software:
Server Hostname: 10.32.161.129
Server Port: 8080
Document Path: /
Document Length: 321 bytes
Concurrency Level: 100
Time taken for tests: 7.220 seconds
Complete requests: 50000
Failed requests: 0
Total transferred: 26450000 bytes
HTML transferred: 16050000 bytes
Requests per second: 6925.63 [#/sec] (mean)
Time per request: 14.439 [ms] (mean)
Time per request: 0.144 [ms] (mean, across all concurrent requests)
Transfer rate: 3577.79 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.8 0 9
Processing: 4 13 7.5 12 74
Waiting: 1 13 7.8 11 74
Total: 8 14 6.8 12 76
Percentage of the requests served within a certain time (ms)
50% 12
66% 13
75% 15
80% 17
90% 22
95% 26
98% 40
99% 45
100% 76 (longest request)
分析如下:
吞吐量:
服务器每秒处理了6925.63个请求,表明吞吐量表现良好。
响应时间:
平均响应时间为14.439毫秒,处于较低水平,整体响应速度较快。
50%的请求在12毫秒内完成,90%的请求在22毫秒内完成,也体现了快速的响应。
个别请求耗时较长,最长请求时间为76毫秒,需要进一步分析原因。
并发性:
测试中使用了100个并发连接,服务器仍能保持较好的吞吐量和响应时间,说明并发处理能力较强。
稳定性:
测试过程中没有出现失败请求,表明服务器运行稳定。
其他指标:
连接时间:平均连接时间为1毫秒,连接建立速度较快。
等待时间:平均等待时间为13毫秒,大部分请求在服务器端的等待时间较低。
传输速率:平均传输速率为3577.79 Kbytes/秒,传输速度较快。
总结:
从测试结果来看,该服务器在上述测试条件下表现出了良好的性能,吞吐量高、响应时间低、并发性强、运行稳定。
建议:
针对个别耗时较长的请求进行分析,找出原因并优化。
考虑更高并发的压力测试,以全面评估服务器的性能承载能力。
结合实际业务场景,对测试结果进行更有针对性的分析。
2、wrk压测工具安装
# 安装
yum -y groupinstall 'Development Tools'
yum -y install openssl-devel git zlib-devel
git clone https://github.com/giltene/wrk2.git
cd wrk2
make
cp wrk /usr/local/bin
# 使用帮助
# 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
-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)
# 压测(-c 100表示并发数为100,-d 10表示测试时间为10秒,-t 12表示线程数为12)
# wrk -c 100 -d 10 -t 12 http://10.32.161.129:8080/
Running 10s test @ http://10.32.161.129:8080/
12 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.72ms 7.94ms 130.68ms 85.33%
Req/Sec 3.08k 1.12k 11.41k 73.92%
369023 requests in 10.10s, 179.55MB read
Requests/sec: 36536.72
Transfer/sec: 17.78MB
分析如下:
吞吐量:
服务器每秒处理了36536.72个请求,表明吞吐量表现优秀。
响应时间:
平均响应时间为5.72毫秒,处于较低水平,整体响应速度较快。
部分请求响应时间较长,最长请求时间达到130.68毫秒,需要进一步关注。
并发性:
测试中使用了120个并发连接,服务器仍能保持较高的吞吐量和较低的平均响应时间,说明并发处理能力强。
稳定性:
测试过程中没有显示失败请求,表明服务器运行稳定。
其他指标:
请求总数:369023个,较为充分地体现了服务器的处理能力。
传输速率:17.78MB/秒,数据传输效率高。
总结:
从测试结果来看,该服务器在上述测试条件下表现出了优秀的性能,吞吐量高、响应时间低、并发性强、运行稳定。
但仍需重点关注部分请求响应时间较长的问题,并进行针对性优化。
建议:
分析长尾请求: 深入分析响应时间较长的请求,找出原因,例如是否存在资源瓶颈、业务逻辑耗时、数据库访问频繁等,并进行针对性优化。
持续监控: 在实际业务场景中,持续监控服务器性能指标,及时发现性能瓶颈并进行优化。
调整测试参数: 尝试调整并发连接数、测试时长等参数,进一步评估服务器性能承载能力。
综合评估: 结合业务场景的实际需求,对服务器性能进行综合评估,并制定适当的性能优化策略。
3、wrk2压测工具安装
# 安装
yum -y groupinstall 'Development Tools'
yum -y install openssl-devel git zlib-devel
git clone https://github.com/giltene/wrk2.git
cd wrk2
make
cp wrk /usr/local/bin
# 使用帮助
# 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
-H, --header <H> Add header to request
-L --latency Print latency statistics
-U --u_latency Print uncorrected latency statistics
--timeout <T> Socket/request timeout
-B, --batch_latency Measure latency of whole
batches of pipelined ops
(as opposed to each op)
-v, --version Print version details
-R, --rate <T> work rate (throughput)
in requests/sec (total)
[Required Parameter]
Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)
# 压测(-c 100表示并发数为100,-d 10表示测试时间为10秒,-t 12表示线程数为12,-R 1000表示每秒请求数为1000)
# wrk -c 100 -d 10 -t 12 -R 1000 http://10.32.161.129:8080/
Running 10s test @ http://10.32.161.129:8080/
12 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.01ms 433.16us 4.21ms 65.29%
Req/Sec -nan -nan 0.00 0.00%
10031 requests in 10.00s, 4.88MB read
Requests/sec: 1003.08
Transfer/sec: 499.76KB
分析如下:
吞吐量:
服务器每秒处理了1003.08个请求,表明吞吐量表现良好。
响应时间:
平均响应时间为1.01毫秒,处于较低水平,整体响应速度较快。
99%的请求在3毫秒内完成,表明响应时间稳定。
并发性:
测试中使用了120个并发连接,服务器仍能保持较好的吞吐量和响应时间,说明并发处理能力较强。
稳定性:
测试过程中没有出现失败请求,表明服务器运行稳定。
其他指标:
请求数:10031个,与 ab 测试结果一致。
传输数据量:4.88MB,与 ab 测试结果一致。
总结:
从测试结果来看,该服务器在上述测试条件下表现出了良好的性能,吞吐量高、响应时间低、并发性强、运行稳定。
建议:
结合实际业务场景,对测试结果进行更有针对性的分析。
具体分析:
与 ab 测试结果相比,wrk 测试结果的吞吐量略高,响应时间略低。这是由于 wrk 使用了更高效的算法,可以更有效地利用 CPU 资源。此外,wrk 使用了更小的请求体,因此响应时间也更低。
从吞吐量和响应时间来看,该服务器在上述测试条件下可以满足大多数业务需求。但是,如果需要进一步提高性能,可以考虑以下措施:
优化服务器硬件配置,例如增加 CPU 核心数或内存容量。
优化服务器软件配置,例如调整缓存大小或减少数据库访问次数。
优化业务逻辑,例如减少不必要的计算或IO操作。
参考:https://github.com/hegphegp/docker-learning/tree/master/%E5%B8%B8%E7%94%A8%E8%BD%AF%E4%BB%B6/%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95%E5%B7%A5%E5%85%B7
浙公网安备 33010602011771号