天天看點

利用wrk工具壓測騰訊CLB

可以做壓測的工具有好多,ab、jmeter,此處選用wrk進行壓測

環境

一台CLB執行個體(在騰訊雲平台上建立)

四台RS伺服器(後端提供web服務的機器,在騰訊雲上建立CVM雲主機)

兩台壓測用戶端(在騰訊雲上建立CVM雲主機)

各個主機的帶寬均為100Mbps

CLB執行個體如下:

利用wrk工具壓測騰訊CLB

四台RS伺服器

利用wrk工具壓測騰訊CLB

兩台壓測用戶端

利用wrk工具壓測騰訊CLB
利用wrk工具壓測騰訊CLB

一、先配置後端四台伺服器

四台伺服器均作如下操作,系統均為centos6.8 64位

yum install -y nginx
           

安裝完之後需要修改default.conf檔案,否則不能啟動nginx服務

vi /etc/nginx/conf.d/default.conf
#
# The default server
#

server {
listen       80;                   監聽端口為80
server_name  www.example.com;      做虛拟主機
#listen       [::]:80 default_server;  注釋掉此行
server_name  _;
root         /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}

error_page 404 /404.html;
    location = /40x.html {
} 
           

重新開機nginx服務

service nginx restart
           

接着做如下

/usr/share/nginx/html/為nginx 的根目錄

在此目錄下建立test目錄

mkdir test
vi index.html   測試界面
test01     測試界面内容
           

確定可以通路

利用wrk工具壓測騰訊CLB

剩下的三台依次建立測試内容,分别為test02、test03、test04,用相同的域名www.example.com

這個需要修改本地計算機的hosts檔案,確定單台nginx可以通路

二、建立CLB綁定主機

CLB需要配置監聽器管理,如下

利用wrk工具壓測騰訊CLB

建立http監聽器

利用wrk工具壓測騰訊CLB
利用wrk工具壓測騰訊CLB
利用wrk工具壓測騰訊CLB

建立完監聽器後,綁定上面四台主機

利用wrk工具壓測騰訊CLB

這個時候将CLB的vip 與www.example.com對應關系寫到本地計算機的hosts檔案

140.143.51.59 www.example.com
           

本地計算機上通路http://www.example.com/test/,確定可以輪訓

如下

利用wrk工具壓測騰訊CLB
利用wrk工具壓測騰訊CLB
利用wrk工具壓測騰訊CLB
利用wrk工具壓測騰訊CLB

三、配置壓測用戶端兩台

一般壓測端的機器配置需要比CLB的那四台要高

兩台均作如下操作

安裝wrk

https://github.com/wg/wrk/wiki/Installing-Wrk-on-Linux(安裝文檔)

sudo yum groupinstall 'Development Tools'
sudo yum install -y openssl-devel git 
git clone https://github.com/wg/wrk.git wrk #這一步會報錯,解決如下yum update -y nss curl libcurl 

cd wrk
make
# move the executable to somewhere in your PATH
sudo cp wrk /somewhere/in/your/PATH
           

裝完wrk之後,需要在壓測用戶端編寫hosts檔案

140.143.51.59(CLB的vip) www.example.com
           

進行測壓,兩台同時進行

cd wrk
./wrk -t32 -c10000 -d30s  http://www.example.com/test/
           

This runs a benchmark for 30 seconds, using 32 threads, and keeping 400 HTTP connections open.

以下是wrk的參數

-c, --connections: total number of HTTP connections to keep open with
                   each thread handling N = connections/threads

-d, --duration:    duration of the test, e.g. 2s, 2m, 2h

-t, --threads:     total number of threads to use

-s, --script:      LuaJIT script, see SCRIPTING

-H, --header:      HTTP header to add to request, e.g. "User-Agent: wrk"

    --latency:     print detailed latency statistics

    --timeout:     record a timeout if a response is not received within
                   this amount of time.
           

輸出資訊如下

利用wrk工具壓測騰訊CLB

Latency: 可以了解為響應時間, 有平均值, 标準偏差, 最大值, 正負一個标準差占比.

Req/Sec: 每個線程每秒鐘的完成的請求數, 同樣有平均值, 标準偏差, 最大值, 正負一個标準差占比.

一般我們來說我們主要關注平均值和最大值. 标準差如果太大說明樣本本身離散程度比較高. 有可能系統性能波動很大.

可以看到吞吐量Requests/sec為6w+,1914744個請求中有109個未成功,主機的帶寬為14.62MB*8=116.96Mbps,帶寬為100Mbps

其中 Non-2xx or 3xx responses這個參數不能大于200,否則需要重測