2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 11:31:58 +08:00

Fix memory_usage lua script

This commit is contained in:
Ken Hibino 2022-03-23 16:21:45 -07:00
parent 8a4fb71dd5
commit 0cfa7f47ba

View File

@ -293,28 +293,30 @@ for i=3,6 do
end end
end end
local group_names = redis.call("SRANDMEMBER", KEYS[7], tonumber(ARGV[3])) local group_names = redis.call("SRANDMEMBER", KEYS[7], tonumber(ARGV[3]))
local group_sample_total = 0 if (table.getn(group_names) > 0) then
for _, gname in ipairs(group_names) do local group_sample_total = 0
local group_key = ARGV[4] .. gname for _, gname in ipairs(group_names) do
local ids = redis.call("ZRANGE", group_key, 0, sample_size - 1) local group_key = ARGV[4] .. gname
local sample_total = 0 local ids = redis.call("ZRANGE", group_key, 0, sample_size - 1)
if (table.getn(ids) > 0) then local sample_total = 0
for _, id in ipairs(ids) do if (table.getn(ids) > 0) then
local bytes = redis.call("MEMORY", "USAGE", ARGV[1] .. id) for _, id in ipairs(ids) do
sample_total = sample_total + bytes local bytes = redis.call("MEMORY", "USAGE", ARGV[1] .. id)
sample_total = sample_total + bytes
end
local n = redis.call("ZCARD", group_key)
local avg = sample_total / table.getn(ids)
group_sample_total = group_sample_total + (avg * n)
end
local m = redis.call("MEMORY", "USAGE", group_key)
if (m) then
group_sample_total = group_sample_total + m
end end
local n = redis.call("ZCARD", group_key)
local avg = sample_total / table.getn(ids)
group_sample_total = group_sample_total + (avg * n)
end
local m = redis.call("MEMORY", "USAGE", group_key)
if (m) then
group_sample_total = group_sample_total + m
end end
local group_size = redis.call("SCARD", KEYS[7])
local group_memusg_avg = group_sample_total / table.getn(group_names)
memusg = memusg + (group_memusg_avg * group_size)
end end
local group_size = redis.call("SCARD", KEYS[7])
local group_memusg_avg = group_sample_total / table.getn(group_names)
memusg = memusg + (group_memusg_avg * group_size)
return memusg return memusg
`) `)