"Fossies" - the Fresh Open Source Software Archive

Member "wrk-4.2.0/scripts/setup.lua" (7 Feb 2021, 864 Bytes) of package /linux/www/wrk-4.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 -- example script that demonstrates use of setup() to pass
    2 -- data to and from the threads
    3 
    4 local counter = 1
    5 local threads = {}
    6 
    7 function setup(thread)
    8    thread:set("id", counter)
    9    table.insert(threads, thread)
   10    counter = counter + 1
   11 end
   12 
   13 function init(args)
   14    requests  = 0
   15    responses = 0
   16 
   17    local msg = "thread %d created"
   18    print(msg:format(id))
   19 end
   20 
   21 function request()
   22    requests = requests + 1
   23    return wrk.request()
   24 end
   25 
   26 function response(status, headers, body)
   27    responses = responses + 1
   28 end
   29 
   30 function done(summary, latency, requests)
   31    for index, thread in ipairs(threads) do
   32       local id        = thread:get("id")
   33       local requests  = thread:get("requests")
   34       local responses = thread:get("responses")
   35       local msg = "thread %d made %d requests and got %d responses"
   36       print(msg:format(id, requests, responses))
   37    end
   38 end