From 84d8e7b2942032cf1292970ad8041f7c326e327e Mon Sep 17 00:00:00 2001 From: IgorPerikov Date: Tue, 3 Dec 2019 20:10:22 +0300 Subject: [PATCH] #147: let AIMD grow by configurable amount --- .../netflix/concurrency/limits/limit/AIMDLimit.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/AIMDLimit.java b/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/AIMDLimit.java index 940d13d6..b18b7400 100644 --- a/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/AIMDLimit.java +++ b/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/AIMDLimit.java @@ -31,6 +31,7 @@ public static class Builder { private int minLimit = 20; private int initialLimit = 20; private int maxLimit = 200; + private int increase = 1; private double backoffRatio = 0.9; private long timeout = DEFAULT_TIMEOUT; @@ -55,6 +56,12 @@ public Builder backoffRatio(double backoffRatio) { return this; } + public Builder increaseBy(int increase) { + Preconditions.checkArgument(increase >= 1, "Increase value must be >= 1"); + this.increase = increase; + return this; + } + /** * Timeout threshold that when exceeded equates to a drop. * @param timeout @@ -75,7 +82,8 @@ public AIMDLimit build() { public static Builder newBuilder() { return new Builder(); } - + + private final int increase; private final double backoffRatio; private final long timeout; private final int minLimit; @@ -83,6 +91,7 @@ public static Builder newBuilder() { private AIMDLimit(Builder builder) { super(builder.initialLimit); + this.increase = builder.increase; this.backoffRatio = builder.backoffRatio; this.timeout = builder.timeout; this.maxLimit = builder.maxLimit; @@ -96,7 +105,7 @@ protected int _update(long startTime, long rtt, int inflight, boolean didDrop) { if (didDrop || rtt > timeout) { currentLimit = (int) (currentLimit * backoffRatio); } else if (inflight * 2 >= currentLimit) { - currentLimit = currentLimit + 1; + currentLimit = currentLimit + increase; } if (currentLimit >= maxLimit) {