line/armeria

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

开放

#3,829 创建于 2021年9月23日

 (9 条评论) (0 个反应) (0 位负责人)Java (863 个派生)batch import
good first issuenew feature

仓库指标

星标
 (4,552 个星标)
PR 合并指标
 (平均合并 5天 12小时) (30 天内合并 42 个 PR)

描述

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

贡献者指南