summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-06-17 21:12:47 +0200
committerGitHub <noreply@github.com>2021-06-17 21:12:47 +0200
commit40bd5b5e39ba3cb52170fd5cdbbf4e9f6c1a7bf2 (patch)
tree1c4a29f6c81d8dea6d19412bdb3e46e19e45041a /config
parent5f0cc6461a201d3843c7d56c1eec9a5c2798dfb2 (diff)
Revert "Cleanup, no functional changes, take 2"
Diffstat (limited to 'config')
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/benchmark/LoadTester.java78
1 files changed, 38 insertions, 40 deletions
diff --git a/config/src/main/java/com/yahoo/vespa/config/benchmark/LoadTester.java b/config/src/main/java/com/yahoo/vespa/config/benchmark/LoadTester.java
index 43caf2d52fe..3a8d80e5ffe 100644
--- a/config/src/main/java/com/yahoo/vespa/config/benchmark/LoadTester.java
+++ b/config/src/main/java/com/yahoo/vespa/config/benchmark/LoadTester.java
@@ -1,4 +1,4 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.benchmark;
import com.yahoo.collections.Tuple2;
@@ -33,8 +33,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
-import static com.yahoo.vespa.config.ConfigKey.createFull;
-
/**
* A config client for generating load against a config server or config proxy.
* <p>
@@ -71,7 +69,8 @@ public class LoadTester {
String configsList = parser.getBinarySwitches().get("-l");
String defPath = parser.getBinarySwitches().get("-dd");
debug = parser.getUnarySwitches().contains("-d");
- new LoadTester().runLoad(host, port, iterations, threads, configsList, defPath);
+ LoadTester loadTester = new LoadTester();
+ loadTester.runLoad(host, port, iterations, threads, configsList, defPath);
}
private void runLoad(String host, int port, int iterations, int threads,
@@ -98,17 +97,14 @@ public class LoadTester {
private Map<ConfigDefinitionKey, Tuple2<String, String[]>> readDefs(String defPath) throws IOException {
Map<ConfigDefinitionKey, Tuple2<String, String[]>> ret = new HashMap<>();
if (defPath == null) return ret;
-
File defDir = new File(defPath);
if (!defDir.isDirectory()) {
- System.out.println("# Given def file dir is not a directory: " +
- defDir.getPath() + " , will not send def contents in requests.");
+ System.out.println("# Given def file dir is not a directory: " + defDir.getPath() + " , will not send def contents in requests.");
return ret;
}
- File[] files = defDir.listFiles();
+ final File[] files = defDir.listFiles();
if (files == null) {
- System.out.println("# Given def file dir has no files: " +
- defDir.getPath() + " , will not send def contents in requests.");
+ System.out.println("# Given def file dir has no files: " + defDir.getPath() + " , will not send def contents in requests.");
return ret;
}
for (File f : files) {
@@ -135,7 +131,7 @@ public class LoadTester {
sb.append((metrics.failedRequests));
sb.append("\n");
sb.append('#').append(TransportMetrics.getInstance().snapshot().toString()).append('\n');
- System.out.println(sb);
+ System.out.println(sb.toString());
}
private List<ConfigKey<?>> readConfigs(String configsList) throws IOException {
@@ -193,10 +189,10 @@ public class LoadTester {
private class LoadThread extends Thread {
- private final int iterations;
- private final String host;
- private final int port;
- private final Metrics metrics = new Metrics();
+ int iterations = 0;
+ String host = "";
+ int port = 0;
+ Metrics metrics = new Metrics();
LoadThread(int iterations, String host, int port) {
this.iterations = iterations;
@@ -208,24 +204,44 @@ public class LoadTester {
public void run() {
Spec spec = new Spec(host, port);
Target target = connect(spec);
-
+ ConfigKey<?> reqKey;
+ JRTClientConfigRequest request;
+ int totConfs = configs.size();
+ boolean reconnCycle = false; // to log reconn message only once, for instance at restart
for (int i = 0; i < iterations; i++) {
- ConfigKey<?> reqKey = configs.get(ThreadLocalRandom.current().nextInt(configs.size()));
+ reqKey = configs.get(ThreadLocalRandom.current().nextInt(totConfs));
ConfigDefinitionKey dKey = new ConfigDefinitionKey(reqKey);
Tuple2<String, String[]> defContent = defs.get(dKey);
if (defContent == null && defs.size() > 0) { // Only complain if we actually did run with a def dir
System.out.println("# No def found for " + dKey + ", not sending in request.");
}
- ConfigKey<?> configKey = createFull(reqKey.getName(), reqKey.getConfigId(), reqKey.getNamespace(), defContent.first);
- JRTClientConfigRequest request = createRequest(configKey, defContent.second);
+ request = getRequest(ConfigKey.createFull(reqKey.getName(), reqKey.getConfigId(), reqKey.getNamespace(), defContent.first), defContent.second);
if (debug) System.out.println("# Requesting: " + reqKey);
long start = System.currentTimeMillis();
target.invokeSync(request.getRequest(), 10.0);
long end = System.currentTimeMillis();
if (request.isError()) {
- target = handleError(request, spec, target);
+ if ("Connection lost".equals(request.errorMessage()) || "Connection down".equals(request.errorMessage())) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ if (!reconnCycle) {
+ System.out.println("# Connection lost, reconnecting...");
+ reconnCycle = true;
+ }
+ target.close();
+ target = connect(spec);
+ } else {
+ System.err.println(request.errorMessage());
+ }
+ metrics.incFailedRequests();
} else {
- System.out.println("# Connection OK");
+ if (reconnCycle) {
+ reconnCycle = false;
+ System.out.println("# Connection OK");
+ }
long duration = end - start;
if (debug) {
@@ -239,7 +255,7 @@ public class LoadTester {
}
}
- private JRTClientConfigRequest createRequest(ConfigKey<?> reqKey, String[] defContent) {
+ private JRTClientConfigRequest getRequest(ConfigKey<?> reqKey, String[] defContent) {
if (defContent == null) defContent = new String[0];
final long serverTimeout = 1000;
return JRTClientConfigRequestV3.createWithParams(reqKey, DefContent.fromList(Arrays.asList(defContent)),
@@ -250,24 +266,6 @@ public class LoadTester {
private Target connect(Spec spec) {
return supervisor.connect(spec);
}
-
- private Target handleError(JRTClientConfigRequest request, Spec spec, Target target) {
- if (List.of("Connection lost", "Connection down").contains(request.errorMessage())) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- System.out.println("# Connection lost, reconnecting...");
- target.close();
- target = connect(spec);
- } else {
- System.err.println(request.errorMessage());
- }
- metrics.incFailedRequests();
- return target;
- }
-
}
}