ab使用命令:ab -c 20 -n 1000 http://localhost:8000/
-c 併發數
-n 請求總數
測試環境:1g記憶體,單cpu單核,虛擬機器ubuntu
測試結果:
server software: tornadoserver/5.0.2
server hostname: localhost
server port: 8000
document path: /
document length: 11 bytes
concurrency level: 20
time taken for tests: 2.772 seconds
complete requests: 1000
failed requests: 0
total transferred: 206000 bytes
html transferred: 11000 bytes
requests per second: 360.74 [#/sec] (mean)
time per request: 55.441 [ms] (mean) 使用者能夠看到的響應時間 ,等於下面的時間*併發數
time per request: 2.772 [ms] (mean, across all concurrent requests) 伺服器處理乙個請求的時間
transfer rate: 72.57 [kbytes/sec] received
connection times (ms)
min mean[+/-sd] median max
connect: 0 0 0.2 0 3
processing: 2 55 92.1 42 1055
waiting: 2 55 92.1 42 1055
total: 2 55 92.2 42 1056
percentage of the requests served within a certain time (ms) (百分比的請求小於多少響應時間)
50% 42
66% 48
75% 53
80% 56
90% 89
95% 101
98% 113
99% 115
100% 1056 (longest request)
增加併發度和請求數
命令:ab -n 10000 -c 1050 http://localhost:8000/
錯誤:apr_socket_recv: connection reset by peer (104)
apr_socket_recv這個是作業系統核心的乙個引數,在高併發的情況下,核心會認為系統受到了syn flood攻擊,會傳送cookies(possible syn flooding on port 80. sending cookies),這樣會減慢影響請求的速度,所以在應用服務**上設定下這個引數為0禁用系統保護就可以進行大併發測試了:
# vim /etc/sysctl.conf
net.ipv4.tcp_syncookies = 0
# sysctl -p
然後就可以超過1000個併發測試了。
改過之後還不行,發現是連線問題,加個引數-k , 啟用http中的「keepalive」特性, 就可以了
結果:server software: tornadoserver/5.0.2
server hostname: localhost
server port: 8000
document path: /
document length: 11 bytes
concurrency level: 1050
time taken for tests: 45.480 seconds
complete requests: 10000
failed requests: 0
keep-alive requests: 10000
total transferred: 2300000 bytes
html transferred: 110000 bytes
requests per second: 219.88 [#/sec] (mean)
time per request: 4775.381 [ms] (mean)
time per request: 4.548 [ms] (mean, across all concurrent requests)
transfer rate: 49.39 [kbytes/sec] received
connection times (ms)
min mean[+/-sd] median max
connect: 0 298 1704.1 0 15398
processing: 4 1923 4676.8 1331 42394
waiting: 4 1923 4676.8 1331 42394
total: 56 2221 5124.8 1375 45435
percentage of the requests served within a certain time (ms)
50% 1375
66% 1719
75% 2016
80% 2089
90% 2499
95% 2700
98% 15741
99% 43323
100% 45435 (longest request)
經過反覆測試,單cpu單核的環境下,開啟http的長連線,在總請求10000的基數下,併發最大為3000,如果不開啟長連線,達到300的時候就會報錯,連線被取消,測試直接退出
使用apache的ab命令進行壓測
環境盡量和線上保持一致 ngixn版本,php版本,網路大小,在測試高併發的時候要修改測試機的最大訪問量ulimit n,ab是單執行緒程式,只能利用單一cpu,在給效能好的伺服器端應用做壓測時,往往跑ab的測試機負荷滿了 而伺服器應用的效能還綽綽有餘。yum y install httpd too...
使用Mysqlslap對Mysql進行壓力測試
mysql5.1版本之後mysql伺服器自帶的基準測試工具,隨mysql一起安裝,可以模擬伺服器負載,並輸出相關的統計資訊,可以指定或自動生成查詢語句。mysqlslap mysqlslap concurrency 50,300 併發50,300個程序 iterations 3 測試執行次數 num...
使用ab對頁面進行壓力測試
ab是apache自帶的乙個很好用的壓力測試工具,當安裝完apache的時候,就可以在bin下面找到ab 1 我們可以模擬100個併發使用者,對乙個頁面傳送1000個請求 ab n1000 c100 其中 n代表請求數,c代表併發數 返回結果 首先是apache的版本資訊 this is apach...