summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-04-05 09:49:43 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2024-04-05 09:49:43 +0200
commitbf7c818c5cc2ba91be13573e45e3578c28de29ba (patch)
tree4e61eaf5461060e1513d1545519926411f4d36b5
parentc6908fefe8f527312ade2e938d724cda754ac2ef (diff)
Print rate.
-rw-r--r--vespa-feed-client-api/src/main/java/ai/vespa/feed/client/OperationStats.java14
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/BenchmarkingCluster.java12
2 files changed, 17 insertions, 9 deletions
diff --git a/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/OperationStats.java b/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/OperationStats.java
index 2eb41838560..e9337ab7a43 100644
--- a/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/OperationStats.java
+++ b/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/OperationStats.java
@@ -12,6 +12,7 @@ import java.util.stream.Collectors;
*/
public class OperationStats {
+ private final double duration;
private final long requests;
private final Map<Integer, Long> responsesByCode;
private final long inflight;
@@ -22,9 +23,10 @@ public class OperationStats {
private final long bytesSent;
private final long bytesReceived;
- public OperationStats(long requests, Map<Integer, Long> responsesByCode, long exceptions, long inflight,
- long averageLatencyMillis, long minLatencyMillis, long maxLatencyMillis,
+ public OperationStats(double duration, long requests, Map<Integer, Long> responsesByCode, long exceptions,
+ long inflight, long averageLatencyMillis, long minLatencyMillis, long maxLatencyMillis,
long bytesSent, long bytesReceived) {
+ this.duration = duration;
this.requests = requests;
this.responsesByCode = responsesByCode;
this.exceptions = exceptions;
@@ -38,9 +40,10 @@ public class OperationStats {
/** Returns the difference between this and the initial. Min and max latency are not modified. */
public OperationStats since(OperationStats initial) {
- return new OperationStats(requests - initial.requests,
+ return new OperationStats(duration - initial.duration,
+ requests - initial.requests,
responsesByCode.entrySet().stream()
- .collect(Collectors.toMap(entry -> entry.getKey(),
+ .collect(Collectors.toMap(Map.Entry::getKey,
entry -> entry.getValue() - initial.responsesByCode.getOrDefault(entry.getKey(), 0L))),
exceptions - initial.exceptions,
inflight - initial.inflight,
@@ -123,9 +126,12 @@ public class OperationStats {
@Override
public String toString() {
+ Map<Integer, Double> rateByCode = responsesByCode.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()/duration));
return "Stats{" +
"requests=" + requests +
", responsesByCode=" + responsesByCode +
+ ", responseRateByCode=" + rateByCode +
", exceptions=" + exceptions +
", inflight=" + inflight +
", averageLatencyMillis=" + averageLatencyMillis +
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/BenchmarkingCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/BenchmarkingCluster.java
index 753bc0240d3..afe4773988c 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/BenchmarkingCluster.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/BenchmarkingCluster.java
@@ -26,6 +26,7 @@ public class BenchmarkingCluster implements Cluster {
return thread;
});
+ private final AtomicLong timeOfFirstDispatch = new AtomicLong(0);
private final AtomicLong requests = new AtomicLong();
private long results = 0;
private long responses = 0;
@@ -45,6 +46,9 @@ public class BenchmarkingCluster implements Cluster {
public void dispatch(HttpRequest request, CompletableFuture<HttpResponse> vessel) {
requests.incrementAndGet();
long startNanos = System.nanoTime();
+ if (timeOfFirstDispatch.get() == 0) {
+ timeOfFirstDispatch.set(startNanos);
+ }
delegate.dispatch(request, vessel);
vessel.whenCompleteAsync((response, thrown) -> {
results++;
@@ -88,15 +92,13 @@ public class BenchmarkingCluster implements Cluster {
if (responsesByCode[code] > 0)
responses.put(code, responsesByCode[code]);
- return new OperationStats(requests,
- responses,
- exceptions,
+ double duration = (System.nanoTime() - timeOfFirstDispatch.get())*1e-9;
+ return new OperationStats(duration, requests, responses, exceptions,
requests - results,
this.responses == 0 ? -1 : totalLatencyMillis / this.responses,
this.responses == 0 ? -1 : minLatencyMillis,
this.responses == 0 ? -1 : maxLatencyMillis,
- bytesSent,
- bytesReceived);
+ bytesSent, bytesReceived);
}
@Override