使用ab對nginx進行壓力測試

nginx以高併發,省內存著稱。
 
相信大多數安裝nginx的同學都想知道自己的nginx性能如何。
 
我想跟大家分享下我使用ab工具的壓力測試方法和結果,
 
ab是針對apache的性能測試工具,可以只安裝ab工具。
 
ubuntu使用如下命令
 
apt-get install apache2-utils
 
 
測試之前需要準備一個簡單的html、一個php、一個圖片文件。
 
分別對他們進行測試。
 
我們把這個三個文件放到nginx安裝目錄默認的html目錄下,
 
 
準備之後我們就可以測試了
 
ab -kc 1000 -n 1000 http://localhost/ab.html
 
這個指令會使用1000個併發,進行連接1000次。結果如下
 
root@SNDA-172-17-12-117:/usr/local/nginx# ab -kc 1000 -n 1000 http://www.nginx.c n/ab.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.nginx.cn (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
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.2.3
Server Hostname: www.nginx.cn
Server Port: 80
 
Document Path: /ab.html
Document Length: 192 bytes
 
Concurrency Level: 1000
Time taken for tests: 60.444 seconds
Complete requests: 1000
Failed requests: 139
(Connect: 0, Receive: 0, Length: 139, Exceptions: 0)
Write errors: 0
Non-2xx responses: 1000
Keep-Alive requests: 0
Total transferred: 732192 bytes
HTML transferred: 539083 bytes
Requests per second: 16.54 [#/sec] (mean)
Time per request: 60443.585 [ms] (mean)
Time per request: 60.444 [ms] (mean, across all concurrent requests)
Transfer rate: 11.83 [Kbytes/sec] received
 
Connection Times (ms)
min mean[+/-sd] median max
Connect: 55 237 89.6 261 328
Processing: 58 5375 13092.8 341 60117
Waiting: 57 5337 12990.0 341 59870
Total: 386 5611 13083.7 572 60443
 
Percentage of the requests served within a certain time (ms)
50% 572
66% 606
75% 635
80% 672
90% 30097
95% 42004
98% 47250
99% 49250
100% 60443 (longest request)
 
對於php文件和圖片文件可以使用同樣指令進行,結果我就不貼出來了。
 
 
 
ab -kc 500 -n 5000 http://localhost/ab.php
 
ab -kc 500 -n 5000 http://localhost/ab.gif
 
 
 
輸出結果我們可以從字面意思就可以理解。
 
這裏對兩個比較重要的指標做下說明
 
比如
 
Requests per second: 16.54 [#/sec] (mean)
Time per request: 60443.585 [ms] (mean)
 
Requests per second表示當前測試的服務器每秒可以處理16.54個靜態html的請求。
 
Time per request表示nginx收到用戶請求,到給出響應頁面要花費的時間。
 
 
 
你可以適當調節-c 和-n大小來測試服務器性能,藉助htop指令來直觀的查看機器的負載情況。
 
我的機器是盛大雲的超微主機,平時負載cpu是1.7%,htop命令結果截圖
 
 
加壓後的負載100%,負載基本已經上來了。htop命令結果截圖
詳細出處參考:http://www.nginx.cn/110.html
 
看來我需要好好優化一下,或者就換臺機器了。
 
參考http://go2linux.garron.me/linux/2010/04/how-benchmark-stress-your-apache-nginx-or-iis-server-718
 
 
詳細出處參考:http://www.nginx.cn/110.html
發佈了2 篇原創文章 · 獲贊 37 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章