ab壓力測試的分析
-c 100 即:每次併發100個
-n 10000 即: 共傳送10000個請求
2. 測試結果分析
[[email protected] htdocs]$ /data1/apache/bin/ab -c 1000 -n 50000 "http://10.10.10.10/a.php"
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation,
Benchmarking 10.65.129.21 (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
Finished 50000 requests
Server Software: Apache/1.3.33
Server Hostname: 10.65.129.21
Server Port: 80
Document Path: /a.php //請求的資源
Document Length: 0 bytes // 文件返回的長度,不包括相應頭
Concurrency Level: 1000 // 併發個數
Time taken for tests: 48.650 seconds //總請求時間
Complete requests: 50000 // 總請求數
Failed requests: 0 //失敗的請求數
Broken pipe errors: 0
Total transferred: 9750000 bytes
HTML transferred: 0 bytes
Requests per second: 1027.75 [#/sec] (mean) // 平均每秒的請求數
Time per request: 973.00 [ms] (mean) // 平均每個請求消耗的時間
Time per request: 0.97 [ms] (mean, across all concurrent requests) // 就是上面的時間 除以併發數
Transfer rate: 200.41 [Kbytes/sec] received // 時間傳輸速率
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 183 2063.3 0 45003
Processing: 28 167 770.6 85 25579
Waiting: 21 167 770.6 85 25578
Total: 28 350 2488.8 85 48639
Percentage of the requests served within a certain time (ms)
50% 85 // 就是有50%的請求都是在85ms內完成的
66% 89
75% 92
80% 96
90% 168
95% 640
98% 984
99% 3203
100% 48639 (last request)
3. 用127.0.0.1來訪問可以排除網路的因素,不過在Linux上用本機的對外ip訪問也是不走網絡卡,沒有網路消耗的
ab 幫助:
1. 我們知道用ab測試時,最大併發不能超過1024,其實ab本身沒有做這個限制,而是系統限制每個程序開啟的最大的檔案數為1024,ulimit檢視如下:
[[email protected] ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 1024
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 32765
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
而且open files這個選項在一般的系統裡是不允許修改成無限制的,如下:
[[email protected] ~]# ulimit -n unlimited
bash: ulimit: open files: cannot modify limit: Operation not permitted
但是稍微修改大一些或者是小一些,還是允許的,我們修改的小一些試試:
[[email protected] ~]# ulimit -n 1020
[[email protected] ~]# ulimit -n
1020
[[email protected] ~]#
在用ab測試,錯誤如下:
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 1019
ioctl(1019, FIONBIO, [1]) = 0
gettimeofday({1243919682, 867688}, NULL) = 0
connect(1019, {sa_family=AF_INET, sin_port=htons(80),sin_addr=inet_addr("10.55.38.18")}, 16) = -1 EINPROGRESS (Operation nowin progress)
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = -1 EMFILE (Too many open files)
close(-1) = -1 EBADF (Bad file descriptor)
第1019個還能正常開啟,下一個就報Too many open files的錯誤了
確實有效,那麼我們修改大一些吧:
[[email protected] ~]# ulimit -n 10240
[[email protected] ~]# ulimit -n
10240
[[email protected] ~]#
但是我們發現改大卻不行,這裡卻冒出了一個AF_AX25的名詞:
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 1024
ioctl(1024, FIONBIO, [1]) = 0
gettimeofday({1243919592, 254950}, NULL) = 0
connect(1024, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("10.55.38.18")}, 16) = -1 EINPROGRESS (Operation now in progress)
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 1025
ioctl(1025, FIONBIO, [1]) = 0
gettimeofday({1243919592, 255242}, NULL) = 0
connect(1025, {sa_family=AF_AX25, sa_data="\0P\n7&\22\0\0\0\0\0\0\0\0"}, 16) = -1 EAFNOSUPPORT (Address family not supported by protocol)
這個AF_AX25可能是buffer溢位造成的,但不確定哦:)。
另:
-n 可以指定最大請求數,但是也不能超過50000哦:)
-v n 當n>=2 時,可以顯示傳送的http請求頭,和響應的http頭及內容; 壓力測試時不要這麼做哦:)