关于Go语言命令行压力测试工具Wrk

藏色散人
藏色散人 转载
2021-06-01 15:06:46 2285浏览

下面由golang教程栏目给大家介绍Go语言 命令行压力测试工具Wrk,希望对需要的朋友有所帮助!

Go语言 命令行压力测试工具Wrk

下载

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

make

sudo cp -R wrk /usr/local/bin/wrk

查看版本号

wrk -v
使用方法: wrk <选项> <被测HTTP服务的URL>                            
  Options:                                            
    -c, --connections <N>  跟服务器建立并保持的TCP连接数量  
    -d, --duration    <T>  压测时间           
    -t, --threads     <N>  使用多少个线程进行压测   
                                                      
    -s, --script      <S>  指定Lua脚本路径       
    -H, --header      <H>  为每一个HTTP请求添加HTTP头      
        --latency          在压测结束后,打印延迟统计信息   
        --timeout     <T>  超时时间     
    -v, --version          打印正在使用的wrk的详细版本信息
                                                      
  <N>代表数字参数,支持国际单位 (1k, 1M, 1G)
  <T>代表时间参数,支持时间单位 (2s, 2m, 2h)

常用请求方式

wrk -t8 -c200 -d30s --latency "http://www.bing.com"

自定义请求 -s

wrk = {
    scheme  = "http",
    host    = "localhost",
    port    = nil,
    method  = "GET",
    path    = "//m.sbmmt.com/m/",
    headers = {},
    body    = nil,
    thread  = <userdata>
}

列子 先用postman测试之后 直接从post里面copy出来设置

wrk.method = "POST"
wrk.body   = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
wrk -d3s -c2 -s scripts/post.lua https://httpbin.org/get

以上就是关于Go语言命令行压力测试工具Wrk的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:segmentfault,如有侵犯,请联系admin@php.cn删除