Open fhalde opened 4 years ago
@giltene are you aware of this?
I ran into what may be a similar issue where when I view a lua table
from a different thread context, the keys
and values
are swapped.
local counter = 0
local threads = {}
function setup(thread)
thread:set("id", counter)
table.insert(threads, thread)
counter = counter + 1
end
function init(args)
uniq = 0
codes={left="right"}
end
function increment(t,k,v)
t[k]=(t[k] or 0)+(v or 1)
end
function response(status, headers, body)
increment(codes, status)
end
function status_pairs(tbl, flip)
local lst={}
for k, v in pairs(tbl) do
if flip then k, v = v, k end
if k ~= "left" then
table.insert(lst, {k, v})
end
end
table.sort(lst, function(l,r) return l[1] < r[1] end)
local i, n = 0, table.getn(lst)
return function()
i = i + 1
if i <= n then
return lst[i][1], lst[i][2]
end
end
end
function done(summary, latency, requests)
local results={}
for _, thread in ipairs(threads) do
local codes = thread:get("codes")
-- i have no idea why (or even how) wrk2 flips this table
-- but it does (but wrk doesn't), so we check for to see
-- if it's flipped when iterating over status code/count pairs
local flip = codes["left"] ~= "right"
local status = string.format("Thread Codes %-2s =>", thread:get("id"))
for k, v in status_pairs(codes, flip) do
status = string.format("%s %s:%s", status, k, v)
increment(results, k, v)
end
io.write(status .. "\n")
end
io.write("\n")
end
I have the following script
prints
which basically means the table that I am setting
t:set('r', requests)
is not being shared or accessible. This is working correctly inwrk