Provides a com.twitter.util.Future that waits to be issued permits
permits until after the previously scheduled waiters have had their permits
issued.
Provides a com.twitter.util.Future that waits to be issued permits
permits until after the previously scheduled waiters have had their permits
issued. Permits are spaced out evenly, so that they aren't issued in big
batches all at once.
If a waiter is scheduled, but the existing queue is empty, it is delayed until sufficient permits have built up. If enough time has passed since the last waiter was permitted so that permits would have built up while it was waiting, it will be permitted immediately.
If the returned com.twitter.util.Future is interrupted, we try to cancel it. If it's successfully cancelled, the com.twitter.util.Future is satisfied with a java.util.concurrent.CancellationException, and the permits will not be issued, so a subsequent waiter can take advantage of the permits.
If await
is invoked when there are already maxWaiters
waiters waiting
for permits, the com.twitter.util.Future is immediately satisfied with
a java.util.concurrent.RejectedExecutionException.
If more permits are requested than burstSize
then it returns a failed
java.lang.IllegalArgumentException com.twitter.util.Future
immediately.
Returns the current number of outstanding waiters in the queue
An asynchronous meter.
Processes can create an asynchronously awaiting future, a "waiter" to wait until the meter allows it to continue, which is when the meter can give it as many permits as it asked for. Up to
burstSize
permits are issued everyburstDuration
. IfmaxWaiters
waiters are enqueued simultaneously, it will reject further attempts to wait, until some of the tasks have been executed.It may be appropriate to use this to smooth out bursty traffic, or if using a resource that's rate-limited based on time. However, to avoid overwhelming a constrained resource that doesn't exert coordination controls like backpressure, it's safer to limit based on AsyncSemaphore, since it can speed up if that resource speeds up, and slow down if that resource slows down.