apache ab test使用 apache ab test使用 單獨安裝ab和htpasswd轉載自:http://www.cnblogs.com/super-d2/p/3831155.html#tophttp://blog.chinaunix.net/uid-20382003-id-30321...
apache ab test使用 apache ab test使用 單獨安裝ab和htpasswd
轉載自:
http://www.cnblogs.com/super-d2/p/3831155.html#top
http://blog.chinaunix.net/uid-20382003-id-3032167.html
單獨安裝ab和htpasswd
yum install -y httpd-tools 完成後,就可以直接運行ab # which ab /usr/bin/ab # rpm -qf /usr/bin/ab httpd-tools-2.2.15-47.el6.centos.1.x86_64 # which htpasswd /usr/bin/htpasswd
壓測方法,一定要指定頁面名
/usr/bin/ab -n 3000 -c 3000 https://www.baidu.com/index.php
壓測之前先執行下麵命令
ulimit -n 65535
htpasswd加密
預設以DES加密 htpasswd -c /root/aa.txt test # cat aa.txt test:Dl4dQa5GI3Qzs md5和sha加密 htpasswd -c -m /root/.aa.txt user1
先查看一下版本信息 ab -V(註意是大寫的V)
2、我們也可以使用小寫的v查看下ab命令的一些屬性 ab -v
1、命令格式
ab命令放在apache目錄bin目錄下麵,使用方法如下
./ab -n 3000 -c 3000 http://www.test.com/
其中-n代表每次併發量,-c代表總共發送的數量
2、測試結果分析
[root@Svr107 bin]# ./ab -n 3000 -c 3000 http://www.test.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.twioo.com (be patient)
Completed 300 requests
Completed 600 requests
Completed 900 requests
Completed 1200 requests
Completed 1500 requests
Completed 1800 requests
Completed 2100 requests
Completed 2400 requests
Completed 2700 requests
Completed 3000 requests
Finished 3000 requests
Server Software: nginx/0.7.65
Server Hostname: www.test.com
Server Port: 80
Document Path: / ###請求的資源
Document Length: 50679 bytes ###文檔返回的長度,不包括頁頭
Concurrency Level: 3000 ###併發個數
Time taken for tests: 30.449 seconds ###總請求時間
Complete requests: 3000 ###總請求數
Failed requests: 0 ###失敗的請求數
Write errors: 0
Total transferred: 152745000 bytes
HTML transferred: 152037000 bytes
Requests per second: 98.52 [#/sec] (mean) ###平均每秒的請求數
Time per request: 30449.217 [ms] (mean) ###平均每個請求消耗的時間
Time per request: 10.150 [ms] (mean, across all concurrent requests) ###上面的請求除以併發數
Transfer rate: 4898.81 [Kbytes/sec] received ###傳輸速率
Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 54 27.1 55 98
Processing: 51 8452 5196.8 7748 30361
Waiting: 50 6539 5432.8 6451 30064
Total: 54 8506 5210.5 7778 30436
Percentage of the requests served within a certain time (ms)
50% 7778 ###50%的請求都在7778ms內完成
66% 11059
75% 11888
80% 12207
90% 13806 ###90%的請求都在13806 ms內完成
95% 18520
98% 24232
99% 24559
100% 30436 (longest request) ###100%的請求都在30436ms內完成 大部分請求響應時間都很長
3、如果用ab訪問的是本機上的web伺服器,使用127.0.0.1或者是web伺服器上的網卡IP地址,這個是不走網路設備的,可以忽略網路消耗
4、ab使用的一些問題
a、ab命令在一般系統上面做測試時候,一般併發不能超過1024個,其實是因為因為系統限制每個進程打開的最大文件數為1024,可以用ulimit -a來查看
open files (-n) 65536 ##這個我系統已經修改過
b、-n 可以指定最大請求數,但是不能超過50000個
c、-v n 當n>=2 時,可以顯示發送的http請求頭,和響應的http頭及內容,壓力測試時不要這麼做
[root@Svr107 bin]# ./ab -n 1 -c 1 -v 2 http://www.test.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.test.com (be patient)...INFO: POST header ==
---
GET / HTTP/1.0
Host: www.test.com
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
Server: nginx/0.7.65
Date: Thu, 01 Dec 2011 13:08:16 GMT
Content-Type: text/html
Connection: close
Vary: Accept-Encoding
Content-Length: 50515
Last-Modified: Thu, 01 Dec 2011 13:08:04 GMT
Accept-Ranges: bytes
<sc< div="">
..done
Server Software: nginx/0.7.65
Server Hostname: www.test.com
Server Port: 80
Document Path: /
Document Length: 50515 bytes
Concurrency Level: 1
Time taken for tests: 0.006 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Total transferred: 50751 bytes
HTML transferred: 50515 bytes
Requests per second: 176.27 [#/sec] (mean)
Time per request: 5.673 [ms] (mean)
Time per request: 5.673 [ms] (mean, across all concurrent requests)
Transfer rate: 8736.39 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 5 5 0.0 5 5
Waiting: 1 1 0.0 1 1
Total: 6 6 0.0 6 6
在做壓力測試的時候,一般情況下壓力測試客戶端接收到的數據量一定會遠大於發送出去的數據量
問題
b -n 3000 -c 3000 http://192.168.0.2/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.0.2 (be patient)
socket: Too many open files (24)
解決方法:
查看當前要以打開的文件個數
[root@zabbix ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 14802
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024 #只能打開1024個socket文件 /埠
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 14802
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
調整可以打開的文件數
[root@zabbix ~]# ulimit -n 65535
重新執行ab命令即可解決
自己壓測結果
# /usr/bin/ab -n 3000 -c 3000 https://www.baidu.com/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.baidu.com (be patient)
Completed 300 requests
Completed 600 requests
SSL handshake failed (5).
Completed 900 requests
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
SSL handshake failed (5).
/usr/bin/ab -n 3000 -c 3000 https://www.baidu.com:443/index.php
/usr/bin/ab -n 3000 -c 3000 http://www.80ops.cn/archives/178.html
/usr/bin/ab -n 3 -c 3 http://www.80ops.cn/archives/178.html
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.80ops.cn (be patient).....done
Server Software: nginx/1.6.3
Server Hostname: www.80ops.cn
Server Port: 80
Document Path: /archives/178.html
Document Length: 74117 bytes
Concurrency Level: 3
Time taken for tests: 1.092 seconds
Complete requests: 3
Failed requests: 0
Write errors: 0
Total transferred: 223206 bytes
HTML transferred: 222351 bytes
Requests per second: 2.75 [#/sec] (mean)
Time per request: 1092.167 [ms] (mean)
Time per request: 364.056 [ms] (mean, across all concurrent requests)
Transfer rate: 199.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 28 30 1.3 30 31
Processing: 126 587 435.8 817 993
Waiting: 38 44 5.1 47 48
Total: 157 616 435.2 846 1022
Percentage of the requests served within a certain time (ms)
50% 669
66% 669
75% 1022
80% 1022
90% 1022
95% 1022
98% 1022
99% 1022
100% 1022 (longest request)
You have new mail in /var/spool/mail/root
相關問題
http://blog.csdn.net/largetalk/article/details/7337102
http://2hei.net/linux_web_test_tools_for_https.html