《如何使用Apache的ab進(jìn)行壓力測(cè)試》要點(diǎn):
本文介紹了如何使用Apache的ab進(jìn)行壓力測(cè)試,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
ab是apache自帶的壓力測(cè)試工具,當(dāng)安裝完apache的時(shí)候,就可以在bin下面找到ab然后進(jìn)行apache 負(fù)載壓力測(cè)試了,測(cè)試方法非常的簡單我們只要./ab -n1000 -c100 url就可以了,下面介紹一下具體的使用方法
一、下載
1、可以安裝apache/mysql/php套裝軟件:xampp
2、可以直接上apache官網(wǎng)下載apache
選擇windows版本:
選擇具體類型:
其中后兩個(gè)是有名的wamp以及xampp集成環(huán)境,如果只想下載apache可以選擇前三個(gè)網(wǎng)站,這里我們第一個(gè)ApacheHaus為例
下載完后直接解壓到硬盤,我這里解壓到D盤,ab.exe程序就在D:\Apache24\bin中.
二、使用ab.exe
打開cmd,進(jìn)到bin目錄中,輸入ab回車就可以看到詳細(xì)的幫助信息:
三、測(cè)試node.js服務(wù)的壓力
我先在linux上啟動(dòng)一個(gè)node程序,此時(shí)訪問地址是:http://192.168.132.144:8000/
打開cmd進(jìn)入到bin目錄中,輸入ab.exe -c 1000 -n 1000 http://192.168.132.144:8000/
注意最后一個(gè)/必須要輸入,測(cè)試結(jié)果如下:
四、Apache的ab命令集合
格式: ./ab [options] [http://]hostname[:port]/path
參數(shù):
-n requests Number of requests to perform
//在測(cè)試會(huì)話中所執(zhí)行的哀求個(gè)數(shù).默認(rèn)時(shí),僅執(zhí)行一個(gè)哀求
-c concurrency Number of multiple requests to make
//一次產(chǎn)生的哀求個(gè)數(shù).默認(rèn)是一次一個(gè).
-t timelimit Seconds to max. wait for responses
//測(cè)試所進(jìn)行的最大秒數(shù).其內(nèi)部隱含值是-n 50000.它可以使對(duì)服務(wù)器的測(cè)試限制在一個(gè)固定的總時(shí)間以內(nèi).默認(rèn)時(shí),沒有時(shí)間限制.
-p postfile File containing data to POST
//包含了需要POST的數(shù)據(jù)的文件.
-T content-type Content-type header for POSTing
//POST數(shù)據(jù)所使用的Content-type頭信息.
-v verbosity How much troubleshooting info to print
//設(shè)置顯示信息的詳細(xì)程度 - 4或更大值會(huì)顯示頭信息, 3或更大值可以顯示響應(yīng)代碼(404, 200等), 2或更大值可以顯示警告和其他信息. -V 顯示版本號(hào)并退出.
-w Print out results in HTML tables
//以HTML表的格式輸出結(jié)果.默認(rèn)時(shí),它是白色背景的兩列寬度的一張表.
-i Use HEAD instead of GET
// 執(zhí)行HEAD哀求,而不是GET.
-x attributes String to insert as table attributes
//
-y attributes String to insert as tr attributes
//
-z attributes String to insert as td or th attributes
//
-C attribute Add cookie, eg. 'Apache=1234. (repeatable)
//-C cookie-name=value 對(duì)哀求附加一個(gè)Cookie:行. 其典型形式是name=value的一個(gè)參數(shù)對(duì).此參數(shù)可以重復(fù).
-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.
//-P proxy-auth-username:password 對(duì)一個(gè)中轉(zhuǎn)代理提供BASIC認(rèn)證信任.用戶名和密碼由一個(gè):隔開,并以base64編碼形式發(fā)送.無論服務(wù)器是否需要(即, 是否發(fā)送了401認(rèn)證需求代碼),此字符串都會(huì)被發(fā)送.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
//-attributes 設(shè)置 屬性的字符串. 缺陷程序中有各種靜態(tài)聲明的固定長度的緩沖區(qū).另外,對(duì)命令行參數(shù)、服務(wù)器的響應(yīng)頭和其他外部輸入的解析也很簡單,這可能會(huì)有不良后果.它沒有完整地實(shí)現(xiàn)HTTP/1.x; 僅接受某些'預(yù)想'的響應(yīng)格式. strstr(3)的頻繁使用可能會(huì)帶來性能問題,即, 你可能是在測(cè)試ab而不是服務(wù)器的性能.
參數(shù)很多,一般我們用 -c 和 -n 參數(shù)就可以了. 例如:
./ab -c 1000 -n 1000 http://127.0.0.1/index.php
這個(gè)表示同時(shí)處理1000個(gè)哀求并運(yùn)行1000次index.php文件.
#/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 http://127.0.0.1/index.html.zh-cn.gb2312
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
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 127.0.0.1 (be patient)
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 1000 requests
Server Software: Apache/2.0.54
//平臺(tái)apache 版本2.0.54
Server Hostname: 127.0.0.1
//服務(wù)器主機(jī)名
Server Port: 80
//服務(wù)器端口
Document Path: /index.html.zh-cn.gb2312
//測(cè)試的頁面文檔
Document Length: 1018 bytes
//文檔大小
Concurrency Level: 1000
//并發(fā)數(shù)
Time taken for tests: 8.188731 seconds
//整個(gè)測(cè)試持續(xù)的時(shí)間
Complete requests: 1000
//完成的哀求數(shù)量
Failed requests: 0
//失敗的哀求數(shù)量
Write errors: 0
Total transferred: 1361581 bytes
//整個(gè)場(chǎng)景中的網(wǎng)絡(luò)傳輸量
HTML transferred: 1055666 bytes
//整個(gè)場(chǎng)景中的HTML內(nèi)容傳輸量
Requests per second: 122.12 [#/sec] (mean)
//大家最關(guān)心的指標(biāo)之一,相當(dāng)于 LR 中的 每秒事務(wù)數(shù) ,后面括號(hào)中的 mean 表示這是一個(gè)平均值
Time per request: 8188.731 [ms] (mean)
//大家最關(guān)心的指標(biāo)之二,相當(dāng)于 LR 中的 平均事務(wù)響應(yīng)時(shí)間 ,后面括號(hào)中的 mean 表示這是一個(gè)平均值
Time per request: 8.189 [ms] (mean, across all concurrent requests)
//每個(gè)哀求實(shí)際運(yùn)行時(shí)間的平均值
Transfer rate: 162.30 [Kbytes/sec] received
//平均每秒網(wǎng)絡(luò)上的流量,可以幫助排除是否存在網(wǎng)絡(luò)流量過大導(dǎo)致響應(yīng)時(shí)間延長的問題
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 646 1078.7 89 3291
Processing: 165 992 493.1 938 4712
Waiting: 118 934 480.6 882 4554
Total: 813 1638 1338.9 1093 7785
//網(wǎng)絡(luò)上消耗的時(shí)間的分解,各項(xiàng)數(shù)據(jù)的具體算法還不是很清楚
Percentage of the requests served within a certain time (ms)
50% 1093
66% 1247
75% 1373
80% 1493
90% 4061
95% 4398
98% 5608
99% 7368
100% 7785 (longest request)
//整個(gè)場(chǎng)景中所有哀求的響應(yīng)情況.在場(chǎng)景中每個(gè)哀求都有一個(gè)響應(yīng)時(shí)間,其中50%的用戶響應(yīng)時(shí)間小于1093 毫秒,60% 的用戶響應(yīng)時(shí)間小于1247 毫秒,最大的響應(yīng)時(shí)間小于7785 毫秒
由于對(duì)于并發(fā)哀求,cpu實(shí)際上并不是同時(shí)處理的,而是按照每個(gè)哀求獲得的時(shí)間片逐個(gè)輪轉(zhuǎn)處理的,所以基本上第一個(gè)Time per request時(shí)間約等于第二個(gè)Time per request時(shí)間乘以并發(fā)哀求數(shù).
《如何使用Apache的ab進(jìn)行壓力測(cè)試》是否對(duì)您有啟發(fā),歡迎查看更多與《如何使用Apache的ab進(jìn)行壓力測(cè)試》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/13028.html