Backpressure Queue Simulation
Backpressure Queue Simulation
You have a bounded queue with capacity C. Each tick provides:
Arrivals: number of incoming requestsService: number of requests the system can process
Rules per tick (in order):
- Add arrivals to the queue.
- If queue exceeds capacity, drop the excess (load shedding).
- Process up to
Servicerequests from the queue.
Return the total dropped requests and the max queue size observed (after arrivals and shedding, before service).
Types
type Tick struct {
Arrivals int
Service int
}
Function signature
func BackpressureSim(capacity int, ticks []Tick) (dropped int, maxQueue int)
Example
capacity = 5
ticks = [
{Arrivals: 3, Service: 1}, // queue: 3 -> process 1 => 2
{Arrivals: 5, Service: 2}, // queue: 7 -> drop 2 => 5 -> process 2 => 3
]
Dropped = 2
Max queue = 5
Constraints
0 <= len(ticks) <= 1000000 <= Arrivals, Service <= 1_000_0000 <= capacity <= 1_000_000
Run tests to see results
No issues detected