利用wrk工具压测腾讯CLB

可以做压测的工具有好多,ab、jmeter,此处选用wrk进行压测

环境

一台CLB实例(在腾讯云平台上创建)
四台RS服务器(后端提供web服务的机器,在腾讯云上创建CVM云主机)
两台压测客户端(在腾讯云上创建CVM云主机)
各个主机的带宽均为100Mbps

CLB实例如下:
这里写图片描述
四台RS服务器
这里写图片描述

两台压测客户端
这里写图片描述
这里写图片描述


一、先配置后端四台服务器

四台服务器均作如下操作,系统均为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     测试界面内容

确保可以访问

这里写图片描述

剩下的三台依次创建测试内容,分别为test02、test03、test04,用相同的域名www.example.com

这个需要修改本地计算机的hosts文件,确保单台nginx可以访问

二、创建CLB绑定主机

CLB需要配置监听器管理,如下
这里写图片描述
新建http监听器
这里写图片描述

这里写图片描述

这里写图片描述

创建完监听器后,绑定上面四台主机

这里写图片描述


这个时候将CLB的vip 与www.example.com对应关系写到本地计算机的hosts文件

140.143.51.59 www.example.com

本地计算机上访问http://www.example.com/test/,确保可以轮训

如下
这里写图片描述

这里写图片描述

这里写图片描述

三、配置压测客户端两台

一般压测端的机器配置需要比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.

输出信息如下

这里写图片描述

可以看到吞吐量Requests/sec为6w+,1914744个请求中有109个未成功,主机的带宽为14.62MB*8=116.96Mbps,带宽为100Mbps
其中 Non-2xx or 3xx responses这个参数不能大于200,否则需要重测

猜你喜欢

转载自blog.csdn.net/qq_36357820/article/details/80009273
今日推荐