From 12b14fbd0bb21380faa470cf8b954554cdf93160 Mon Sep 17 00:00:00 2001 From: Michael Eischer <eischer@cs.fau.de> Date: Thu, 2 Jul 2020 14:01:54 +0200 Subject: [PATCH] Speedup replica initialization This defers the creation of request paths until a client is actually instantiated. Previously this initialization happened when REFITConfig loaded the client class, which slows down the configuration check. --- .../application/rezk/REZKTestClientExists.java | 15 +++++++++------ .../application/rezk/REZKTestClientReadWrite.java | 15 +++++++++------ .../rezk/REZKTestClientReadWriteActive.java | 15 +++++++++------ .../rezk/REZKTestClientReadWriteConflict.java | 15 +++++++++------ 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/refit/application/rezk/REZKTestClientExists.java b/src/refit/application/rezk/REZKTestClientExists.java index c2d6bb9..057930e 100644 --- a/src/refit/application/rezk/REZKTestClientExists.java +++ b/src/refit/application/rezk/REZKTestClientExists.java @@ -9,18 +9,21 @@ import refit.util.REFITTime; public class REZKTestClientExists extends REZKTestClient { private static final String[] prePaths = new String[2 * REFITConfig.NR_OF_NODES]; - static { - for (int i = 0; i < prePaths.length; i++) { - prePaths[i] = String.format("%s%05d", "/node", i); - } - } - private String[] paths; private boolean[] isValidPath; private int counter = 0; public REZKTestClientExists(REFITClientLibrary service) { super(service); + + synchronized (prePaths) { + if (prePaths[0] == null) { + for (int i = 0; i < prePaths.length; i++) { + prePaths[i] = String.format("%s%05d", "/node", i); + } + } + } + paths = new String[REFITConfig.NR_OF_NODES]; isValidPath = new boolean[paths.length]; // ensure reproducibility diff --git a/src/refit/application/rezk/REZKTestClientReadWrite.java b/src/refit/application/rezk/REZKTestClientReadWrite.java index a3d21b2..f45349a 100644 --- a/src/refit/application/rezk/REZKTestClientReadWrite.java +++ b/src/refit/application/rezk/REZKTestClientReadWrite.java @@ -12,17 +12,20 @@ import refit.util.REFITTime; public class REZKTestClientReadWrite extends REZKTestClient { private static final String[] paths = new String[REFITConfig.NR_OF_NODES]; - static { - for (int i = 0; i < paths.length; i++) { - paths[i] = String.format("%s%05d", "/node", i); - } - } - private int counter = 0; private Random rand; public REZKTestClientReadWrite(REFITClientLibrary service) { super(service); + + synchronized (paths) { + if (paths[0] == null) { + for (int i = 0; i < paths.length; i++) { + paths[i] = String.format("%s%05d", "/node", i); + } + } + } + rand = new Random(service.getNodeID()); } diff --git a/src/refit/application/rezk/REZKTestClientReadWriteActive.java b/src/refit/application/rezk/REZKTestClientReadWriteActive.java index e45828e..7baf684 100644 --- a/src/refit/application/rezk/REZKTestClientReadWriteActive.java +++ b/src/refit/application/rezk/REZKTestClientReadWriteActive.java @@ -11,18 +11,21 @@ import refit.util.REFITTime; public class REZKTestClientReadWriteActive extends REZKTestClient { private static final String[] paths = new String[REFITConfig.NR_OF_NODES]; - static { - for (int i = 0; i < paths.length; i++) { - paths[i] = String.format("%s%05d", "/node", i); - } - } - private static AtomicLong nextObj = new AtomicLong(); private int counter = 0; private Random rand; public REZKTestClientReadWriteActive(REFITClientLibrary service) { super(service); + + synchronized (paths) { + if (paths[0] == null) { + for (int i = 0; i < paths.length; i++) { + paths[i] = String.format("%s%05d", "/node", i); + } + } + } + rand = new Random(service.getNodeID()); } diff --git a/src/refit/application/rezk/REZKTestClientReadWriteConflict.java b/src/refit/application/rezk/REZKTestClientReadWriteConflict.java index bbab85b..1391f17 100644 --- a/src/refit/application/rezk/REZKTestClientReadWriteConflict.java +++ b/src/refit/application/rezk/REZKTestClientReadWriteConflict.java @@ -10,16 +10,19 @@ import refit.util.REFITTime; public class REZKTestClientReadWriteConflict extends REZKTestClient { private static final String[] paths = new String[REFITConfig.ACTIVE_NODES]; - static { - for (int i = 0; i < paths.length; i++) { - paths[i] = String.format("%s%05d", "/node", i); - } - } - private Random rand; public REZKTestClientReadWriteConflict(REFITClientLibrary service) { super(service); + + synchronized (paths) { + if (paths[0] == null) { + for (int i = 0; i < paths.length; i++) { + paths[i] = String.format("%s%05d", "/node", i); + } + } + } + rand = new Random(service.getNodeID()); } -- GitLab