line/armeria

Provides a throttling strategy based on the number of pending blocking tasks.

Open

#3,829 建立於 2021年9月23日

在 GitHub 查看
 (9 留言) (0 反應) (0 負責人)Java (4,552 star) (863 fork)batch import
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);
        }
    }
}

貢獻者指南