Lua script in wrk (GO)

Source: Internet
Author: User

Reprint Address: Http://www.tuicool.com/articles/IFjIJjU

The wrk is a modern HTTP test tool that provides the functionality of the Lua script to differentiate each request or part of the request.

When executing an HTTP request in WRK, the call to Lua is divided into 3 stages, setup,running,done, with a separate scripting environment for each WRK thread.

Global properties of WRK
WRK ={Scheme="http", host="localhost", Port=Nil, Method="GET", Path="/", Headers={}, Body=Nil, Thread= <userdata>,}

A global approach to WRK
-- A string that generates the entire request, for example: return -- get/http/1.1 -- Host:tool.lu function Wrk.format (method, path, headers, body) -- get the IP and port of the domain name, return to table, for example: Return ' {127.0.0.1:80} ' function Wrk.lookup (host, service) -- determine if addr can connect, for example: ' 127.0.0.1:80 ', returns TRUE or false function wrk.connect (addr)

Setup phase

Setup is created before the thread is started.

function Setup (thread) -- Thread provides 1 properties, 3 methods -- thread.addr Set the IP that the request needs to be hit -- thread:get (name) gets the thread global variable -- thread:set (name, value) sets the thread global variable -- thread:stop () terminating thread

Running stage
function init (args) -- Each thread is called only 1 times, and args is used to get the arguments passed in on the command line, such as--env=pre function delay () -- Each thread is called multiple times, and the delay before the next request is sent, in units of Ms function request () -- Each thread is called multiple times, returning an HTTP request function Response (status, headers, body) -- Each thread is called multiple times, returning an HTTP response

Done Stage

Can be used to customize a result report, which is performed only once during the entire process

functionDone (summary, latency, requests) Latency.min--Minimum value seenLatency.max--Maximum value seenLatency.mean--average value seenLatency.stdev--Standard deviationLatency:percentile (99.0)--99th Percentile ValueLatency (i)--raw value and CountSummary={Duration= N,--run duration in microsecondsRequests = N,--Total completed requestsbytes = N,--Total Bytes ReceivedErrors ={Connect= N,--Total socket Connection ErrorsRead = N,--Total socket Read ErrorsWrite = N,--Total Socket Write errorsStatus = N,--Total HTTP Status codes > 399Timeout = N--Total Request Timeouts  }}

Submit an example form
Wrk.method ="POST"Wrk.body="" --write directly to death if you do not need to request the data to be differentiatedwrk.headers["Content-type"] ="application/x-www-form-urlencoded"--if you want to implement form content that is not the same every timeLocalqueries = {    "language=php",    "Language=java",    "Language=lua"}Locali =0Request=function()    LocalBODY = Wrk.format (Nil,Nil,Nil, Queries[i% #queries +1]) I= i +1    returnBodyEnd

Lua script in wrk (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.