If we are going to dispatch delayed API errors as a part of the rate limiting work, then we need machinery that can send out delayed responses without leaking an endless amount of goroutines that are all just blocked on time.Sleep.
This refactors things so that the delayed API responses are queued into an IPQ and will be sent out by a single goroutine at the right time, which will be much friendlier on the scheduler.
Additionally we also add new sort functionality to the IPQs so that on each push, we can re-sort the pending items so that those that are due to be processed first will be popped first.
If we are going to dispatch delayed API errors as a part of the rate limiting work, then we need machinery that can send out delayed responses without leaking an endless amount of goroutines that are all just blocked on
time.Sleep
.This refactors things so that the delayed API responses are queued into an IPQ and will be sent out by a single goroutine at the right time, which will be much friendlier on the scheduler.
Additionally we also add new sort functionality to the IPQs so that on each push, we can re-sort the pending items so that those that are due to be processed first will be popped first.
Signed-off-by: Neil Twigg neil@nats.io