Skip to content

Commit

Permalink
Address PR feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Oct 16, 2023
1 parent de0cd49 commit 8544807
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Benchmarking {
static final int SIZE_GET_KEYSPACE = 3750000;
static final int SIZE_SET_KEYSPACE = 3000000;
static final int ASYNC_OPERATION_TIMEOUT_SEC = 1;
// measurements are done in nanosec, but it should be converted to seconts later
static final double SECONDS_IN_NANO = 1e-9;

private static ChosenAction randomAction() {
if (Math.random() > PROB_GET) {
Expand All @@ -47,7 +49,7 @@ public interface Operation {
void go() throws Exception;
}

public static Pair<ChosenAction, Long> getLatency(Map<ChosenAction, Operation> actions) {
public static Pair<ChosenAction, Long> measurePerformance(Map<ChosenAction, Operation> actions) {
var action = randomAction();
long before = System.nanoTime();
try {
Expand Down Expand Up @@ -88,17 +90,17 @@ public static Map<ChosenAction, LatencyResults> calculateResults(
ArrayList<Long> latencies = entry.getValue();

double avgLatency =
1e-9 * latencies.stream().mapToLong(Long::longValue).sum() / latencies.size();
SECONDS_IN_NANO * latencies.stream().mapToLong(Long::longValue).sum() / latencies.size();

Collections.sort(latencies);
results.put(
action,
new LatencyResults(
avgLatency,
1e-9 * percentile(latencies, 50),
1e-9 * percentile(latencies, 90),
1e-9 * percentile(latencies, 99),
1e-9 * stdDeviation(latencies, avgLatency)));
SECONDS_IN_NANO * percentile(latencies, 50),
SECONDS_IN_NANO * percentile(latencies, 90),
SECONDS_IN_NANO * percentile(latencies, 99),
SECONDS_IN_NANO * stdDeviation(latencies, avgLatency)));
}

return results;
Expand Down Expand Up @@ -159,9 +161,10 @@ public static void testClientSetGet(
"> iteration = %d/%d, client# = %d/%d%n",
iterationIncrement + 1, iterations, clientIndex + 1, clientCount);
}

var actions = getActionMap(clients.get(clientIndex), config.dataSize, async);
// operate and calculate tik-tok
Pair<ChosenAction, Long> result =
measurePerformance(clients.get(clientIndex), config.dataSize, async);
Pair<ChosenAction, Long> result = measurePerformance(actions);
actionResults.get(result.getLeft()).add(result.getRight());

iterationIncrement = iterationCounter.getAndIncrement();
Expand All @@ -188,7 +191,7 @@ public static void testClientSetGet(

var calculatedResults = calculateResults(actionResults);
if (config.resultsFile != null) {
Reporting.WriteJson(
JsonWriter.WriteJson(
calculatedResults,
config.resultsFile,
config.dataSize,
Expand All @@ -204,7 +207,7 @@ public static void testClientSetGet(
System.out.println();
}

public static Pair<ChosenAction, Long> measurePerformance(
public static Map<ChosenAction, Operation> getActionMap(
Client client, int dataSize, boolean async) {

String value = RandomStringUtils.randomAlphanumeric(dataSize);
Expand Down Expand Up @@ -233,7 +236,6 @@ public static Pair<ChosenAction, Long> measurePerformance(
.asyncSet(generateKeySet(), value)
.get(ASYNC_OPERATION_TIMEOUT_SEC, TimeUnit.SECONDS)
: () -> ((SyncClient) client).set(generateKeySet(), value));

return getLatency(actions);
return actions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Map;
import lombok.Getter;

public class Reporting {
public class JsonWriter {

public static void WriteJson(
Map<ChosenAction, LatencyResults> calculatedResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testResourceSetGet() {
ChosenAction.GET_NON_EXISTING, new ArrayList<>(),
ChosenAction.SET, new ArrayList<>());
for (int i = 0; i < iterations; i++) {
var latency = Benchmarking.getLatency(actions);
var latency = Benchmarking.measurePerformance(actions);
latencies.get(latency.getKey()).add(latency.getValue());
}

Expand Down

0 comments on commit 8544807

Please sign in to comment.