zoukankan      html  css  js  c++  java
  • 性能压测工具-wrk

    一、简介:

         是一款针对协议的基准测试工具,它能够在单机多核的条件下,使用系统自带的高性能机制,通过多线程和事件模式,对目标机器产生大量的负载。
    • 优势
      • 轻量级性能测试工具
      • 安装使用简单
      • 基于系统自带的高性能I/O机制,如epoll,kqueue,利用异步的事件驱动框架,通过很少的线程就可以压出很大的并发
    • 劣势
      • wrk 目前仅支持单机压测,不是用来取代 JMeter, LoadRunner 等专业的测试工具。
     

    二、参数说明

    Usage: wrk <options> <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的详细版本     
                                                     
      Numeric arguments may include a SI unit (1k, 1M, 1G)
      Time arguments may include a time unit (2s, 2m, 2h)
    

    例如: 

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


    Running 30s test @ http://www.bing.com (压测时间30s) 8 threads and 200 connections (共8个测试线程,200个连接) Thread Stats Avg Stdev Max +/- Stdev (平均值) (标准差)(最大值)(正负一个标准差所占比例) Latency 46.67ms 215.38ms 1.67s 95.59% (延迟) Req/Sec 7.91k 1.15k 10.26k 70.77% (处理中的请求数) Latency Distribution (延迟分布) 50% 2.93ms 75% 3.78ms 90% 4.73ms 99% 1.35s (99分位的延迟) 1790465 requests in 30.01s, 684.08MB read (30.01秒内共处理完成了1790465个请求,读取了684.08MB数据) Requests/sec: 59658.29 (平均每秒处理完成59658.29个请求) Transfer/sec: 22.79MB (平均每秒读取数据22.79MB)

         wrk -t1 -c4 -d100s -T3s --script=post.lua --latency http://localhost:8080/xtopic/news

    post.lua脚本文件
    paramArr = {}
    falg = 0
    -- 初始化 
    function init(args)
        for line in io.lines("requestParams.txt") do //requestParams.txt 请求参数文件
           print(line)
           paramArr[falg] = line
           falg = falg+1
       end
    end
    -- 请求
    function request()
       local headers = { }
       headers['Content-Type'] = "application/json"
       body = paramArr[math.random(0,table.getn(paramArr))]
       return wrk.format("POST",nil,headers,body)
    end
    
    -- 响应
    function response(status,headers,body)
    
            if(status ~= 200)
                    then
                    print("response===error",status,body)
            else
                    print("response===success",status,body)
    
            end
    end
    

    三、wrk内置函数

              wrk中执行http请求的时候,调用lua分为3个阶段,setup,running,done,每个wrk线程中都有独立的脚本环境

  • 相关阅读:
    dwSun带你选Python的编辑器/IDE
    ubuntu中文乱码解决
    解决matplotlib中文显示
    1506.01186-Cyclical Learning Rates for Training Neural Networks
    1503.02531-Distilling the Knowledge in a Neural Network.md
    1804.03235-Large scale distributed neural network training through online distillation.md
    mysql导入太慢解决方法
    已某个时间单位(日月周年)来分割时间段
    阿里云邮件推送
    阿里云短信推送服务
  • 原文地址:https://www.cnblogs.com/Onlywjy/p/14638312.html
Copyright © 2011-2022 走看看