Processing one request at a time under-utilizes an accelerator (GPUs are efficient at large matmuls, not many tiny ones); waiting to accumulate a large batch before running anything hurts latency for early-arriving requests. Implement a dynamic (static-window) batching policy: incoming requests are grouped into a batch either once max_batch_size requests have arrived, or once max_wait_time has elapsed since the oldest currently-waiting request arrived — whichever happens first.
close_time = min(t0 + max_wait_time, time at which the batch reaches max_batch_size)
where t0 is the oldest unbatched request's arrival time.
max_batch_size.max_batch_size, it closes at batch_start_time + max_wait_time even if a new request would otherwise have joined later.Track the current open batch's start time (the first request's arrival in that batch). Every subsequent request either joins if the batch isn't full yet and hasn't timed out, or starts a new batch. A request arriving exactly at the timeout boundary should be treated as arriving after closure (>=), to avoid an off-by-one ambiguity.
No results yet
Run your code to check it against the examples, or submit to run every test.