Drain a fixed backlog at a selected rate and turn the remaining depth into a drain, steady, or throttle remediation action.

backlog depth The backlog depth and the scalar drain rate together decide the remediation action, so the result is reproducible without any live queue object.

Queue Drain Remediation Report

rate
queue_drain_remediation_report.rb
Replay: real traced execution (multi-file project)
rate = 1
depth = 4
drained = 0

rate.times do
  drained += 1 if drained < depth
end

remaining = depth - drained

action = if remaining >= 3
  "drain"
elsif remaining == 0
  "throttle"
else
  "steady"
end

puts "rate=#{rate}"
puts "drained=#{drained}"
puts "remaining=#{remaining}"
puts "action=#{action}"
rate = 3
depth = 4
drained = 0

rate.times do
  drained += 1 if drained < depth
end

remaining = depth - drained

action = if remaining >= 3
  "drain"
elsif remaining == 0
  "throttle"
else
  "steady"
end

puts "rate=#{rate}"
puts "drained=#{drained}"
puts "remaining=#{remaining}"
puts "action=#{action}"
rate = 5
depth = 4
drained = 0

rate.times do
  drained += 1 if drained < depth
end

remaining = depth - drained

action = if remaining >= 3
  "drain"
elsif remaining == 0
  "throttle"
else
  "steady"
end

puts "rate=#{rate}"
puts "drained=#{drained}"
puts "remaining=#{remaining}"
puts "action=#{action}"
  1. rate ← 1, depth ← 4, drained ← 0

    1rate→ 1 = 1  #@rate=3, 52depth→ 4 = 43drained→ 0 = 045rate1.times do6  drained += 1 if drained < depth7end
  2. do

    5rate1.times do6  drained0 += 1 if drained < depth47end
  3. remaining ← 3, action ← drain

    9remaining→ 3 = depth4 - drained11011action→ drain = if remaining3 >= 312  "drain"13elsif remaining3 == 014  "throttle"15else16  "steady"17end1819puts "rate=#{rate1}"20puts "drained=#{drained1}"21puts "remaining=#{remaining3}"22puts "action=#{actiondrain}"
    outputrate=1
    drained=1
    remaining=3
    action=drain
  1. rate ← 3, depth ← 4, drained ← 0

    1rate→ 3 = 32depth→ 4 = 43drained→ 0 = 045rate3.times do6  drained += 1 if drained < depth7end
  2. do

    pass 1 of 3
    5rate.times do6  drained0 += 1 if drained < depth47end
    All 3 passes — pass 1 is the card above
    passdrainedrate
    10
    21
    323
  3. remaining ← 1, action ← steady

    9remaining→ 1 = depth4 - drained31011action→ steady = if remaining1 >= 312  "drain"13elsif remaining1 == 014  "throttle"15else16  "steady"17end1819puts "rate=#{rate3}"20puts "drained=#{drained3}"21puts "remaining=#{remaining1}"22puts "action=#{actionsteady}"
    outputrate=3
    drained=3
    remaining=1
    action=steady
  1. rate ← 5, depth ← 4, drained ← 0

    1rate→ 5 = 52depth→ 4 = 43drained→ 0 = 045rate5.times do6  drained += 1 if drained < depth7end
  2. do

    pass 1 of 5
    5rate.times do6  drained0 += 1 if drained < depth47end
    All 5 passes — pass 1 is the card above
    passdrainedrate
    10
    21
    32
    43
    545
  3. remaining ← 0, action ← throttle

    9remaining→ 0 = depth4 - drained41011action→ throttle = if remaining0 >= 312  "drain"13elsif remaining0 == 014  "throttle"15else16  "steady"17end1819puts "rate=#{rate5}"20puts "drained=#{drained4}"21puts "remaining=#{remaining0}"22puts "action=#{actionthrottle}"
    outputrate=5
    drained=4
    remaining=0
    action=throttle