diff options
Diffstat (limited to 'vespa-http-client')
2 files changed, 5 insertions, 7 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/GatewayThrottler.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/GatewayThrottler.java index cc637904553..189fd348c0e 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/GatewayThrottler.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/GatewayThrottler.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.http.client.core.communication; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * When the gateways says it can not handle more load, we should send less load. That is the responsibility @@ -13,7 +13,6 @@ public class GatewayThrottler { private long backOffTimeMs = 0; private final long maxSleepTimeMs; - private static Random random = new Random(); public GatewayThrottler(long maxSleepTimeMs) { this.maxSleepTimeMs = maxSleepTimeMs; @@ -39,7 +38,7 @@ public class GatewayThrottler { } public int distribute(int expected) { - double factor = 0.5 + random.nextDouble(); + double factor = 0.5 + ThreadLocalRandom.current().nextDouble(); Double result = expected * factor; return result.intValue(); } diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottler.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottler.java index 6ecbb56888e..7cf4e32a880 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottler.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottler.java @@ -3,7 +3,7 @@ package com.yahoo.vespa.http.client.core.operationProcessor; import com.yahoo.vespa.http.client.core.ThrottlePolicy; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * Adjusts in-flight operations based on throughput. It will walk the graph and try to find @@ -34,11 +34,10 @@ public class IncompleteResultsThrottler { private final ConcurrentDocumentOperationBlocker blocker = new ConcurrentDocumentOperationBlocker(); private final int maxInFlightValue; private final int minInFlightValue; - private final Random random = new Random(); private final ThrottlePolicy policy; // 9-11 seconds with some randomness to avoid fully synchronous feeders. - public final long phaseSizeMs = 9000 + (random.nextInt() % 2000); + public final long phaseSizeMs = 9000 + (ThreadLocalRandom.current().nextInt() % 2000); private final Clock clock; private final Object monitor = new Object(); @@ -129,7 +128,7 @@ public class IncompleteResultsThrottler { private void adjustCycle() { adjustCycleCount++; - stabilizingPhasesLeft = adjustCycleCount < 5 ? 1 : 2 + random.nextInt() % 2; + stabilizingPhasesLeft = adjustCycleCount < 5 ? 1 : 2 + ThreadLocalRandom.current().nextInt() % 2; double maxPerformanceChange = getCeilingDifferencePerformance(adjustCycleCount); boolean messagesQueued = minPermitsAvailable < 2; |