Offer a fixed number of arrivals into a bounded queue and turn the accepted and remaining counts into a drain, steady, or throttle remediation action.

queue pressure A `queue.Queue` with a fixed `maxsize` makes backpressure deterministic: the accepted count and remaining slots together select the remediation action.

Bounded Queue Remediation Report

arrivals
bounded_queue_remediation_report.py
Replay: real traced execution (multi-file project)
import queue


arrivals = 1
buffer = queue.Queue(maxsize=4)
accepted = 0

for item in range(arrivals):
    try:
        buffer.put_nowait(item)
        accepted += 1
    except queue.Full:
        pass

remaining = 4 - buffer.qsize()
action = "drain" if accepted <= 1 else "throttle" if remaining == 0 else "steady"

print("arrivals=" + str(arrivals) + " accepted=" + str(accepted) + " remaining=" + str(remaining) + " action=" + action)
import queue


arrivals = 3
buffer = queue.Queue(maxsize=4)
accepted = 0

for item in range(arrivals):
    try:
        buffer.put_nowait(item)
        accepted += 1
    except queue.Full:
        pass

remaining = 4 - buffer.qsize()
action = "drain" if accepted <= 1 else "throttle" if remaining == 0 else "steady"

print("arrivals=" + str(arrivals) + " accepted=" + str(accepted) + " remaining=" + str(remaining) + " action=" + action)
import queue


arrivals = 5
buffer = queue.Queue(maxsize=4)
accepted = 0

for item in range(arrivals):
    try:
        buffer.put_nowait(item)
        accepted += 1
    except queue.Full:
        pass

remaining = 4 - buffer.qsize()
action = "drain" if accepted <= 1 else "throttle" if remaining == 0 else "steady"

print("arrivals=" + str(arrivals) + " accepted=" + str(accepted) + " remaining=" + str(remaining) + " action=" + action)
  1. arrivals ← 1, buffer ← ⟨Queue A⟩, accepted ← 0

    4arrivals→ 1 = 1  #@arrivals=3, 55buffer→ ⟨Queue A⟩ = queue<module 'queue' from '/usr/local/lib/python3.12/queue.py'>.Queue(maxsize=4)6accepted→ 0 = 0
  2. for item in range(arrivals):

    8for item0 in range(arrivals1):9    try:10        buffer.put_nowait(item)
  3. accepted ← 1

    8for item in range(arrivals):9    try:10        buffer⟨Queue A⟩.put_nowait(item0)11        accepted→ 1 += 112    except queue.Full:
  4. remaining ← 3, action ← drain

    15remaining→ 3 = 4 - buffer⟨Queue A⟩.qsize()16action→ drain = "drain" if accepted1 <= 1 else "throttle" if remaining3 == 0 else "steady"1718print("arrivals=" + str(arrivals1) + " accepted=" + str(accepted1) + " remaining=" + str(remaining3) + " action=" + actiondrain)
    outputarrivals=1 accepted=1 remaining=3 action=drain
  1. arrivals ← 3, buffer ← ⟨Queue A⟩, accepted ← 0

    4arrivals→ 3 = 35buffer→ ⟨Queue A⟩ = queue<module 'queue' from '/usr/local/lib/python3.12/queue.py'>.Queue(maxsize=4)6accepted→ 0 = 0
  2. for item in range(arrivals):

    pass 1 of 3
    8for item0 in range(arrivals3):9    try:10        buffer.put_nowait(item)
    All 3 passes — pass 1 is the card above
    passitem
    10
    21
    32
  3. accepted ← 1

    pass 1 of 3
    8for item in range(arrivals):9    try:10        buffer⟨Queue A⟩.put_nowait(item0)11        accepted→ 1 += 112    except queue.Full:
    All 3 passes — pass 1 is the card above
    passitemaccepted
    100 1
    211 2
    322 3
  4. remaining ← 1, action ← steady

    15remaining→ 1 = 4 - buffer⟨Queue A⟩.qsize()16action→ steady = "drain" if accepted3 <= 1 else "throttle" if remaining1 == 0 else "steady"1718print("arrivals=" + str(arrivals3) + " accepted=" + str(accepted3) + " remaining=" + str(remaining1) + " action=" + actionsteady)
    outputarrivals=3 accepted=3 remaining=1 action=steady
  1. arrivals ← 5, buffer ← ⟨Queue A⟩, accepted ← 0

    4arrivals→ 5 = 55buffer→ ⟨Queue A⟩ = queue<module 'queue' from '/usr/local/lib/python3.12/queue.py'>.Queue(maxsize=4)6accepted→ 0 = 0
  2. for item in range(arrivals):

    pass 1 of 5
    8for item0 in range(arrivals5):9    try:10        buffer.put_nowait(item)
    All 5 passes — pass 1 is the card above
    passitem
    10
    21
    32
    43
    54
  3. accepted ← 1

    pass 1 of 5
    8for item in range(arrivals):9    try:10        buffer⟨Queue A⟩.put_nowait(item0)11        accepted→ 1 += 112    except queue.Full:
    All 5 passes — pass 1 is the card above
    passitemaccepted
    100 1
    211 2
    322 3
    433 4
    54
  4. remaining ← 0, action ← throttle

    15remaining→ 0 = 4 - buffer⟨Queue A⟩.qsize()16action→ throttle = "drain" if accepted4 <= 1 else "throttle" if remaining0 == 0 else "steady"1718print("arrivals=" + str(arrivals5) + " accepted=" + str(accepted4) + " remaining=" + str(remaining0) + " action=" + actionthrottle)
    outputarrivals=5 accepted=4 remaining=0 action=throttle