zoukankan      html  css  js  c++  java
  • 解析wrk压测工具

    一.简介

    wrk是一款针对 Http 协议的基准测试工具,它能够在单机多核 CPU 的条件下,使用系统自带的高性能 I/O 机制,如 epoll,kqueue等,通过多线程和事件模式,对目标机器产生大量的负载。

    wrk是开源的, 代码在 github 上:https://github.com/wg/wrk

    优势

    1.轻量级性能测试工具
    2.安装简单
    3.学习曲线基本为0,几分钟就学会使用了
    4.基于系统自带的高性能I/O机制,如epoll,kqueue,利用异步的事件驱动框架,通过很少的线程就可以压出很大的并发量,例如几万、几十万,这是很多性能测试工具无法做到的。

    劣势

    wrk 目前仅支持单机压测,后续也不太可能支持多机器对目标机压测,因为它本身的定位,并不是用来取代 JMeter, LoadRunner 等专业的测试工具。

    二.格式及用法

    Usage: wrk <options> <url>                           
    
      Options:                                           
        -c, --connections <N>  Connections to keep open  
        -d, --duration    <T>  Duration of test          
        -t, --threads     <N>  Number of threads to use  
                                                         
        -s, --script      <S>  Load Lua script file      
        -H, --header      <H>  Add header to request     
            --latency          Print latency statistics  
            --timeout     <T>  Socket/request timeout    
        -v, --version          Print version details     
                                                    
      Numeric arguments may include a SI unit (1k, 1M, 1G)
      Time arguments may include a time unit (2s, 2m, 2h)
    

    翻译成中文:

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

    三.安装、使用和结果分析

    centos系统中的安装

    yum install -y openssl-devel git 
    git clone https://github.com/wg/wrk.git wrk
    cd wrk
    make
    # 将可执行文件移动到 /usr/local/bin 位置
    cp wrk /usr/local/bin
    # 输入wrk,如果有以下显示,则说明安装成功了
    Usage: wrk <options> <url>                            
      Options:                                            
        -c, --connections <N>  Connections to keep open   
        -d, --duration    <T>  Duration of test           
        -t, --threads     <N>  Number of threads to use   
                                                          
        -s, --script      <S>  Load Lua script file       
        -H, --header      <H>  Add header to request      
            --latency          Print latency statistics   
            --timeout     <T>  Socket/request timeout     
        -v, --version          Print version details      
                                                          
      Numeric arguments may include a SI unit (1k, 1M, 1G)
      Time arguments may include a time unit (2s, 2m, 2h)
    

    使用

    做一个简单的压测,分析下结果:

    wrk -t4 -c400 -d30s -T5s --latency https://www.baidu.com
    

    输出:

    Running 30s test @ https://www.baidu.com
      4 threads and 400 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.83s   852.06ms   4.99s    67.78%
        Req/Sec    35.22     27.99   180.00     77.91%
      Latency Distribution
         50%    2.60s 
         75%    3.41s 
         90%    4.20s 
         99%    4.58s 
      3118 requests in 30.07s, 31.32MB read
      Socket errors: connect 0, read 0, write 0, timeout 123
    Requests/sec:    103.69
    Transfer/sec:      1.04MB
    

    以上是使用4个线程400个连接,对百度首页进行了30秒的压测,并要求在压测结果中输出响应延迟信息。

    以下是解释压测结果:

    Running 30s test @ https://www.baidu.com(压测时间30s)
    
      4 threads and 400 connections(共4个测试线程,400个连接)
    
      Thread Stats   Avg      Stdev     Max   +/- Stdev
                  (平均值) (标准差)(最大值)(正负一个标准差所占比例)
        Latency     2.83s   852.06ms   4.99s    67.78%
        (延迟)
        Req/Sec    35.22     27.99   180.00     77.91%
        (处理中的请求数)
    
      Latency Distribution (延迟分布)
         50%    2.60s 
         75%    3.41s 
         90%    4.20s 
         99%    4.58s (99分位的延迟:99%的请求在4.58s以内)
      3118 requests in 30.07s, 31.32MB read(30.07秒内共处理完成了3118个请求,读取了31.32MB数据)
    Requests/sec:  103.69 (平均每秒处理完成59658.29个请求)
    Transfer/sec:      1.04MB (平均每秒读取数据22.79MB)
    
  • 相关阅读:
    【HDU 1007】Quoit Design
    【BZOJ 4516】【SDOI 2016】生成魔咒
    【SPOJ 1812】Longest Common Substring II
    NOI2014 全国互测Round2
    1231: [Usaco2008 Nov]mixup2 混乱的奶牛
    3529: [Sdoi2014]数表
    2693: jzptab
    2565: 最长双回文串
    1562: [NOI2009]变换序列
    1965: [Ahoi2005]SHUFFLE 洗牌
  • 原文地址:https://www.cnblogs.com/even160941/p/15625450.html
Copyright © 2011-2022 走看看