如何测试web服务器性能,如何执行Web服务器性能基准测试?
本文概述
你知道你網站的平均響應時間嗎?你知道你的網站可以處理多少個并發用戶嗎?
負載測試對于Web應用程序了解網站容量至關重要。如果要選擇Web服務器, 那么要做的第一件事就是執行負載測試, 然后看看哪一個對你來說效果很好。
標桿管理可以幫助你做出決定;
哪個Web服務器效果最好
你需要服務的服務器數量x請求數量
哪種配置可為你帶來最佳效果
有幾種在線工具可以進行壓力測試。但是, 如果你正在尋找內部解決方案或僅對Web服務器性能進行基準測試, 則可以使用ApacheBench以及下面列出的一些工具。
我已經使用DigitalOcean上托管的Apache&Nginx Web服務器對其進行了測試。
工具清單
ApacheBench
SIEGE
Gobench
Apache JMeter
wrk
Httpload
curl-loader
httperf
Tsung
ApacheBench
ApacheBench(ab)是可與任何Web服務器一起使用的開源命令行程序。在這篇文章中, 我將解釋如何安裝這個小程序并執行負載測試以對結果進行基準測試。
Apache
讓我們使用yum命令安裝ApacheBench。
yum install httpd-tools
如果你已經擁有httpd工具, 則可以忽略它。
現在, 讓我們看看它如何處理500個并發的5000個請求。
[[email?protected] ~]# ab -n 5000 -c 500 http://localhost:80/
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software:??????? Apache/2.2.15
Server Hostname:??????? localhost
Server Port:??????????? 80
Document Path:????????? /
Document Length:??????? 4961 bytes
Concurrency Level:????? 500
Time taken for tests:?? 13.389 seconds
Complete requests:????? 5000
Failed requests:??????? 0
Write errors:?????????? 0
Non-2xx responses:????? 5058
Total transferred:????? 26094222 bytes
HTML transferred:?????? 25092738 bytes
Requests per second:??? 373.45 [#/sec] (mean)
Time per request:?????? 1338.866 [ms] (mean)
Time per request:?????? 2.678 [ms] (mean, across all concurrent requests)
Transfer rate:???? ?????1903.30 [Kbytes/sec] received
Connection Times (ms)
min? mean[+/-sd] median?? max
Connect:??????? 0?? 42? 20.8???? 41??? 1000
Processing:???? 0? 428 2116.5???? 65?? 13310
Waiting:??????? 0? 416 2117.7???? 55?? 13303
Total:???????? 51? 470 2121.0??? 102?? 13378
Percentage of the requests served within a certain time (ms)
50%??? 102
66%??? 117
75%??? 130
80%??? 132
90%??? 149
95%??? 255
98%? 13377
99%? 13378
100%? 13378 (longest request)
[[email?protected] ~]#
因此, 你可以看到, Apache每秒處理373個請求, 并且總共花費了13.389秒來處理所有請求。
現在你知道默認配置可以滿足許多請求, 因此當你進行任何配置更改時, 你可以再次進行測試以比較結果并選擇最佳結果。
Nginx的
讓我們測試一下我們對Apache所做的工作, 以便你可以比較哪個性能更好。
[[email?protected] ~]# ab -n 5000 -c 500 http://localhost:80/
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software:??????? nginx/1.10.1
Server Hostname:??????? localhost
Server Port:??????????? 80
Document Path:????????? /
Document Length:??????? 3698 bytes
Concurrency Level:????? 500
Time taken for tests:?? 0.758 seconds
Complete requests:????? 5000
Failed requests:??????? 0
Write errors:?????????? 0
Total transferred:????? 19660000 bytes
HTML transferred:?????? 18490000 bytes
Requests per second:??? 6593.48 [#/sec] (mean)
Time per request:?????? 75.832 [ms] (mean)
Time per request:?????? 0.152 [ms] (mean, across all concurrent requests)
Transfer rate:????? ????25317.93 [Kbytes/sec] received
Connection Times (ms)
min? mean[+/-sd] median?? max
Connect:??????? 0??? 6? 11.0????? 2????? 53
Processing:???? 5?? 19?? 8.2???? 17????? 53
Waiting:??????? 0?? 18?? 8.2???? 16????? 47
Total:???????? 10?? 25? 17.4???? 18????? 79
Percentage of the requests served within a certain time (ms)
50%???? 18
66%???? 21
75%???? 21
80%???? 22
90%???? 69
95%???? 73
98%???? 75
99%???? 76
00%???? 79 (longest request)
[[email?protected] ~]#
哇!你看到了嗎? Nginx每秒處理6593個請求!贏家。
因此, 你只需要與兩臺Web服務器進行比較, 便會了解為Web應用程序選擇哪一臺。
以上測試是在CentOS 6.8(64位)上進行的。你可以嘗試OS和Web Server版本的多種組合以獲得最佳結果。
SIEGE
SIEGE是UNIX支持的HTTP負載測試實用程序。你可以在一個文本文件中放入多個URL, 以進行測試。你可以使用yum安裝圍攻。
# yum install siege
讓我們以500個并發請求運行測試5秒鐘。
[[email?protected] ~]# siege -q -t 5S -c 500 http://localhost/
Lifting the server siege...????? done.
Transactions:?????????????? ??????? 4323 hits
Availability:???????? ????? 100.00 %
Elapsed time:?????????????? ??????? 4.60 secs
Data transferred: ?????? 15.25 MB
Response time:??????????? ??????? 0.04 secs
Transaction rate: ????? 939.78 trans/sec
Throughput:???????????????? ??????? 3.31 MB/sec
Concurrency:?????????????? ?????? 37.97
Successful transactions:??????? 4323
Failed transactions:???? ?????????? 0
Longest transaction:??? ??????? 1.04
Shortest transaction:??? ??????? 0.00
[[email?protected] ~]#
分解參數。
-q –安靜運行(不顯示請求詳細信息)
-t –運行5秒鐘
-c – 500個并發請求
如你所見, 可用性為100%, 響應時間為0.04秒。你可以根據你的目標調整負載測試參數。
Gobench
Gobench用Go語言和簡單的負載測試實用程序編寫, 以基準測試Web服務器的性能。它支持超過20, 000個并發用戶, 而ApacheBench不支持。
Apache JMeter
JMeter是衡量Web應用程序性能的最受歡迎的開源工具之一。 JMeter是基于Java的應用程序, 不僅是Web服務器, 而且你可以將其用于PHP, Java。 ASP.net, SOAP, REST等
JMeter擁有不錯的友好GUI, 并且最新版本3.0需要Java 7或更高版本才能啟動該應用程序。如果你的目標是優化Web應用程序性能, 則必須嘗試JMeter。
wrk
wrk是另一個現代的性能評估工具, 可將負載加到你的Web服務器上, 并為你提供延遲, 每秒請求, 每秒傳輸等詳細信息。
使用wrk, 你可以指定運行帶有多個線程的負載測試。
讓我們舉一個例子, 對500個并發用戶和8個線程進行5分鐘的測試。
wrk –t8 –c500 -d300s http://localhost
Httpload
Httpload可以從文件中讀取多個URL, 也可以在命令參數中指定它。最新版本支持SSL / TLS, 這意味著你可以查詢啟用HTTPS(SSL)的網頁URL。
測試啟用SSL的URL時, 可以選擇指定密碼, 簡單的test命令如下所示。
httpload -cipher AES256-SHA -parallel 200 -seconds 120 URL_LIST.txt
為了更好地理解它, 上面將針對200個并發用戶運行測試2分鐘。
curl-loader
curl-loader用C編寫, 可以模擬應用程序負載, 它支持SSL / TLS。除了網頁測試外, 你還可以使用此開源工具在FTP服務器上執行加載。
你可以在單個批處理配置中創建包含HTTP, HTTPS, FTP和FTPS的測試計劃。
httperf
httperf是一種高性能工具, 專注于微觀和宏觀水平的基準測試。它支持HTTP / 1.1和SSL協議。
如果你期望并發用戶數, 并且希望測試Web服務器是否可以滿足一定數量的請求, 則可以使用以下命令。
httperf --server localhost --port 80 --num-conns 1000 --rate 100
上面的命令將以每秒100個請求的速度測試1000個HTTP請求。
Tsung
Tsung是一種多協議分布式壓力測試工具, 可以對HTTP, SOAP, PostgreSQL, LDAP, XAMP, MySQL服務器進行壓力測試。它支持HTTP / 1.0, HTTP / 1.1, 并且cookie被自動處理。
使用Tsung生成報告是可行的。
總結
我希望以上基準測試工具能使你對Web服務器的性能有所了解, 并幫助你確定最適合你的項目的工具。
總結
以上是生活随笔為你收集整理的如何测试web服务器性能,如何执行Web服务器性能基准测试?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle视图不能创建,ORACLEs
- 下一篇: 北京大学计算机系 丁主任,丁骋、李时新参