line/armeria

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

Open

#3,829 opened on 2021年9月23日

GitHub で見る
 (9 comments) (0 reactions) (0 assignees)Java (4,552 stars) (863 forks)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);
        }
    }
}

コントリビューターガイド

Provides a throttling strategy based on the number of pending blocking tasks. · line/armeria#3829 | Good First Issue