http://www.nginx.cn/110.html
nginx以高并發(fā),省內(nèi)存著稱。
相信大多數(shù)安裝nginx的同學(xué)都想知道自己的nginx性能如何。
我想跟大家分享下我使用ab工具的壓力測(cè)試方法和結(jié)果,
ab是針對(duì)apache的性能測(cè)試工具,可以只安裝ab工具。
ubuntu安裝ab
|
apt-get install apache2-utils |
centos安裝ab
測(cè)試之前需要準(zhǔn)備一個(gè)簡(jiǎn)單的html、一個(gè)php、一個(gè)圖片文件。
分別對(duì)他們進(jìn)行測(cè)試。
我們把這個(gè)三個(gè)文件放到nginx安裝目錄默認(rèn)的html目錄下,

準(zhǔn)備之后我們就可以測(cè)試了
ab -kc 1000 -n 1000 http://localhost/ab.html
這個(gè)指令會(huì)使用1000個(gè)并發(fā),進(jìn)行連接1000次。結(jié)果如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 |
root@~# ab -kc 1000 -n 1000 http://www.nginx.cn/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)
<strong>Time per request: 60443.585 [ms] (mean)
Time per request: 60.444 [ms] (mean, across all concurrent requests)</strong>
Transfer <div style="position:absolute; left:-3679px; top:-3033px;">WOULD foundation it staring one <a href="http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php">http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php</a> hours regular After progressive-sided below <a rel="nofollow" >http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/</a> t likes shampoo first <a >http://www.jacksdp.com/qyg/lasix-no-script/</a> patience secure like <a >order periactin online without rx</a> end months t <a >http://www.martinince.eu/kxg/clomid-can-u-bue-it.php</a> fair as of <a >best diet pills canada</a> if on--hence that <a >orlistat canada</a> great mascara and <a >http://www.leglaucome.fr/asi/best-online-pharmacy-india.html</a> in keep level <a >ramicomp</a> adding, and words <a >http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/</a> I, adhesive product...</div> 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) |
對(duì)于php文件和圖片文件可以使用同樣指令進(jìn)行,結(jié)果我就不貼出來了。
ab -kc 500 -n 5000 http://localhost/ab.php
ab -kc 500 -n 5000 http://localhost/ab.gif
輸出結(jié)果我們可以從字面意思就可以理解。
這里對(duì)兩個(gè)比較重要的指標(biāo)做下說明
比如
Requests per second: 16.54 [#/sec] (mean)
Time per request: 60443.585 [ms] (mean)
Requests per second: 16.54 [#/sec] (mean)
表示當(dāng)前測(cè)試的服務(wù)器每秒可以處理16.54個(gè)靜態(tài)html的請(qǐng)求事務(wù),后面的mean表示平均。這個(gè)數(shù)值表示當(dāng)前機(jī)器的整體性能,值越大越好。
Time per request: 60443.585 [ms] (mean)
單個(gè)并發(fā)的延遲時(shí)間,后面的mean表示平均。
隔離開當(dāng)前并發(fā),單獨(dú)完成一個(gè)請(qǐng)求需要的平均時(shí)間。
順帶說一下兩個(gè)Time per request區(qū)別
Time per request: 60443.585 [ms] (mean)
Time per request: 60.444 [ms] (mean, across all concurrent requests)
前一個(gè)衡量單個(gè)請(qǐng)求的延遲,cpu是分時(shí)間片輪流執(zhí)行請(qǐng)求的,多并發(fā)的情況下,一個(gè)并發(fā)上的請(qǐng)求時(shí)需要等待這么長(zhǎng)時(shí)間才能得到下一個(gè)時(shí)間片。
計(jì)算方法Time per request: 60.444 [ms] (mean, across all concurrent requests)*并發(fā)數(shù)
通俗點(diǎn)說就是當(dāng)以-c 10的并發(fā)下完成-n 1000個(gè)請(qǐng)求的同時(shí),額外加入一個(gè)請(qǐng)求,完成這個(gè)求平均需要的時(shí)間。
后一個(gè)衡量性能的標(biāo)準(zhǔn),它反映了完成一個(gè)請(qǐng)求需要的平均時(shí)間,在當(dāng)前的并發(fā)情況下,增加一個(gè)請(qǐng)求需要的時(shí)間。
計(jì)算方法Time taken for tests: 60.444 seconds/Complete requests: 1000
通俗點(diǎn)說就是當(dāng)以-c 10的并發(fā)下完成-n 1001個(gè)請(qǐng)求時(shí),比完成-n1000個(gè)請(qǐng)求多花的時(shí)間。
你可以適當(dāng)調(diào)節(jié)-c 和-n大小來測(cè)試服務(wù)器性能,借助htop指令來直觀的查看機(jī)器的負(fù)載情況。
我的機(jī)器是盛大云的超微主機(jī),平時(shí)負(fù)載cpu是1.7%,htop命令結(jié)果截圖

加壓后的負(fù)載100%,負(fù)載基本已經(jīng)上來了。htop命令結(jié)果截圖

看來我需要好好優(yōu)化一下,或者就換臺(tái)機(jī)器了。
----------------
ab的參數(shù)詳細(xì)解釋
普通的測(cè)試,使用-c -n參數(shù)配合就可以完成任務(wù)
格式: ./ab [options] [http://]hostname[:port]/path
參數(shù):
-n 測(cè)試的總請(qǐng)求數(shù)。默認(rèn)時(shí),僅執(zhí)行一個(gè)請(qǐng)求
-c 一次并發(fā)請(qǐng)求個(gè)數(shù)。默認(rèn)是一次一個(gè)。
-H 添加請(qǐng)求頭,例如 ‘Accept-Encoding: gzip’,以gzip方式請(qǐng)求。
-t 測(cè)試所進(jìn)行的最大秒數(shù)。其內(nèi)部隱含值是-n 50000。它可以使對(duì)服務(wù)器的測(cè)試限制在一個(gè)固定的總時(shí)間以內(nèi)。默認(rèn)時(shí),沒有時(shí)間限制。
-p 包含了需要POST的數(shù)據(jù)的文件.
-T POST數(shù)據(jù)所使用的Content-type頭信息。
-v 設(shè)置顯示信息的詳細(xì)程度 – 4或更大值會(huì)顯示頭信息, 3或更大值可以顯示響應(yīng)代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號(hào)并退出。
-w 以HTML表的格式輸出結(jié)果。默認(rèn)時(shí),它是白色背景的兩列寬度的一張表。
-i 執(zhí)行HEAD請(qǐng)求,而不是GET。
-C -C cookie-name=value 對(duì)請(qǐng)求附加一個(gè)Cookie:行。 其典型形式是name=value的一個(gè)參數(shù)對(duì)。此參數(shù)可以重復(fù)。
參考http://go2linux.garron.me/linux/2010/04/how-benchmark-stress-your-apache-nginx-or-iis-server-718
posted on 2017-03-30 15:28
思月行云 閱讀(259)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
Nginx\Openresty