aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java
diff options
context:
space:
mode:
authorMorten Tokle <mortent@verizonmedia.com>2021-12-07 12:52:42 +0100
committerMorten Tokle <mortent@verizonmedia.com>2021-12-07 12:52:42 +0100
commit5e956429169d3a733114e5f76f051167f291c786 (patch)
treefa2b9cc664c8c639482397e9a4566149dac3ae29 /vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java
parentae09069f544a086af4ae02a092ec66788a3cae9e (diff)
Extract vespa-feed-client-api module from vespa-feed-client
Diffstat (limited to 'vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java')
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java
new file mode 100644
index 00000000000..1f9cf8e5155
--- /dev/null
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/StaticThrottler.java
@@ -0,0 +1,47 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.feed.client.impl;
+
+import ai.vespa.feed.client.HttpResponse;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+
+/**
+ * Reduces max throughput whenever throttled; increases it slowly whenever successful responses are obtained.
+ *
+ * @author jonmv
+ */
+public class StaticThrottler implements Throttler {
+
+ protected final long maxInflight;
+ protected final long minInflight;
+ private final AtomicLong targetX10;
+
+ public StaticThrottler(FeedClientBuilderImpl builder) {
+ minInflight = 16L * builder.connectionsPerEndpoint * builder.endpoints.size();
+ maxInflight = 256 * minInflight; // 4096 max streams per connection on the server side.
+ targetX10 = new AtomicLong(10 * maxInflight); // 10x the actual value to allow for smaller updates.
+ }
+
+ @Override
+ public void sent(long inflight, CompletableFuture<HttpResponse> vessel) { }
+
+ @Override
+ public void success() {
+ targetX10.incrementAndGet();
+ }
+
+ @Override
+ public void throttled(long inflight) {
+ targetX10.set(max(inflight * 5, minInflight * 10));
+ }
+
+ @Override
+ public long targetInflight() {
+ return min(maxInflight, targetX10.get() / 10);
+ }
+
+}