diff options
Diffstat (limited to 'orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientTimeouts.java')
-rw-r--r-- | orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientTimeouts.java | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientTimeouts.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientTimeouts.java index cdae68a0d06..c54b6aae4fe 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientTimeouts.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientTimeouts.java @@ -3,23 +3,23 @@ package com.yahoo.vespa.orchestrator.controller; import com.yahoo.concurrent.UncheckedTimeoutException; import com.yahoo.time.TimeBudget; -import com.yahoo.vespa.jaxrs.client.JaxRsTimeouts; import java.time.Duration; +import java.util.Optional; /** * Calculates various timeouts associated with a REST call from the Orchestrator to the Cluster Controller. * * <p>Timeout handling of HTTP messaging is fundamentally flawed in various Java implementations. * We would like to specify a max time for the whole operation (connect, send request, and receive response). - * Jersey JAX-RS implementation and the Apache HTTP client library provides a way to set the connect timeout C + * The Apache HTTP client library provides a way to set the connect timeout C * and read timeout R. So if the operation takes NR reads, and the writes takes TW time, * the theoretical max time is: T = C + R * NR + TW. With both NR and TW unknown, there's no way to * set a proper C and R.</p> * * @author hakonhall */ -public class ClusterControllerClientTimeouts implements JaxRsTimeouts { +public class ClusterControllerClientTimeouts { static final Duration CONNECT_TIMEOUT = Duration.ofMillis(100); // Time reserved to guarantee that even though the server application honors a server timeout S, // some time will pass before the server sees the timeout, and after it has returned. @@ -36,40 +36,28 @@ public class ClusterControllerClientTimeouts implements JaxRsTimeouts { * A logical call to CC may in fact call the CC several times, if the first ones are down and/or not * the master. * - * @param timeBudget The time budget for a single logical call to the the Cluster Controller. + * @param timeBudget The time budget for a single logical call to the Cluster Controller. */ public ClusterControllerClientTimeouts(TimeBudget timeBudget) { this.timeBudget = timeBudget; } - @Override - public Duration getConnectTimeoutOrThrow() { - return CONNECT_TIMEOUT; - } - - @Override - public Duration getReadTimeoutOrThrow() { - Duration timeLeft = timeBudget.timeLeft().get(); - - // timeLeft = CONNECT_TIMEOUT + readTimeout - Duration readTimeout = timeLeft.minus(CONNECT_TIMEOUT); - - if (readTimeout.toMillis() <= 0) { + public Duration getServerTimeoutOrThrow() { + // readTimeout = DOWNSTREAM_OVERHEAD + serverTimeout + TimeBudget serverBudget = readBudget().withReserved(DOWNSTREAM_OVERHEAD); + if (serverBudget.timeLeft().get().compareTo(MIN_SERVER_TIMEOUT) < 0) throw new UncheckedTimeoutException("Timed out after " + timeBudget.originalTimeout().get()); - } - return readTimeout; + return serverBudget.timeLeft().get(); } - public Duration getServerTimeoutOrThrow() { - // readTimeout = DOWNSTREAM_OVERHEAD + serverTimeout - Duration serverTimeout = getReadTimeoutOrThrow().minus(DOWNSTREAM_OVERHEAD); - - if (serverTimeout.toMillis() < MIN_SERVER_TIMEOUT.toMillis()) { - throw new UncheckedTimeoutException("Timed out after " + timeBudget.originalTimeout().get()); - } + public Duration connectTimeout() { + return CONNECT_TIMEOUT; + } - return serverTimeout; + public TimeBudget readBudget() { + // timeLeft = CONNECT_TIMEOUT + readTimeout + return timeBudget.withReserved(CONNECT_TIMEOUT); } } |