当前位置:网站首页>Introduction to wrk pressure test tool
Introduction to wrk pressure test tool
2022-06-28 22:05:00 【InfoQ】
What is? wrk
wrk The advantages of :
- Lightweight performance testing tool ;
- Simple installation ( relative Apache ab Come on );
- Learning curve is basically zero , I can learn how to use it in a few minutes ;
- High performance based on the system I/O Mechanism , Such as epoll, kqueue, Using asynchronous event driven framework , A large amount of concurrency can be squeezed out through a small number of threads ;
Inferiority :
wrk Installation
brew install wrk
git clone https:``//github.com/wg/wrk.git wrk``cd wrk``make``# Move executable to /usr/local/bin Location ``sudo cp wrk /usr/local/bin
wrk -t12 -c400 -d30s http:``//www.baidu.com
wrk Command parameter description
wrkwrk --helpwrk --help``Usage: wrk <options> <url> `` ``Options: `` ``-c, --connections <N> Connections to keep open Established and maintained with the server TCP Number of connections The total number of connections ( Number of connections processed per thread = Total connections / Number of threads )`` ``-d, --duration <T> Duration of test Measurement time `` ``-t, --threads <N> Number of threads to use How many threads are used for pressure testing `` ` ` ``-s, --script <S> Load Lua script file Appoint Lua Script path `` ``-H, --header <H> Add header to request For every one HTTP Request add HTTP head `` ``--latency Print latency statistics After pressure test , Print delay statistics `` ``--timeout <T> Socket/request timeout Timeout time `` ``-v, --version Print version details Print in use wrk Detailed version information for `` ` ` ``Numeric arguments may include a SI unit (1k, 1M, 1G)`` ``Time arguments may include a time unit (2s, 2m, 2h)<N> For digital parameters , Support international units (1k, 1M, 1G) <T> Represents time parameter , Time units supported (2s, 2m, 2h)
Test report
wrk -t12 -c400 -d30s --latency http:``//www.baidu.com
Running 30s test @ http:``//www.baidu.com ( Measurement time 30s)`` ``12 threads and 400 connections ( common 12 Test threads ,400 A connection )``( Average ) ( Standard deviation ) ( Maximum )( Proportion of plus or minus one standard deviation )`` ``Thread Stats Avg Stdev Max +/- Stdev`` ``Latency 386.32ms 380.75ms 2.00s 86.66% ( Delay `` ``Req/Sec 17.06 13.91 252.00 87.89% ( Requests per second `` ``Latency Distribution ( Delay distribution `` ``50% 218.31ms`` ``75% 520.60ms`` ``90% 955.08ms`` ``99% 1.93s`` ``4922 requests in 30.06s, 73.86MB read (30.06s Internal processing 4922 A request , Consumed flow 73.86MB)`` ``Socket errors: connect 0, read 0, write 0, timeout 311 ( Number of errors ``Requests/sec: 163.76 (QPS 163.76, That is, the average number of requests processed per second is 163.76)``Transfer/sec: 2.46MB ( Average traffic per second 2.46MB)
Use Lua Script for complex testing
--scriptwrk Yes Lua Script support
function setup(thread)
thread.addr - get or set the thread's server address``thread:get(name) - get the value of a global in the thread's env``thread:set(name, value) - set the value of a global in the thread's env``thread:stop() - stop the thread
function init(args)``function delay()``function request()``function response(status, headers, body)
init(args): Called by test thread , Only when entering the operation phase , Call once . Support starting from wrk In command , Get command line parameters ;
delay(): Calls before each request is sent , If you need to customize the delay time , You can set it in this method ;
request(): Used to generate requests , This method is called every time , So be careful not to do time-consuming operations in this method ;
response(status, headers, body): Called every time a response is received , To improve performance , If the method is not defined , that wrk No resolutionheadersandbody;
function done(summary, latency, requests)
done() Method will only be called once during the entire test , We can choose from the given parameters , Obtain pressure test results , Generate customized test reports .
wrk = {`` ``scheme = ``"http"``,`` ``host = ``"localhost"``,`` ``port = 8080,`` ``method = ``"GET"``,`` ``path = ``"/"``,`` ``headers = {},`` ``body = nil,`` ``thread = <userdata>,`` ``}
tablewrkwrk.fomat
wrk.lookup
wrk.connect
function wrk.format(method, path, headers, body)` ` ``wrk.format returns a HTTP request string containing the passed parameters`` ``merged with values from the wrk table.`` ``# According to parameters and global variables wrk, Generate a HTTP rquest character string .` `function wrk.lookup(host, service)` ` ``wrk.lookup returns a table containing all known addresses ``for` `the host`` ``and service pair. This corresponds to the POSIX getaddrinfo() function.`` ``# Given host and service(port/well known service name), Return all available server address information .` `function wrk.connect(addr)` ` ``wrk.connect returns true ``if` `the address can be connected to, otherwise`` ``it returns false. The address must be one returned from wrk.lookup().`` ``# Test whether the given server address information can successfully create a connection
Case study : adopt Lua Script pressure test example
wrk.method = ``"POST"``wrk.body = ``"foo=bar&baz=quux"``wrk.headers[``"Content-Type"``] = ``"application/x-www-form-urlencoded"
request = function()`` ``uid = math.random(1, 10000000)`` ``path = ``"/test?uid="` `.. uid`` ``return` `wrk.format(nil, path)``end
function delay()`` ``return` `10``end
token = nil``path = ``"/auth"` `request = function()`` ``return` `wrk.format(``"GET"``, path)``end` `response = function(status, headers, body)`` ``if` `not token and status == 200 then`` ``token = headers[``"X-Token"``]`` ``path = ``"/test"`` ``wrk.headers[``"X-Token"``] = token`` ``end``end
/auth/testinit = function(args)`` ``local r = {}`` ``r[1] = wrk.format(nil, ``"/?foo"``)`` ``r[2] = wrk.format(nil, ``"/?bar"``)`` ``r[3] = wrk.format(nil, ``"/?baz"``)` ` ``req = table.concat(r)``end` `request = function()`` ``return` `req``end
边栏推荐
- LeetCode116. 填充每个节点的下一个右侧节点指针
- LeetCode188. The best time to buy and sell stocks IV
- LeetCode1114. Print in sequence
- [Note: analog MOS integrated circuit] bandgap reference (basic principle + current mode + voltage mode circuit explanation)
- Which software is safer to open an account on and what is the account opening process?
- Biovendor free light chain( κ and λ) Test steps of ELISA Kit
- Constructing the three-dimensional anti penetration of the actual combat defense system
- The rogue downloader named by 315 is back
- Leetcode: expand a binary tree into a linked list_ one hundred and fourteen
- An artifact extracted from a well-known software and paid by a group of people
猜你喜欢

安全 创新 实践|海泰方圆受邀参加“数字时代的网信创新与价值共创”技术交流研讨会

接口测试流程
![[webapi] return dynamic list dynamic](/img/83/b0b36ddab6d74ccd89811cbb58d051.jpg)
[webapi] return dynamic list dynamic

postman简介与安装步骤
![Sword finger offer:[day 1 stack and queue (simple)] --- > stack containing min function](/img/16/2edfc478a56e5b5e7299621ac778c2.jpg)
Sword finger offer:[day 1 stack and queue (simple)] --- > stack containing min function
![[software test] 2022 national unified college enrollment examination](/img/9a/d76d7eb30a097d364fef28c2230e1a.png)
[software test] 2022 national unified college enrollment examination

17 `bs object Node name h3 Parent ` parents get parent node ancestor node

Alist+raidrive gives the computer a complete 8billion GB hard disk drive

Anti rabbit dylight 488 abbkine universal immunofluorescence (if) toolbox

直播预告|SQL也能玩转工业级机器学习?MLOps meetup V3带你一探究竟!
随机推荐
接口用例设计
Understanding web automated testing
LeetCode213. 打家劫舍II
#yyds干货盘点# 解决剑指offer: 连续子数组的最大和(二)
In one sentence, I will tell you the meaning of select 1, 2 and 3 in SQL injection, and explain the meaning of each part of SQL injection in detail
Web自动化工具选择
Akamai acquires linode
Definition and precautions of genuine St link/v2 j-link jtag/swd pin
LeetCode560. Subarray with and K
【激活函数】
Anti rabbit dylight 488 abbkine universal immunofluorescence (if) toolbox
Security dilemma of NFT liquidity agreement - Analysis of the hacked event of NFT loan agreement xcarnival
Construction and application of urban brain knowledge map
LeetCode116. Populate the next right node pointer for each node
Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!
Go cryptobin common encryption and decryption Libraries
How can the sports app keep the end-to-side background alive to make the sports record more complete?
硬件开发笔记(七): 硬件开发基本流程,制作一个USB转RS232的模块(六):创建0603封装并关联原理图元器件
Real time transformer: meituan's research on single image depth estimation
LeetCode:合并两个有序链表_21