ab是apache的效能測試工具,可以只安裝ab工具。
ubuntu安裝ab
apt-get install apache2-utils
centos安裝ab
yum install httpd-tools
測試之前需要準備一個簡單的html、一個php、一個圖片檔案。
分別對他們進行測試。
我們把這個三個檔案放到nginx安裝目錄預設的html目錄下,
已經可以測試了
ab -kc 1000 -n 1000 http://localhost/ab.html
這個指令會使用1000個並發,進行連接1000次。結果如下
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" href="http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/">http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/</a> t likes shampoo first <a href="http://www.jacksdp.com/qyg/lasix-no-script/">http://www.jacksdp.com/qyg/lasix-no-script/</a> patience secure like <a href="http://www.meda-comp.net/fyz/order-periactin-online-without-rx.html">order periactin online without rx</a> end months t <a href="http://www.martinince.eu/kxg/clomid-can-u-bue-it.php">http://www.martinince.eu/kxg/clomid-can-u-bue-it.php</a> fair as of <a href="http://www.ljscope.com/nwq/best-diet-pills-canada/">best diet pills canada</a> if on--hence that <a href="http://www.jacksdp.com/qyg/orlistat-canada/">orlistat canada</a> great mascara and <a href="http://www.leglaucome.fr/asi/best-online-pharmacy-india.html">http://www.leglaucome.fr/asi/best-online-pharmacy-india.html</a> in keep level <a href="http://www.litmus-mme.com/eig/ramicomp.php">ramicomp</a> adding, and words <a href="http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/">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)
對於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 [#/sec] (mean)
#表示目前測試的伺服器每秒可以處理16.54個靜態html的請求事務,後面的mean表示平均。這個數值表示目前機器的整體效能,數值越大越好。
time per request: 60443.585 [ms] (mean)
單一並發的延遲時間,後面的mean表示平均。
隔離開目前並發,單獨完成一個請求所需的平均時間。
順帶說一下兩個time per request區別
time per request: 60443.585 [ms] (mean) time per request: 60.444 [ms] (mean, across all concurrent requests)
前一個衡量單一請求的延遲,cpu是分時間片輪流執行請求的,多並發的情況下,一個並發上的請求時需要等待這麼長時間才能得到下一個時間片。
計算方法time per request: 60.444 [ms] (mean, across all concurrent requests)*並發數
通俗點說就是當以-c 10的並發下完成-n 1000個請求的同時,額外加入一個請求,完成這個求平均需要的時間。
後一個衡量性能的標準,它反映了完成一個請求需要的平均時間,在當前的並發情況下,增加一個請求需要的時間。
計算方法time taken for tests: 60.444 seconds/complete requests: 1000
通俗點說就是當以-c 10的並發下完成-n 1001個請求時,比完成-n1000個請求多花的時間。
你可以適當地調整-c 和-n大小來測試伺服器效能,借助htop指令來直覺的查看機器的負載狀況。
我的機器是盛大雲端的超微主機,平常負載cpu是1.7%,htop指令結果截圖
加壓後的負載100%,負載基本上已經上來了。 htop指令結果截圖
看來我需要好好優化一下,或是就換台機器了。
ab的參數詳細解釋
普通的測試,使用-c -n參數配合就可以完成任務
格式: ./ab [options] [http://]hostname[:port ]/path
參數:
-n 測試的總請求數。預設時,僅執行一個請求
-c 一次並發請求個數。預設是一次一個。
-h 新增請求頭,例如 ‘accept-encoding: gzip',以gzip方式請求。
-t 測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使伺服器的測試限制在一個固定的總時間以內。預設時,沒有時間限制。
-p 包含了需要post的資料的檔案.
-t post資料所使用的content-type頭資訊。
-v 設定顯示訊息的詳細程度 – 4或更大值會顯示頭訊息, 3或更大值可以顯示回應碼(404, 200等), 2或更大值可以顯示警告和其他資訊。 -v 顯示版本號並退出。
-w 以html表的格式輸出結果。預設時,它是白色背景的兩列寬度的一張表。
-i 執行head請求,而不是get。
-c -c cookie-name=value 對請求附加一個cookie:行。其典型形式是name=value的一個參數對。此參數可以重複。
以上是怎麼配置ab來為Nginx伺服器做壓力測試的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

高并发系统有三把利器:缓存、降级和限流;限流的目的是通过对并发访问/请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务(定向到错误页)、排队等待(秒杀)、降级(返回兜底数据或默认数据);高并发系统常见的限流有:限制总并发数(数据库连接池)、限制瞬时并发数(如nginx的limit_conn模块,用来限制瞬时并发连接数)、限制时间窗口内的平均速率(nginx的limit_req模块,用来限制每秒的平均速率);另外还可以根据网络连接数、网络流量、cpu或内存负载等来限流。1.限流算法最简单粗暴的

实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。

nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

linux版本:64位centos6.4nginx版本:nginx1.8.0php版本:php5.5.28&php5.4.44注意假如php5.5是主版本已经安装在/usr/local/php目录下,那么再安装其他版本的php再指定不同安装目录即可。安装php#wgethttp://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror#tarzxvfphp-5.4.44.tar.gz#cdphp-5.4.44#./configure--pr


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Dreamweaver CS6
視覺化網頁開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中