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