blob: 1f9cf8e5155d743cffa5deda64356b86ea677922 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
}
}
|