性能术语

  1. 性能测试

性能测试是利用流程来降低应用程序,升级程序,补丁程序部署风险的某一种手段, 通过模拟产生真实业务的压力对被测试系统进行压力测试, 验证被测试系统在不同压力下的具体情况, 从而找出潜在的瓶颈.

那么, 性能测试的方法都有哪些? 性能测试相关的专业术语都有哪些? 平常所见到的 TPS 等与性能测试的关系为何?

  1. 测试方法

这里简单的描述一下常见的性能测试方法, 其他不做过多介绍:

  • 负载测试(Load Testing): Large amount of users, 从小的负荷开始, 逐渐增加负载, 观察不同负载下应用程序的响应时间,消耗资源等等, 它是测试系统在不同工作负荷(负载)下的性能指标, 从而了解服务器的工作能力.
  • 压力测试(Stress Testing): Too many users, too much data, too little time and too little root, 在负荷条件(系统资源极少)情况下系统长时间运行的稳定性, 利用脚本故意吃掉服务器部分 CPU/内存/带宽等方式, 亦或者大业务量情况下导致的服务器资源不足, 从而观察系统的稳定性 , 测试系统是否发生崩溃, 宕机, 无法请求等问题, 找到系统某项功能的隐患, 发现系统是否拥有良好的容错能力, 恢复能能力. 压力测试分为: 稳定性压力测试, 破坏性压力测试.
  • 容量测试(Volume Test): Large amount of data, 测试预先分析的指标极限值(最大并发等), 测试系统在极限情况下运行状态.
  1. 测试术语
  • RT: 响应时间, 在单用户系统中, 响应时间可以很好的度量系统性能. 注意, 不同的系统, 不同场景, 响应事件对用户的感官是不同的
  • ART: 平均事务响应时间, 用于分析系统运行期间的性能走向
  • Throughput: 吞吐量, 单位时间内处理请求的数量, 在并发系统而言, 吞吐量常常作为系统的性能指标
  • 并发用户数: 系统可以同时承载正常使用系统的用户数目
  • QPS: Query per second, 每秒查询次数, 某些特定的查询服务器, 例如域名系统的性能就以 QPS 来衡量
  • TPS: Transactions per second, 每秒事务数, 一个事务表示客户端发送请求, 服务器做出响应的完整过程
  • RPS: Request per second, 每秒请求数, 最大吞吐率, 其往往等价于 TPS.

其中 ART 和 TPS 在不同的并发用户数目下, 两者的值有着巨大的区别, 例如, 对于一个最大并发数目为 10, 每一个事务处理时间为 1 的系统而言:

1
2
3
4
5
6
7
8
9
# 1. 只有 10 个用户同时并发请求时
TPS == 10
ART == 1
# 2. 峰值: 有 20 个用户同时并发请求时
TPS == 10
ART == (1 + 2) / 2 == 1.5
# 3. 峰值: 有 50 个用户同时并发请求时
TPS == 10
ART == (1(首 10 辆) + 2 + 3 + 4 + 5(最后十辆)) / 5 == 3

ab

命令

ab(Apache Benchmark)一般作为第一章节所述的压力测试工具, 其针对 HTTP 服务器进行性能测试, 模拟多线程并发请求, 测试服务器的负载压力. 在测试过程中考虑到带宽原因, 很多情况下, 一般在单机上进行压力测试, 而非远程, 当然, 如果需要将带宽也加入到压力测试的考虑范围, 则建议远程进行 ab 命令压测.

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
39
40
41
42
43
44
Usage: ab [options] [http[s]://]hostname[:port]/path

options are:
-n requests 指定压力测试的总执行次数
-c concurrency 指定压力测试的并发数
-t timelimit 指定时间内发送全部请求, 默认隐含的-n值为 50000
-s timeout 请求响应最大超时, 默认 30S
-b windowsize TCP 发送和接收缓冲池大小(字节)
-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 HTML 格式打印结果
-i 使用 HEAD 请求代替 GET
-x attributes 插入字符串作为table标签的属性
-y attributes 插入字符串作为tr标签的属性
-z attributes 插入字符串作为td, th标签的属性
-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 使用HTTP 的KeepAlive特性
-d 不显示百分比.
-S 不显示预估和警告信息.
-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 发生socket连接错误也不退出
-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

例如下面的一些命令例子:

1
2
3
4
5
6
# 1. 总共 800 个请求, 200并发
ab -n 800 -c 200 -r "http://127.0.0.1:5000/"
# 2. 在限定的60秒发送请求, 一次 100 个并发
ab -t 60 -c 100 -r "http://127.0.0.1:5000/"
# 3. 指定请求体以携带文件
ab -t 60 -c 100 -r -T "text/plain" -p t.txt "http://127.0.0.1:5000/upload"

输出

命令: ab -n 900 -c 130 -r "http://127.0.0.1:5000/sleep"

其输出如下:

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
47
48
49
50
51
52
53
54
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 127.0.0.1 (be patient)
# 1. 完成的请求数目
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 900 requests


Server Software: gunicorn/19.7.1 服务器软件名称及版本信息
Server Hostname: 127.0.0.1 服务器主机名
Server Port: 5000 服务器端口

Document Path: /sleep 供测试的URL路径或页面文档
Document Length: 10 bytes 供测试的URL返回的文档大小

Concurrency Level: 130 并发数
Time taken for tests: 2.024 seconds 整个测试持续时间
Complete requests: 900 完成请求数目
Failed requests: 0 失败的请求数目
Total transferred: 153000 bytes 整个测试场景的网络传输字节
HTML transferred: 9000 bytes 整个测试场景的HTML 内容传输字节

Requests per second: 444.72 [#/sec] (mean) 平均每秒的请求数
Time per request: 292.318 [ms] (mean) 平均事务响应时间, 并发客户端都请求一次的平均时间
Time per request: 2.249 [ms] (mean, across all concurrent requests) 每个请求实际运行时间的平均值
Transfer rate: 73.83 [Kbytes/sec] received 平均每秒网络上的流量

Connection Times (ms) 网络上消耗的时间的分解
min mean[+/-sd] median max
Connect: 0 3 4.3 1 23
Processing: 203 239 32.0 226 312
Waiting: 201 236 30.7 222 308
Total: 203 242 31.6 232 313

Percentage of the requests served within a certain time (ms) 整个场景中所有请求的响应情况
50% 232
66% 254
75% 275
80% 279
90% 287
95% 296
98% 307
99% 309
100% 313 (longest request)

参考

站内: