2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-27 00:02:19 +08:00

Fix memory usage lua script

This commit is contained in:
Ken Hibino 2022-03-26 14:33:03 -07:00
parent 0cfa7f47ba
commit bc27126670

View File

@ -292,30 +292,25 @@ for i=3,6 do
memusg = memusg + m memusg = memusg + m
end end
end end
local group_names = redis.call("SRANDMEMBER", KEYS[7], tonumber(ARGV[3])) local groups = redis.call("SMEMBERS", KEYS[7])
if (table.getn(group_names) > 0) then if table.getn(groups) > 0 then
local group_sample_total = 0 local agg_task_count = 0
for _, gname in ipairs(group_names) do local agg_task_sample_total = 0
local group_key = ARGV[4] .. gname local agg_task_sample_size = 0
local ids = redis.call("ZRANGE", group_key, 0, sample_size - 1) for i, gname in ipairs(groups) do
local sample_total = 0 local group_key = ARGV[4] .. gname
if (table.getn(ids) > 0) then agg_task_count = agg_task_count + redis.call("ZCARD", group_key)
for _, id in ipairs(ids) do if i <= tonumber(ARGV[3]) then
local bytes = redis.call("MEMORY", "USAGE", ARGV[1] .. id) local ids = redis.call("ZRANGE", group_key, 0, sample_size - 1)
sample_total = sample_total + bytes for _, id in ipairs(ids) do
end local bytes = redis.call("MEMORY", "USAGE", ARGV[1] .. id)
local n = redis.call("ZCARD", group_key) agg_task_sample_total = agg_task_sample_total + bytes
local avg = sample_total / table.getn(ids) agg_task_sample_size = agg_task_sample_size + 1
group_sample_total = group_sample_total + (avg * n) end
end end
local m = redis.call("MEMORY", "USAGE", group_key) end
if (m) then local avg = agg_task_sample_total / agg_task_sample_size
group_sample_total = group_sample_total + m memusg = memusg + (avg * agg_task_count)
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
return memusg return memusg
`) `)