HTTPS压测工具wrk

一、预先安装需求项

为了安装顺利,不受权限的限制,首先可以把用户切换为root用户
# su + 输入root用户对应的密码
1.1 安装支持后续操作的一些组件

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc

1.2 安装编译套件
 

yum install gcc perl-ExtUtils-MakeMaker


 

二、安装or升级版本管理工具git

2.1 查看git版本
 

git --version


若libiconv字符集转换库没安装而出现错误:error: /utf8.c:463: undefined reference to 'libiconv'
解决方案:依次执行如下命令(无以上error则略过)

# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

# tar zxvf libiconv-1.14.tar.gz

# cd libiconv-1.14

# ./configure --prefix=/usr/local/libiconv

# make && make install

2.2 卸载旧版本git
在CentOS6.3系统环境下,如果以上查询的版本比较早(如:1.7.1版本),对后续的安装wrk会受到阻碍,故需升级git到新版本(如:2.2.1版本)
卸载旧版本的目录为:
 

yum remove git

2.3 安装新版本git
1)下载git 2.2.1进行编译安装;2)将git添加到环境变量

# wget https://github.com/git/git/archive/v2.2.1.tar.gz

# tar -zxvf v2.2.1

# cd git-2.2.1

# make configure

# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv

# make all doc

# make install install-doc install-html

# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc

# source /etc/bashrc


再次查看安装新版本git后的效果:

git --version


 

三、正式安装wrk

切换到src目录,再次检验是否安装git

 
  1. # cd /usr/local/src

  2. # yum install git -y


3.1 克隆wrk安装文件到本地 

# git clone https://github.com/wg/wrk.git


3.2 编译wrk文件

 cd wrk

# make


若出现错误:xmlto: command not found,可以尝试重新安装xmlto:# yum -y install xmlto
3.3 创建软链接到指定目录

# ln -s /usr/local/src/wrk/wrk /usr/local/bin


3.4 检验wrk是否安装成功
 

# wrk
 
[root@instance-lnjc135w wrk]# wrk

Usage: wrk <options> <url>

Options:

-c, --connections <N> Connections to keep open

-d, --duration <T> Duration of test

-t, --threads <N> Number of threads to use


-s, --script <S> Load Lua script file

-H, --header <H> Add header to request

--latency Print latency statistics

--timeout <T> Socket/request timeout

-v, --version Print version details


Numeric arguments may include a SI unit (1k, 1M, 1G)

Time arguments may include a time unit (2s, 2m, 2h)

四、wrk性能测试

4.1 配置待测网站的IP指向到内网
根据测试环境的要求,进行环境配置,比如有的网站不允许在外网正式环境进行压测,就需要配置一个指向内网的环境进行测试
打开hosts编辑器
# vim /etc/hosts
配置当前环境的hosts,格式为:

# IP1 url1

# IP2 url2

...

# IPx urlx

ESC键从编辑模式切换到正常模式,然后输入:wq保存并退出

4.2 测试http协议网站的性能

[root@localhost /]# wrk -t2 -c10 -d15 --latency http://www.baidu.com

Running 15s test @ http://www.baidu.com

2 threads and 10 connections

Thread Stats Avg Stdev Max +/- Stdev

Latency 35.64ms 1.31ms 48.59ms 79.38%

Req/Sec 138.40 13.52 151.00 89.00%

Latency Distribution

50% 35.50ms

75% 36.13ms

90% 37.09ms

99% 40.33ms

4151 requests in 15.05s, 60.83MB read

Socket errors: connect 0, read 29, write 0, timeout 0

Requests/sec: 275.72

Transfer/sec: 4.04MB

4.3 wrk参数含义
1)语法中的参数

-t:需要模拟的线程数

-c:需要模拟的连接数

-d:测试的持续时间

--timeout:超时的时间

--latency:显示延迟统计

2)结果显示的指标

Latency:响应时间

Req/Sec:每个线程每秒钟的完成的请求数

Avg:平均

Max:最大

Stdev:标准差

命令的使用

建立20个TCP连接,使用两个线程,用时2分钟,对http://192.168.100.1:80/manage进行压测。

   

执行结果

./wrk -c 20 -t 2 -d 10s http://192.168.100.1:80/manage
Running 10s test @ http://192.168.100.1:80/manage
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   830.07ms   79.77ms   1.05s    68.97%
    Req/Sec    15.77     11.41    50.00     69.09%
  232 requests in 10.04s, 225.66KB read    (10.04s处理了232个请求数,读取了60.30KB的数据)
Requests/sec:     23.11    一秒完成请求数23.11次
Transfer/sec:     22.48KB      每秒读取22.48KB

也可以发送POST请求进行压测

wrk -c 20 -t 2 -d 10 -H "host: dream.com" --script=post.txt http://10.XX.XX.XX:80/manage --latency --timeout 1s

   

 

post.txt

wrk.method = "POST"

   

wrk.body = "x=1&y=2"

   

wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"

   

解析同上。

发布了264 篇原创文章 · 获赞 46 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/qq_27229113/article/details/103202537