wg/wrk — pull request #113 by dhobsd (2014-12-12 23:38:50+00:00)
Title: script: provide scripts per-thread information

Expose new `wrk.threadid` and `wrk.nthreads` variables to the lua state of
each thread. These represent the thread id the lua state is running on, and
the total number of running threads, respectively.

This allows lua scripts to make intelligent decisions about how to form and
balance requests across a number of distinct hosts and URI path endpoints.
For example, scripts could use the thread identifier in conjunction with a
per-luastate counter to force all requests to be unique and deterministic,
which is useful in load testing caching servers as well as pre-filling them.

The following example allows multiple threads to pre-fill 60MM objects.
(Some holes will be present since threads won't execute with fairness, but
that's generally OK enough.)

```lua
local counter = 0
local nobj = 60000000

request = function()
path = "/" .. (counter + ((nobj / wrk.nthreads) * wrk.threadid))
counter = counter + 1
return wrk.format(nil, path)
end
```