line/armeria

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

オープン

#3,829 opened on 2021/09/23

 (9 件のコメント) (0 件のリアクション) (0 人の担当者)Java (863 件のフォーク)batch import
good first issuenew feature

Repository metrics

Stars
 (4,552 個のスター)
PR merge metrics
 (平均マージ 5d 12h) (30d で 42 merged PRs)

説明

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);
        }
    }
}

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