"Fossies" - the Fresh Open Source Software Archive

Member "wrk-4.2.0/scripts/addr.lua" (7 Feb 2021, 504 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 -- a random server address to each thread
    3 
    4 local addrs = nil
    5 
    6 function setup(thread)
    7    if not addrs then
    8       addrs = wrk.lookup(wrk.host, wrk.port or "http")
    9       for i = #addrs, 1, -1 do
   10          if not wrk.connect(addrs[i]) then
   11             table.remove(addrs, i)
   12          end
   13       end
   14    end
   15 
   16    thread.addr = addrs[math.random(#addrs)]
   17 end
   18 
   19 function init(args)
   20    local msg = "thread addr: %s"
   21    print(msg:format(wrk.thread.addr))
   22 end