line/armeria
GitHub で見るProvides a throttling strategy based on the number of pending blocking tasks.
Open
#3,829 opened on 2021年9月23日
good first issuenew feature
説明
If all threads of a BlockingTaskExecutor are busy, a new incoming request is enqueued and will wait until its turn comes.
It will cause GC pressure and a response will be sent when the request is timed out.
Even though the request was timed out, the blocking task executor will execute regardless of the state of the request.
It would be useful to throttle incoming requests based on the queue size of BlockingTaskExecutor
class BlockingTaskLimitingThrottlingStrategy<T extends Request> extends ThrottlingStrategy<T> {
@Override
public CompletionStage<Boolean> accept(ServiceRequestContext ctx, T request) {
var theadPoolExecutor = getTheadPoolExecutor(ctx.blockingTaskExecutor());
if (theadPoolExecutor.getQueue.size() > MAX_QUEUE_SIZE) {
CompletableFuture.completedFuture(false);
} else {
CompletableFuture.completedFuture(true);
}
}
}