带有WebUI的HTTP Benchmark小工具你用过吗?

首先祝Gopher们周末愉快,今天给大家分享一篇关于HTTP压测工具的短文。

前两天在逛推特,无意中发现一个带有WebUI和终端展示的HTTP压测库plow[1] ,其实老早我就想找一个类似的库,终于被我发现了,哈哈。其实这种数据统计展示也可以在业务API中上报的Metrics相关的grafana监控面板上呈现出来。下面我简单介绍一下这个工具的使用。主要参考了一下readme,00。

plow介绍

plow 是采用 Golang 编写的一个 HTTP(S) 基准测试工具。内部采用了性能出色的fasthttp[2]而不是 Go 的默认net/http

plow是如何计算的呢,性能怎么样

这里主要受prometheus-普罗米修斯[3]启发是基于流的算法实现实时计算直方图和分位数,具有很低的内存和CPU消耗。因此,基准测试几乎没有额外的性能开销。

安装与使用

可以通过以下三种方式进行安装:

  • go get

$ go get -u github.com/six-ddc/plow
  • homebrew

$ brew install plow
  • Docker 安装

$ docker run --rm --net=host ghcr.io/six-ddc/plow
# docker run --rm -p 18888:18888 ghcr.io/six-ddc/plow

使用的话可以执行$ plow --help查看更多帮助信息,支持GET和POST请求。

$ plow --help
usage: plow [<flags>] <url>

A high-performance HTTP benchmarking tool with real-time web UI and terminal
displaying

Example:

  plow http://127.0.0.1:8080/ -c 20 -n 100000
  plow https://httpbin.org/post -c 20 -d 5m --body @file.json -T 'application/json' -m POST

Flags:
      --help                    Show context-sensitive help.
  -c, --concurrency=1           Number of connections to run concurrently
  -n, --requests=-1             Number of requests to run
  -d, --duration=DURATION       Duration of test, examples: -d 10s -d 3m
  -i, --interval=200ms          Print snapshot result every interval, use 0 to
                                print once at the end
      --seconds                 Use seconds as time unit to print
      --body=BODY               HTTP request body, if start the body with @, the
                                rest should be a filename to read
      --stream                  Specify whether to stream file specified by
                                '--body @file' using chunked encoding or to read
                                into memory
  -m, --method="GET"            HTTP method
  -H, --header=K:V ...          Custom HTTP headers
      --host=HOST               Host header
  -T, --content=CONTENT         Content-Type header
      --listen="0.0.0.0:18888"  Listen addr to serve Web UI
      --timeout=DURATION        Timeout for each http request
      --dial-timeout=DURATION   Timeout for dial addr
      --req-timeout=DURATION    Timeout for full request writing
      --resp-timeout=DURATION   Timeout for full response reading
      --socks5=ip:port          Socks5 proxy
      --version                 Show application version.

Args:
  <url>  request url

例子

下面主要展示下plow进行get请求压力测试的例子,这里压测图示采用官方的example,命令如下:

$ plow http://127.0.0.1:8080/hello -c 20 -d 15s -n 5000000

这里主要测试的是get请求本地接口:建立了20个连接,在15秒内请求了500w次,相信大家也看懂了这里,下面的flag还是解释一下吧。

  • -c 指定连接数(connections)

  • -n指定请求数(number)

  • -d 指定请求的时间(duration)

接下来看下下官方的example数据展示,左边是终端数据实时展示,右侧是127.0.0.1:18888的实时WebUI数据展示(延迟:最小延迟-平均延迟-最大延迟,每秒请求数)。

参考资料

[1] 

plow: https://github.com/six-ddc/plow

[2] 

fasthttp: https://github.com/valyala/fasthttp#http-client-comparison-with-nethttp

[3] 

prometheus-普罗米修斯: https://github.com/prometheus/client_golang


欢迎关注Go招聘公众号,获取更多精彩内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值