当前位置:网站首页>Detailed installation and use of performance test tool wrk
Detailed installation and use of performance test tool wrk
2022-06-24 21:59:00 【Two black】
It is suggested to use FastApi or Flask etc. Web The server-side framework builds a local HTTP service .
wrk brief introduction
wrk Is a HTTP Protocol benchmarking tools . Benchmarking is a performance testing method , It designs scientific test methods 、 Test tools and test systems , Realize the quantitative and comparable test of a certain performance index of a class of test objects .
GitHub Address :https://github.com/wg/wrk
install
Mac Use it directly HomeBrew Installation :
$ brew install wrk
Command line options
Enter... On the command line wrk Look at the command line options :
$ wrk
Usage: wrk <options> <url>
Options:
-c, --connections <N> Connections to keep open
# Set total http Number of concurrent connections
-d, --duration <T> Duration of test
# Set test duration
-t, --threads <N> Number of threads to use
# Set the number of threads opened ( Cannot be greater than the set number of concurrent requests )
-s, --script <S> Load Lua script file
# Load the specified Lua Script
-H, --header <H> Add header to request
# add to http Request header
--latency Print latency statistics
# Print delay statistics ( It is recommended to enable )
--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)
Basic example
GET request :
$ wrk -c100 -t10 -d10s --latency http://localhost:5000/test_get
# 100 Request points 10 Thread pressure 10 second
Console output :
Running 10s test @ http://localhost:5000/test_get
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 201.71ms 58.06ms 451.62ms 79.16%
Req/Sec 27.94 10.18 70.00 73.70%
Latency Distribution
50% 196.82ms
75% 228.07ms
90% 261.79ms
99% 394.08ms
2817 requests in 10.10s, 473.18KB read
Requests/sec: 278.94
Transfer/sec: 46.86KB
POST request :
$ wrk -c100 -t10 -d10s -s test_post.lua --latency http://localhost:5000/test_post
# Use test_post.lua Script
Lua Script :
wrk.method = "POST"
wrk.headers["Content-Type"] = "application/json"
wrk.body = '{
"k1":1,"k2":2}'
Console output :
Running 10s test @ http://localhost:5000/test_post
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 188.49ms 60.76ms 352.02ms 67.50%
Req/Sec 38.35 23.71 101.00 67.22%
Latency Distribution
50% 182.22ms
75% 230.92ms
90% 272.66ms
99% 325.02ms
3665 requests in 10.10s, 604.87KB read
Requests/sec: 362.77
Transfer/sec: 59.87KB
notes :GET Requests can also use Lua Script .
Advanced usage
Global variables
Lua The global variables of the script during the pressure test (tabel)wrk.
Global variables :
wrk = {
scheme = "http",
host = "localhost",
port = nil,
method = "GET",
path = "/",
headers = {
},
body = nil,
thread = <userdata>,
}
The global method :
function wrk.format(method, path, headers, body)
--[[
wrk.format Method returns a HTTP The requested string , Contains the passed in parameters and wrk A combination of the values of variables .
]]--
function wrk.lookup(host, service)
--[[
wrk.lookup Method returns a containing all known addresses of the host table And service pair , This corresponds to POSIX Of getaddrinfo() Method
]]--
-- host: A host name or address string (IPv4 A dotted decimal string or IPv6 Of 16 Base string )
-- service: The service name can be a decimal port number , It can also be a defined service name , Such as ftp、http etc.
function wrk.connect(addr)
--[[
Judge addr Is it possible to connect , Returns a Boolean value .addr Must be a wrk.lookup() Return value of method .
]]--
Lua Life cycle hooks for scripts
Start-up phase (Setup): The start-up phase begins with the request target IP When the address has been resolved and all threads have been initialized but have not been started .
function setup(thread)
--[[
Implement... In script file setup Method ,wrk Will be at the target IP This method is called when the test thread has been parsed and initialized but has not been started .
wrk Will be called once for each test thread setup Method , And pass in the object representing the test thread thread As a parameter .
setup Method thread object , pick up information 、 Store information 、 Even shut down the thread .
setup Method is executed only once per thread .
thread The object provides 1 Attributes ,3 A way :
thread.addr Get or set the server address of the thread
thread:get(name) Get thread global variables
thread:set(name, value) Set thread global variables
thread:stop() Thread termination
]]--
Operation phase (Running): The operation phase begins with the init Method , Then it is called once in each request cycle request and response Method .
function init(args)
-- Each thread calls only 1 Time ,args Used to obtain all other command parameters passed in from the command line of the current script , for example --env=pre
function delay()
-- Call before each request 1 Time , stay request Call before method , Unit is ms
function request()
-- Call before each request 1 Time , Returns a containing HTTP The requested string ,wrk Will be initiated according to the contents of the string HTTP request .
-- It is usually called in this method wrk.format() Generate HTTP Request string .
function response(status, headers, body)
-- Call each time the request returns 1 Time ,wrk By passing in HTTP Response code , Response head , The response body calls .
Closing phase (Done):
function done(summary, latency, requests)
--[[
done Method to receive a containing the test result data table Variable summary And two representing the delay time of each request and the delay time of each thread respectively QPS The statistical object of . The unit of duration and delay time is ms.
Only is called during the entire test 1 Time .
summary = {
duration = N, -- Run duration , Unit is ms
requests = N, -- Requests completed in total
bytes = N, -- Total amount of data received
errors = {
connect = N, -- socket Total connection failures
read = N, -- socket Total connection read failures
write = N, -- socket Total connection write failures
status = N, -- total HTTP status codes > 399
timeout = N -- total request timeouts
}
}
latency.min -- minimum delay
latency.max -- Max Delay
latency.mean -- Average delay
latency.stdev -- Delay standard deviation
latency:percentile(99.0) -- 99th percentile value
latency(i) -- raw value and count
]]--
Call procedure example
Command line statements :
$ wrk -c1 -t1 -d1s -s test_lua.lua http://localhost:5000
Lua Script :
#!/usr/local/bin/lua
wrk.body = '{
"k1":666}'
path = "/test_post"
function setup(thread)
print(" call setup()")
print(thread.addr)
end
function init(args)
print(" call init()")
end
function delay()
print(" call delay() wait for 500 ms")
return 500
end
function request()
print(" call resquest()")
return wrk.format("POST", path)
end
function response(status, headers, body)
print(" call response()")
if (status == 200)
then
path = "/test_get?k1=" .. body
end
end
function done(summary, latency, requests)
print(" call done()")
end
Console output :
call setup()
127.0.0.1:5000
call init()
call resquest()
Running 1s test @ http://localhost:5000
1 threads and 1 connections
call delay() wait for 500 ms
call resquest()
call response()
call delay() wait for 500 ms
call resquest()
call response()
call delay() wait for 500 ms
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.08ms 135.06us 1.17ms 100.00%
Req/Sec 1.50 0.71 2.00 100.00%
2 requests in 1.01s, 525.00B read
Non-2xx or 3xx responses: 1
Requests/sec: 1.98
Transfer/sec: 519.09B
call done()
HTTP Request log :
127.0.0.1 - - [15/Nov/2019 11:10:02] "POST /test_post HTTP/1.1" 200 -
127.0.0.1 - - [15/Nov/2019 11:10:03] "POST /test_get?k1={"k1":666} HTTP/1.1" 405 -
Learning resource sharing
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it 
These materials , For those who want to engage in 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! The above information can be shared , Just click below to enter the group .
边栏推荐
- Practice of hierarchical management based on kubesphere
- 降低pip到指定版本(通過PyCharm昇級pip,在降低到原來版本)
- 架构实战营 第 6 期 毕业设计
- Introduce the overall process of bootloader, PM, kernel and system startup
- Byte software testing basin friends, you can change jobs. Is this still the byte you are thinking about?
- leetcode_ 1470_ 2021.10.12
- socket(1)
- 基于 KubeSphere 的分级管理实践
- Several schemes of traffic exposure in kubernetes cluster
- Mysql 通过表明获取字段以及注释
猜你喜欢
![[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture](/img/b5/23e3aed317ca262ebd8ff4579a41a9.png)
[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture

机器学习:线性回归

Blender FAQs

A deep learning model for urban traffic flow prediction with traffic events mined from twitter

Interviewer: you said you are proficient in redis. Have you seen the persistent configuration?
![[notes of Wu Enda] convolutional neural network](/img/19/2cac17010c29cbd5ba245de105d6c1.png)
[notes of Wu Enda] convolutional neural network
![[notes of Wu Enda] multivariable linear regression](/img/b1/60a702aaca58b0afa57ac2f552dabf.png)
[notes of Wu Enda] multivariable linear regression

Byte software testing basin friends, you can change jobs. Is this still the byte you are thinking about?

Guava中这些Map的骚操作,让我的代码量减少了50%

多路转接select
随机推荐
Suspend component and asynchronous component
socket(1)
如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
基于 KubeSphere 的分级管理实践
SAP接口debug设置外部断点
力扣每日一题-第25天-496.下一个更大元素Ⅰ
性能测试工具wrk安装使用详解
应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
socket(2)
心楼:华为运动健康的七年筑造之旅
【无标题】
leetcode1720_ 2021-10-14
【论】Deep learning in the COVID-19 epidemic: A deep model for urban traffic revitalization index
TKKC round#3
leetcode:1504. 统计全 1 子矩形的个数
【吴恩达笔记】多变量线性回归
Minimum spanning tree based on Kruskal
Blender FAQs
降低pip到指定版本(通过cmp升级pip,在降低到原来版本)
These map operations in guava have reduced my code by 50%