⑴ 怎麼對nginx代理進行壓力測試
nginx以高並發,省內存著稱。
相信大多數安裝nginx的同學都想知道自己的nginx性能如何。
我想跟大家分享下我使用ab工具的壓力測試方法和結果,
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 proct...</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指令來直觀的查看機器的負載情況。
⑵ php 網站壓力測試主要是測試哪些方面
apache自帶一個測試軟體:ab.exe
ab.exe-k-c300-n2000http://localhost/
-k keep-alive
-c 並發線程數量
-n 請求數量
返回的報告:
每秒處理次數
最慢處理時間
平均每次請求的處理時間
⑶ 普通linux伺服器nginx+php能支持多少並發
和機器硬體配置還有系統、軟體設置什麼的相關。
這個東西結果每個機器都不一樣,具體支持多少必須做壓力測試。
相對來說 nginx 的性能要比 apache 高,apache 的穩定性功能和擴展能力比 nginx 好。
可以看看這個帖子:
http://bbs.51cto.com/thread-920544-1-1.html
⑷ NGINX+PHP好,還是NGINX+APACHE+PHP好
如果單台伺服器的話,NGINX+APACHE+PHP
純粹多此一舉,多了一次請求轉發,效率肯定低,而且現在FPM已經足夠穩定。完全沒必要。
只有多台伺服器集群的話,apache+nginx反代才有意義.NGINX+APACHE+PHP
這種架構存在的原因除了apache出現比較早外,還因為當時FPM不如mole模式穩定。
不見得。Nginx在前面實現動靜分離,靜態內容由Nginx負責,動態請求則交給後面的PHP應用伺服器Apache(libphp5.so)處理。Apache專心處理PHP,這不挺好嗎?
Nginx+PHP-FPM相對Nginx+Apache(libphp5.so)來說,PHP-FPM更靈活,在php-fpm.conf里可以配置監聽不同埠的多個pool,每個pool又可以自由配置PHP-FPM工人進程數pm.max_children,一個pool里的工人進程繁忙不會影響到另一個pool。在Nginx里可以配置應用的不同部分使用不同的pool,而且一台伺服器上可以運行多個版本的PHP-FPM,藉助Nginx的upstream功能,PHP-FPM非常容易橫向擴展。
新浪微博和網路貼吧都在使用Nginx+PHP-FPM的架構,PHP-FPM已經足夠穩定。
ab同樣並發數壓力測試ZF下RPS(請求每秒)對比:
⑸ 請教,如何對PHP站點作壓力測試
網站壓力測試Web-CT 4.0
可以測試不同上網方式、在不同地區、訪問Web不同頁面、在不同並發訪問密度情況下的:客戶端的響應時間、流量和流速;可以測試任何主機、Web Server和頁面(HTML、CGI、JSP、PHP、ASP、GIF、FLASH以及聲音、MPEG等多媒體文檔);可以進行分布式多機並行測試,然後合並和計算機測試報告,實現極高的伺服器測試壓力。
⑹ 在對nginx進行壓力測試的時候為什麼並發了30左右伺服器就假死了
如果你是ssh遠程連接到伺服器,那麼可能是連接數或者帶寬被打滿了。
⑺ php web伺服器。網站上線在即,請問如何測試伺服器壓力呢比如如何知道這個網站到底能同時承受
利用一些軟體吧,可用來進行 Web 壓力測試的工具有很多,比如微軟的 Web Application Stress、Linux下的 siege、功能全面的 Web-CT 等等,這些都是非常優秀的 Web 壓力測試工具。
一、 Siege
一款開源的壓力測試工具,可以根據配置對一個WEB站點進行多用戶的並發訪問,記錄每個用戶所有請求過程的相應時間,並在一定數量的並發訪問下重復進行。
官方:http://www.joedog.org/
1. 下載源碼
請自行google例如:
wget http://soft.vpser.net/test/siege/siege-2.67.tar.gz
2. 解壓、編譯和安裝
tar -zxf siege-2.67.tar.gz cd siege-2.67/ /configure make && make install
3. 運行siege
siege -c 200 -r 10 -f test.txt
-c是並發量,-r是重復次數。 url文件就是一個文本,每行都是一個url,它會從裡面隨機訪問的。
test.txt 內容:
http://blog.test.com/wp-content/uploads/2012/07/cluster6.png
http://blog.test.com/wp-content/uploads/2012/07/cluster7-150x150.png
http://blog.test.com/wp-content/uploads/2012/07/cluster7.png
http://blog.test.com/wp-content/uploads/2012/07/cluster8-150x150.png
http://blog.test.com/wp-content/uploads/2012/07/cluster9-150x150.png
4 結果說明
Lifting the server siege… done.
Transactions: 3419263 hits //完成419263次處理
Availability: 100.00 % //100.00 % 成功率
Elapsed time: 5999.69 secs //總共用時
Data transferred: 84273.91 MB //共數據傳輸84273.91 MB
Response time: 0.37 secs //相應用時1.65秒:顯示網路連接的速度
Transaction rate: 569.91 trans/sec //均每秒完成 569.91 次處理:表示伺服器後
Throughput: 14.05 MB/sec //平均每秒傳送數據
Concurrency: 213.42 //實際最高並發數
Successful transactions: 2564081 //成功處理次數
Failed transactions: 11 //失敗處理次數
Longest transaction: 29.04 //每次傳輸所花最長時間
Shortest transaction: 0.00 //每次傳輸所花最短時間
二、Webbench
webbench最多可以模擬3萬個並發連接去測試網站的負載能力,安裝使用簡單方便。
1. 下載源碼
請自行google例如:
wget http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz
2. 解壓、編譯和安裝
tar zxvf webbench-1.5.tar.gz cd webbench-1.5 make mkdir /usr/local/man #建立相應目錄否則導致無法正常安裝 make install
3. 運行webbench
webbench -c 100 -t 30 http://192.168.1.235/index.html
-c表示並發數,-t表示時間(秒)
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://192.168.1.235/index.html
100 clients, running 30 sec.
Speed=16084 pages/min, 152872 bytes/sec. #運行結果顯示
Requests: 8042 susceed, 0 failed.
三、Web Application Stress Tool
這是由微軟的網站測試人員開發的專門用來進行實際網站壓力測試以一套工具。透過這套功能強大的壓力測試工具,管理人員可以在網站實際上線之前先網站進行如同真實環境下的測試,以找出系統潛在的問題,對系統進行進一步的調整、設置工作。
⑻ nginx上php環境搭建好了怎麼測試
可以在linux里執行 curl 127.0.0.1
如果能返回nginx默認頁面,則表示nginx安裝成功。