測試公式
[xxh@xxh-vmwarevirtualplatform code]$ ab -n 10 -c 3 http://lum2.test/
This is ApacheBench, Version 2.3 <$Revision: 1874286 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking lum2.test (be patient).....done
Server Software: nginx/1.18.0
Server Hostname: lum2.test
Server Port: 80
Document Path: /
Document Length: 39 bytes
Concurrency Level: 3
Time taken for tests: 0.009 seconds
Complete requests: 10
Failed requests: 0
Total transferred: 2730 bytes
HTML transferred: 390 bytes
Requests per second: 1175.78 [#/sec] (mean)
Time per request: 2.552 [ms] (mean)
Time per request: 0.851 [ms] (mean, across all concurrent requests)
Transfer rate: 313.46 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 2 2 0.3 2 3
Waiting: 2 2 0.3 2 3
Total: 2 2 0.3 2 3
Percentage of the requests served within a certain time (ms)
50% 2
66% 2
75% 2
80% 2
90% 3
95% 3
98% 3
99% 3
100% 3 (longest request)
ab -n 10 -c 3 http://lum2.test
公式需要的關鍵變數
[Complete requests] 請求數(成功的) 10
[Time taken for tests] 花費時間 0.009
[Concurrency Level] 併發數 3
......
qps計算
公式: qps = 請求數 / 花費時間
公式: [Requests per second] = [Complete requests] / [Time taken for tests]
結果: 10 / 0.009 = 1111.11111....
為什麼qps不是1175.78? 而是 1111.11….
因為[Time taken for tests]
被四捨五入了。
Time per request (第一個)
公式: tpr(1) = 併發數 * 花費時間 * 1000 / 請求數`
公式: tpr(1) = [Concurrency Level] * [Time taken for tests] * 1000 / [Complete requests] `
結果: 3 * 0.009 * 1000 / 10 = 2.7
(為什麼不是2.5? 因為誤差 上面已介紹)
Time per request (第二個)
公式: tpr(2) = 花費時間 * 1000 / 請求數`
公式: tpr(2) = [Time taken for tests] * 1000 / [Complete requests]
結果: 0.009 * 1000 / 10 = 0.009
ab原始碼
變數解釋:
done 請求數
timetaken 花費時間
concurrency 併發數
//qps
printf("Requests per second: %.2f [#/sec] (mean)\n",
(double) done / timetaken);
//tpr(1)
printf("Time per request: %.3f [ms] (mean)\n",
(double) concurrency * timetaken * 1000 / done);
//tpr(2)
printf("Time per request: %.3f [ms] (mean, across all concurrent requests)\n",(double) timetaken * 1000 / done);
原始碼地址: CloudFundoo/ApacheBench-ab
816行
最後來張php框架qps測試圖
ab -n 20000 -c 200
本作品採用《CC 協議》,轉載必須註明作者和本文連結