软件性能测试工具

1.Vegeta:

原文链接: https://juejin.cn/post/6844903655200522248

1.什么是 Vegeta
Vegeta 是一个用 Go 语言编写的多功能的 HTTP 负载测试工具,它提供了命令行工具和一个开发库。 
官方地址:https://github.com/tsenart/vegeta

2.安装 Vegeta
Vegeta 安装非常简单,由于 Go 语言良好的跨平台性,可以直接下载官方的预编译版本后开箱即用。
预编译版本
这里以 Linux 版本为例:
$ wget https://github.com/tsenart/vegeta/releases/download/v7.0.3/vegeta-7.0.3-linux-amd64.tar.gz
$ tar xzvf vegeta-7.0.3-linux-amd64.tar.gz
$ mv vegeta  /usr/local/bin/复制代码


3.使用标准输入进行压测并生成报告
$ echo "GET http://10.20.192.250" | vegeta attack -rate=50 -connections=1 -duration=1s | tee results.bin | vegeta report
Requests      [total, rate]            50, 51.02
Duration      [total, attack, wait]    37.41975091s, 979.999689ms, 36.439751221s
Latencies     [mean, 50, 95, 99, max]  33.816664905s, 35.021110945s, 37.058121168s, 37.204824958s, 37.319751221s
Bytes In      [total, mean]            9505000, 190100.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:50


4.使用目标文件的内容进行压测,创建 target.txt 文件,内容如下:
$ vim target.txt
GET http://10.20.192.250/
GET http://10.20.192.250/posts/19779.html
GET http://10.20.192.250/show.php

5.使用 Vegeta 进行压测:
$ vegeta attack -targets="target.txt" -rate=10 -duration=2s  > results.bin

6.自定义目标文件
除了前面定义的最简单 HTTP GET 请求外,你还可以定义下面这些更灵活更复杂的 HTTP 请求:

1. 自定义请求头
GET http://user:password@10.20.192.250:80/path/to
X-Account-ID: 8675309

DELETE http://10.20.192.250:80/path/to/remove
Confirmation-Token: 90215
Authorization: Token DEADBEEF

2. 自定义请求的主体
POST http://10.20.192.250:80/things
@/path/to/newthing.json

PATCH http://hi-linux.com:80/thing/71988591
@/path/to/thing-71988591.json

3. 自定义请求头和请求主体
POST http://10.20.192.250:80/things
X-Account-ID: 99
@/path/to/newthing.json

7.生成压测报告:
生成 JSON 格式的压测报告
$ vegeta report -inputs=results.bin -reporter=json > metrics.json

生成基于 Dygraphs 的 HTML 5 压测报告
$ cat results.bin | vegeta report -reporter=plot > plot.html


计算并输出一个基于文本的直方图
$ cat results.bin | vegeta report -reporter="hist[0,2ms,4ms,6ms]"
Bucket         #     %       Histogram
[0,     2ms]   6007  32.65%  ########################
[2ms,   4ms]   5505  29.92%  ######################
[4ms,   6ms]   2117  11.51%  ########
[6ms,   +Inf]  4771  25.93%  ##################

8.生成实时图形压测报告
如果您是 iTerm 用户,可以使用 jaggr 将 Vegeta 与 jplot 整合在一起并在终端上实时绘制压测报告。要实现这个功能你首先需要先安装 jaggr 和 jplot:
1. 安装 jaggr
$ yum install rs/tap/jaggr

# 源代码安装
$ go get -u github.com/rs/jaggr
2. 安装 jplot
$ yum install rs/tap/jplot

# 源代码安装
go get -u github.com/rs/jplot
安装完 jaggr 和 jplot 后,其次你需要在 iTerm 中执行以下命令:

$ echo 'GET http://www.hi-linux.com' | 
vegeta attack -rate 50 -duration 5m | vegeta dump | 
jaggr @count=rps 
hist[100,200,300,400,500]:code 
p25,p50,p95:latency 
sum:bytes_in 
sum:bytes_out | 
jplot rps+code.hist.100+code.hist.200+code.hist.300+code.hist.400+code.hist.500 
latency.p95+latency.p50+latency.p25 
bytes_in.sum+bytes_out.sum


9.分布式压力测试
当进行大规模负载测试时,通常由于受限于 Vegeta 自身机器的性能瓶颈(比如:打开的文件数,内存大小,CPU 和 网络带宽)限制而无法达到预期结果。 这时分布式的使用 Vegeta 可以很好的解决这个问题,实现类似功能的工具很多,比如功能强大的 Ansible。这里我们使用 Pdsh 来实现:

$ pdsh -b -w '10.0.1.1,10.0.2.1,10.0.3.1' 
    'echo "GET http://target/" | vegeta attack -rate=20000 -duration=60s > result.bin'
Pdsh 的全称是 (Parallel Distributed Shell),Pdsh 可并行的执行对目标主机的操作,很方便的批量执行命令和分发任务。Pdsh 还支持交互模式,当要执行的命令不确定时,可直接进入 Pdsh命令行,非常方便。

完成前面的命令后,我们就可以通过 Shell 脚本将结果文件收集到的一起供后面生成报表时使用。

$ for machine in "10.0.1.1 10.0.2.1 10.0.3.1"; do
    scp $machine:~/result.bin $machine.bin &
  done
  
最后我们可以通过 vegeta report 命令生成此次压测的报表。vegeta report 命令可一次性读取使用逗号分隔的多个结果文件并生成报告,默认通过时间戳进行排序。

$ vegeta report -inputs="10.0.1.1.bin,10.0.2.1.bin,10.0.3.1.bin"
Requests      [total, rate]         3600000, 60000.00
Latencies     [mean, 95, 99, max]   223.340085ms, 326.913687ms, 416.537743ms, 7.788103259s
Bytes In      [total, mean]         3714690, 3095.57
Bytes Out     [total, mean]         0, 0.00
Success       [ratio]               100.0%
Status Codes  [code:count]          200:3600000


其它相关:
如果你觉得命令行下使用 Vegeta 比较复杂的话,你还可以使用 Alex 项目。Alex 是一个基于 Vegeta Library 和 Boom 封装的压力测试 Web UI,Vegeta 提供稳定的 QPS 压力源,Boom 提供稳定的并发数压力源。

项目地址:https://github.com/ireaderlab/alex

 2.Siege:

文章来源:
https://mp.weixin.qq.com/s?__biz=MzI3MTI2NzkxMA==&mid=2247484487&idx=1&sn=b52414cd48edd337800c0a004dda8f5a&chksm=eac5256eddb2ac78ddbbeb4f756bc0badd3040b44884f5c270fa990713d941d28c2c87b16184&scene=178&cur_album_id=1342632926051205120#rd

前言:
Siege是一款开源的压力测试工具,设计用于评估WEB应用在压力下的承受能力。 可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。 Siege可以从您选择的预置列表中请求随机的URL。所以siege可用于仿真用户请求负载,而ab则不能。但不要使用siege来执行最高性能基准调校测试,这方面ab就准确很多。 Siege官网:http://www.joedog.org/ 一、安装 编译安装 wget http://www.joedog.org/pub/siege/siege-latest.tar.gz tar -zxvf siege-latest.tar.gz cd siege-2.72/ ./configure make make install 通过包安装 yum install siege 二、用法举例 siege -c 300 -r 100 -f url.txt 说明:-c是并发量,-r是重复次数。url.txt就是一个文本文件,里面是要测试的url,url.txt每行都是一个url。 urls.txt文件是很多行待测试URL的列表以换行符断开,格式为: [protocol://]host.domain.com[:port][path/to/file] url.txt内容: http://192.168.80.166/01.jpg http://192.168.80.166/02.jpg http://192.168.80.166/03.jpg http://192.168.80.166/04.jpg http://192.168.80.166/05.jpg http://192.168.80.166/06.jpg 结果说明: ** SIEGE 2.72 ** Preparing 10 concurrent users for battle. The server is now under siege.. done. Transactions: 300 hits #已完成的事务总署 Availability: 100.00 % #完成的成功率 Elapsed time: 0.08 secs #总共使用的时间 Data transferred: 0.94 MB #响应中数据的总大小 Response time: 0.00 secs #显示网络连接的速度 Transaction rate: 3750.00 trans/sec #平均每秒完成的事务数 Throughput: 11.79 MB/sec #平均每秒传送的数据量 Concurrency: 8.50 #实际最高并发链接数 Successful transactions: 300 #成功处理的次数 Failed transactions: 0 #失败处理的次数 Longest transaction: 0.01 #最长事务处理的时间 Shortest transaction: 0.00 #最短事务处理时间 三、常用的siege命令举例 200个并发对www.google.com发送请求100次 siege -c 200 -r 100 http://www.google.com 在urls.txt中列出所有的网址 siege -c 200 -r 100 -f urls.txt 随机选取urls.txt中列出所有的网址 siege -c 200 -r 100 -f urls.txt -i delay=0,更准确的压力测试,而不是功能测试 siege -c 200 -r 100 -f urls.txt -i -b 指定http请求头 文档类型 siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b 四、Siege使用的一些总结 发送post请求时,url格式为:http://www.xxxx.com/ POST p1=v1&p2=v2 如果url中含有空格和中文,要先进行url编码,否则siege发送的请求url不准确 siege自身感觉也是有瓶颈的,并发数最大也就1000,再提高就会报下面这样的错误 [error] socket: unable to connect sock.c:222: Operation already in progress socket: connection timed out 这样最终导致测试结果怎么都没法超过2W每秒的请求,所以就把siege -c 1000 -r 100 -i -b -f url.txt 放到shell中并发执行 #!/bin/bash user_agent="Siege 1.0" siege_rc="siege.rc" concurrent=150 repet=200 siege_single_urls="singleurl.txt" siege_prefix_urls="prefixurl.txt" for i in {1..10} do siege -c $concurrent -r $repet -i -b -f $siege_single_urls -R $siege_rc -A "$user_agent" &; done

 3.gohttpbench:

https://github.com/parkghost/gohttpbench/

a.install Go into your environment

  https://www.cnblogs.com/nickchou/p/10934025.html

b.download and build Go-HttpBench

  go get github.com/parkghost/gohttpbench
  go build -o gb github.com/parkghost/gohttpbench

c.使用:

gb -c 100 -n 100000 -k http://localhost/10k.dat

4.ab:

a.安装ab:

yum -y install httpd-tools

b.使用ab:

 ab -c 10 -n 100 http://www.myvick.cn/index.php

5.wrk:

a.安装git:

yum install git -y
b.下载源码:

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

c.安装gcc:

yum -y install gcc

d.编译:
cd wrk

make

e.软连接:

ln -s /home/admin/wrk/wrk /usr/local/bin

f.测试:
./wrk -c 1 -t 1 -d 1 http://www.baidu.com

 其它:

Jmeter与LoadRunner:

http://www.51testing.com/html/04/category-catid-204.html

请尊重笔者的劳动成果哦,转载请说明出处哦
原文地址:https://www.cnblogs.com/gufengchen/p/14955225.html