summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-06-16 19:32:50 +0200
committerGitHub <noreply@github.com>2021-06-16 19:32:50 +0200
commita5d947fca330c7765b39051202eba11cf21d8c53 (patch)
tree9b81cf39741abd0fece234e043a1f2c9d02567a2 /config
parent0ba552240a4b5732dad7295b19be0be626883633 (diff)
Revert "Cleanup, no functional changes"
Diffstat (limited to 'config')
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/benchmark/LoadTester.java104
1 files changed, 50 insertions, 54 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 f57da6921ab..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,17 +69,18 @@ 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,
String configsList, String defPath) throws IOException, InterruptedException {
configs = readConfigs(configsList);
defs = readDefs(defPath);
- Metrics m = new Metrics();
List<LoadThread> threadList = new ArrayList<>();
-
long start = System.currentTimeMillis();
+ Metrics m = new Metrics();
+
for (int i = 0; i < threads; i++) {
LoadThread lt = new LoadThread(iterations, host, port);
threadList.add(lt);
@@ -100,14 +99,12 @@ public class LoadTester {
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;
}
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) {
@@ -115,8 +112,7 @@ public class LoadTester {
if (!name.endsWith(".def")) continue;
String contents = IOUtils.readFile(f);
ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromDefFile(f);
- ret.put(key, new Tuple2<>(ConfigUtils.getDefMd5(Arrays.asList(contents.split("\n"))),
- contents.split("\n")));
+ ret.put(key, new Tuple2<>(ConfigUtils.getDefMd5(Arrays.asList(contents.split("\n"))), contents.split("\n")));
}
System.out.println("# Read " + ret.size() + " def files from " + defDir.getPath());
return ret;
@@ -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,20 +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()));
- JRTClientConfigRequest request = getRequest(reqKey);
+ 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.");
+ }
+ 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) {
@@ -235,36 +255,12 @@ public class LoadTester {
}
}
- 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;
- }
-
- private JRTClientConfigRequest getRequest(ConfigKey<?> reqKey) {
- long serverTimeout = 1000;
-
- ConfigDefinitionKey dKey = new ConfigDefinitionKey(reqKey);
- Tuple2<String, String[]> defPair = defs.get(dKey);
-
- String defMd5 = defPair.first;
- DefContent defContent = DefContent.fromList(List.of(defPair.second));
-
- ConfigKey<?> fullKey = createFull(reqKey.getName(), reqKey.getConfigId(), reqKey.getNamespace(), defMd5);
- return JRTClientConfigRequestV3.createWithParams(fullKey, defContent, ConfigUtils.getCanonicalHostName(),
- "", 0, serverTimeout,
- Trace.createDummy(), compressionType, Optional.empty());
+ 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)),
+ ConfigUtils.getCanonicalHostName(), "", 0, serverTimeout, Trace.createDummy(),
+ compressionType, Optional.empty());
}
private Target connect(Spec spec) {