apache的ab命令做壓力測試

來源:互聯網
上載者:User

標籤:進程   最大   資源   顯示   let   tag   mfile   cross   ror   

例: ./ab -c 100 -n 10000 http://127.0.0.1/index.php

-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, http://www.apache.org/

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 now in 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頭及內容; 壓力測試時不要這麼做哦:)

apache的ab命令做壓力測試

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.