打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Go每日一库之带WebUI的HTTP Benchmark
Go语言中文网 2021-07-10

以下文章来源于Go招聘 ,作者ironboxboy

今天给大家分享一篇关于HTTP压测工具的短文。

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

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


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
NovelAI 搭建教程
qBittorrent Enhanced nox手动安装
超详细!AI 绘画神器 Stable Diffusion 基础教程
手把手教学!AI真人图片和视频生成~
如何使用aria2及webui
Stable Diffusion攻略集(Stable Diffusion官方文档、kaggle notebook、webui资源帖)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服