Drain a fixed backlog of arrivals against a bounded depth and turn the remaining depth into a drain, steady, or throttle remediation action.

backlog depth The backlog depth and arrivals are scalars, so the remaining capacity that drives the remediation action stays deterministic without draining a live queue.

Async Queue Remediation Report

arrivals
async_queue.lua
Replay: real traced execution (multi-file project)
local arrivals = 1
local depth = 4
local drained = arrivals
if drained > depth then
  drained = depth
end
local remaining = depth - drained

local action = "steady"
if drained <= 1 then
  action = "drain"
elseif remaining == 0 then
  action = "throttle"
end

print("arrivals=" .. arrivals .. " drained=" .. drained .. " remaining=" .. remaining .. " " .. action)
local arrivals = 3
local depth = 4
local drained = arrivals
if drained > depth then
  drained = depth
end
local remaining = depth - drained

local action = "steady"
if drained <= 1 then
  action = "drain"
elseif remaining == 0 then
  action = "throttle"
end

print("arrivals=" .. arrivals .. " drained=" .. drained .. " remaining=" .. remaining .. " " .. action)
local arrivals = 5
local depth = 4
local drained = arrivals
if drained > depth then
  drained = depth
end
local remaining = depth - drained

local action = "steady"
if drained <= 1 then
  action = "drain"
elseif remaining == 0 then
  action = "throttle"
end

print("arrivals=" .. arrivals .. " drained=" .. drained .. " remaining=" .. remaining .. " " .. action)
  1. arrivals ← 1, depth ← 4, drained ← 1, remaining ← 3, action ← steady

    1local arrivals→ 1 = 1 --@arrivals=3, 52local depth→ 4 = 43local drained→ 1 = arrivals14if drained > depth then5  drained = depth6end7local remaining→ 3 = depth4 - drained189local action→ steady = "steady"10if drained <= 1 then
  2. action ← drain

    9local action = "steady"10if drained1 <= 1 then11  action→ drain = "drain"12elseif remaining == 0 then
  3. print("arrivals=" .. arrivals .. " drained=" .. drained .. " remaining…

    16print("arrivals=" .. arrivals1 .. " drained=" .. drained1 .. " remaining=" .. remaining3 .. " " .. actiondrain)
    outputarrivals=1 drained=1 remaining=3 drain
  1. arrivals ← 3, depth ← 4, drained ← 3, remaining ← 1, action ← steady

    1local arrivals→ 3 = 32local depth→ 4 = 43local drained→ 3 = arrivals34if drained > depth then5  drained = depth6end7local remaining→ 1 = depth4 - drained389local action→ steady = "steady"10if drained <= 1 then11  action = "drain"12elseif remaining == 0 then13  action = "throttle"14end1516print("arrivals=" .. arrivals3 .. " drained=" .. drained3 .. " remaining=" .. remaining1 .. " " .. actionsteady)
    outputarrivals=3 drained=3 remaining=1 steady
  1. arrivals ← 5, depth ← 4, drained ← 5

    1local arrivals→ 5 = 52local depth→ 4 = 43local drained→ 5 = arrivals54if drained > depth then
  2. drained ← 4

    3local drained = arrivals4if drained5 > depth4 then5  drained→ 4 = depth46end
  3. remaining ← 0, action ← steady

    6end7local remaining→ 0 = depth4 - drained489local action→ steady = "steady"10if drained <= 1 then
  4. action ← throttle

    11  action = "drain"12elseif remaining0 == 0 then13  action→ throttle = "throttle"14end
  5. print("arrivals=" .. arrivals .. " drained=" .. drained .. " remaining…

    16print("arrivals=" .. arrivals5 .. " drained=" .. drained4 .. " remaining=" .. remaining0 .. " " .. actionthrottle)
    outputarrivals=5 drained=4 remaining=0 throttle