当前位置:网站首页>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
边栏推荐
- 什么是接口?什么是接口测试?
- [linq] execute SQL like in statements using EF to LINQ
- [Note: analog MOS integrated circuit] bandgap reference (basic principle + current mode + voltage mode circuit explanation)
- 精通数据分析能力,收入翻倍?什么才是最强竞争力
- 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
- LeetCode560. 和为K的子数组
- 城市大脑知识图谱构建及应用研究
- LeetCode116. Populate the next right node pointer for each node
- Leetcode56. consolidation interval
- QJsonObject的使用示例
猜你喜欢
![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

rosdep update 使用小鱼fishros解决ros1/ros2问题 2022

Smarca2 antibody study: abnova smarca2 monoclonal antibody protocol

17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点

The rogue downloader named by 315 is back

10、标准I/O输入输出重定向及管道

BOE was brilliant for the Winter Olympics, but revealed another Chinese technology enterprise dominating the world

PHP login problem

Microsoft's exclusive payment function has also been perfectly unlocked

Query rewriting for opengauss kernel analysis
随机推荐
BOE was brilliant for the Winter Olympics, but revealed another Chinese technology enterprise dominating the world
Google search is dying | DKB
LeetCode986. Intersection of interval lists
Building web automation environment
Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!
LeetCode123. 买卖股票的最佳时机III
电商秒杀系统架构设计
Lua source code analysis: 1 Lua variable type mutability is implemented in C code.
E-commerce is popular, how to improve the store conversion rate?
Leetcode: merge two ordered linked lists_ twenty-one
How to analyze the relationship between enterprise digital transformation and data asset management?
Akamai acquires linode
PHP login problem
17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
Sword finger offer:[day 2 linked list (simple)] --- > reverse linked list
接口用例设计
Proficient in data analysis, double the income? What is the strongest competitiveness
Sword finger offer:[day 1 stack and queue (simple)] --- > use two stacks to realize the queue
为什么要使用 Rust 语言?
[linq] execute SQL like in statements using EF to LINQ