blob: e5d630fea5531979c9a3cc091d7a3544816f1330 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.dispatch.rpc;
import com.yahoo.search.Query;
/**
* @author bjorncs
*/
class TimeoutHelper {
private TimeoutHelper() {}
static Timeout calculateTimeout(Query q) {
long timeLeftMillis = q.getTimeLeft();
if (timeLeftMillis <= 2) return new Timeout(0d, 0d);
// The old timeout logic subtracted 3ms to timeout for client timeout.
// 3ms equalled to 0.6% of the default query timeout (500ms).
// This accounted for cost of network and container post-processing.
// New logic subtracts 1% for client and 2% for content node (request).
double clientTimeout = Math.max(timeLeftMillis * 0.99d, 2d) / 1000d;
double requestTimeout = Math.max(timeLeftMillis * 0.98d, 1d) / 1000d;
return new Timeout(requestTimeout, clientTimeout);
}
record Timeout(double request, double client) {
public boolean timedOut() { return request == 0 && client == 0; }
}
}
|