Refuse the burst, admit the sustained load
Send ten simultaneous requests and ten spaced arrivals through one bounded admission controller and compare refusals.
An admission controller decides which requests enter the system before any model work happens. A queue without a bound converts overload into latency: every request is accepted, and every request waits. A bounded queue converts some of that overload into immediate refusals, which the client can see and act on.
This example sends two arrival patterns through the same controller: ten requests at time zero, and ten requests spaced two time units apart. The burst accepts 4 and rejects 6; the sustained pattern accepts all 10. The difference is not a change in capacity. It is the arrival pattern meeting a fixed queue and concurrency limit. The simulator is deliberately small and its queue accounting is approximate, so the numbers are a trace, not a capacity plan.
Run it
From the canonical repository at commit
f958967d70992d7b09d9c75000bd8c543f1644d4:
python examples/ch26/admission.py --jsonPython 3.11 or later, standard library only. No model, network, GPU or credentials. It finishes immediately.
Implementation
The controller admits an arrival only when the queue has room and active work is
below the concurrency limit. Otherwise it increments rejected. The loop
processes one active slot per time step and records the maximum observed queue.
class AdmissionController:
def __init__(self, max_queue: int = 4, max_concurrency: int = 2, deadline: int = 10) -> None:
if max_queue < 0 or max_concurrency < 1 or deadline < 1:
raise ValueError("invalid admission configuration")
self.max_queue = max_queue
self.max_concurrency = max_concurrency
self.deadline = deadline
def simulate(self, arrivals: List[int]) -> AdmissionResult:
# arrivals: list of arrival times (one per request).
queue: deque[int] = deque()
active = 0
accepted = 0
rejected = 0
expired = 0
max_queue = 0
time = 0
# Sort arrivals.
arrivals_sorted = sorted(arrivals)
i = 0
n = len(arrivals_sorted)
# Event loop until all processed.
while i < n or queue or active > 0:
# Admit arrivals at this time.
while i < n and arrivals_sorted[i] <= time:
if len(queue) < self.max_queue and active < self.max_concurrency:
queue.append(arrivals_sorted[i])
accepted += 1
else:
rejected += 1
i += 1
# Expire old queued requests.
# (Simplified: if queue wait exceeds deadline, drop.)
# Process one active slot.
if queue and active < self.max_concurrency:
queue.popleft()
active += 1
# Complete active work after 1 time unit.
# We approximate: decrement active each step.
if active > 0:
active -= 1
# Expire queued requests older than deadline.
# Remove from front if too old (approx).
max_queue = max(max_queue, len(queue))
time += 1
if time > 1000:
breakExpected outcome
Observed with the command above (exit 0):
{
"burst": {
"policy": "bounded",
"accepted": 4,
"rejected": 6,
"max_queue": 3,
"expired": 0,
"metadata": {
"arrivals": 10
}
},
"sustained": {
"policy": "bounded",
"accepted": 10,
"rejected": 0,
"max_queue": 0,
"expired": 0,
"metadata": {
"arrivals": 10
}
}
}In the burst, six requests were refused immediately. In the sustained pattern,
none were refused and the queue never held a request. max_queue is the largest
observed queue length, not the configured limit; here it was 3 although the
controller was constructed with max_queue=4.
Mechanism and limitations
Documented: the controller rejects an invalid configuration, admits only
when queue and concurrency allow it, counts rejections, processes one active slot
per step, and records the maximum queue. The tests check overflow rejection, the
demo structure, invalid configuration, JSON serialisation and the conservation
identity accepted + rejected == arrivals for a small case.
Observed: the command exited 0 with the burst and sustained results above.
The targeted tests.test_ch26_admission is part of the canonical suite; no
independent test count is claimed here.
Not shown: a real model, service time distribution, deadline expiry (the
field stays zero), priority or fairness, queue latency, or a capacity plan. The
simulator’s admission condition couples queue length to active work in a way that
does not match a production scheduler, and deadline is not exercised. The
numbers must not be used to size a real queue.
Challenge this result
Set max_queue=0 and max_concurrency=1, then simulate the burst. Predict how
many requests are accepted and how many are rejected, and check
accepted + rejected == 10. Then make arrivals every 0.5 time units, which the
integer-time simulator cannot represent directly; explain what the model is
missing and what a real queueing experiment would need to measure.
Source and verification
Canonical source:
examples/ch26/admission.py
at commit f958967d70992d7b09d9c75000bd8c543f1644d4. Tests:
tests/test_ch26_admission.py
.
Chapter: Request Scheduling and Admission Control
.
The run above is a fresh local execution on Windows 11 with Python 3.13.15; it
is a deterministic simulation, not a serving measurement.
Understand this example
Copy this prompt into your AI tool. No code runs here.
Apply this example
Copy this prompt into your AI tool. No code runs here.