Skip to content

Commit

Permalink
Add json reporting.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Sep 22, 2023
1 parent 9817802 commit 94441e2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 50 deletions.
4 changes: 4 additions & 0 deletions java/jabushka/benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ dependencies {
implementation 'redis.clients:jedis:4.4.3'
implementation 'io.lettuce:lettuce-core:6.2.6.RELEASE'
implementation 'commons-cli:commons-cli:1.5.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'

compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
}

// Apply a specific Java toolchain to ease working on different environments.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package javabushka.client;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javabushka.client.jedis.JedisClient;
import javabushka.client.lettuce.LettuceAsyncClient;
Expand Down Expand Up @@ -58,14 +56,6 @@ public static void main(String[] args) {
System.out.println("Error writing to results file");
ioException.printStackTrace();
}

if (runConfiguration.resultsFile.isPresent()) {
try {
runConfiguration.resultsFile.get().close();
} catch (IOException ioException) {
System.out.println("Error closing results file");
}
}
}

private static Options getOptions() {
Expand Down Expand Up @@ -96,12 +86,7 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
}

if (line.hasOption("resultsFile")) {
try {
runConfiguration.resultsFile =
Optional.of(new FileWriter(line.getOptionValue("resultsFile")));
} catch (IOException e) {
throw new ParseException("Unable to write to resultsFile.");
}
runConfiguration.resultsFile = line.getOptionValue("resultsFile");
}

if (line.hasOption("concurrentTasks")) {
Expand Down Expand Up @@ -160,11 +145,7 @@ private static void testJedisClientResourceSetGet(RunConfiguration runConfigurat
int iterations = 100000;
String value = "my-value";

if (runConfiguration.resultsFile.isPresent()) {
runConfiguration.resultsFile.get().write("JEDIS client Benchmarking: ");
} else {
System.out.println("JEDIS client Benchmarking: ");
}
System.out.println("JEDIS client Benchmarking: ");

Map<ChosenAction, Benchmarking.Operation> actions = new HashMap<>();
actions.put(ChosenAction.GET_EXISTING, () -> jedisClient.get(Benchmarking.generateKeySet()));
Expand All @@ -190,11 +171,7 @@ private static void testLettuceClientResourceSetGet(RunConfiguration runConfigur
int iterations = 100000;
String value = "my-value";

if (runConfiguration.resultsFile.isPresent()) {
runConfiguration.resultsFile.get().write("LETTUCE client Benchmarking: ");
} else {
System.out.println("LETTUCE client Benchmarking: ");
}
System.out.println("LETTUCE client Benchmarking: ");

HashMap<ChosenAction, Benchmarking.Operation> actions = new HashMap<>();
actions.put(ChosenAction.GET_EXISTING, () -> lettuceClient.get(Benchmarking.generateKeySet()));
Expand Down Expand Up @@ -231,7 +208,7 @@ public boolean isEqual(String other) {

public static class RunConfiguration {
public String configuration;
public Optional<FileWriter> resultsFile;
public String resultsFile;
public List<Integer> concurrentTasks;
public ClientName clients;
public String host;
Expand All @@ -241,7 +218,7 @@ public static class RunConfiguration {

public RunConfiguration() {
configuration = "Release";
resultsFile = Optional.empty();
resultsFile = null;
concurrentTasks = List.of(1, 10, 100);
clients = ClientName.ALL;
host = "localhost";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package javabushka.client.utils;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class Benchmarking {
Expand Down Expand Up @@ -103,27 +101,11 @@ public static Map<ChosenAction, LatencyResults> calculateResults(
}

public static void printResults(
Map<ChosenAction, LatencyResults> calculatedResults, Optional<FileWriter> resultsFile)
throws IOException {
if (resultsFile.isPresent()) {
printResults(calculatedResults, resultsFile.get());
} else {
printResults(calculatedResults);
}
}

public static void printResults(
Map<ChosenAction, LatencyResults> resultsMap, FileWriter resultsFile) throws IOException {
for (Map.Entry<ChosenAction, LatencyResults> entry : resultsMap.entrySet()) {
ChosenAction action = entry.getKey();
LatencyResults results = entry.getValue();

resultsFile.write("Avg. time in ms per " + action + ": " + results.avgLatency / 1000000.0);
resultsFile.write(action + " p50 latency in ms: " + results.p50Latency / 1000000.0);
resultsFile.write(action + " p90 latency in ms: " + results.p90Latency / 1000000.0);
resultsFile.write(action + " p99 latency in ms: " + results.p99Latency / 1000000.0);
resultsFile.write(action + " std dev in ms: " + results.stdDeviation / 1000000.0);
Map<ChosenAction, LatencyResults> calculatedResults, String resultsFile) throws IOException {
if (resultsFile != null) {
Reporting.WriteJson(calculatedResults, resultsFile);
}
printResults(calculatedResults);
}

public static void printResults(Map<ChosenAction, LatencyResults> resultsMap) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package javabushka.client.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import lombok.Getter;

public class Reporting {

public static void WriteJson(
Map<ChosenAction, LatencyResults> calculatedResults, String resultsFile) throws IOException {

Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
Collection<Measurements> recordings = new ArrayList<>();

Path path = Path.of(resultsFile);
if (Files.exists(path)) {
TypeToken<Collection<Measurements>> collectionType = new TypeToken<>() {};
var json = new String(Files.readAllBytes(path));
recordings = gson.fromJson(json, collectionType);
}
var data = new Measurements();
// TODO: data_size, client, clientCount, num_of_tasks, is_cluster, tps
data.get_existing_average_latency = calculatedResults.get(ChosenAction.GET_EXISTING).avgLatency;
data.get_existing_p50_latency = calculatedResults.get(ChosenAction.GET_EXISTING).p50Latency;
data.get_existing_p90_latency = calculatedResults.get(ChosenAction.GET_EXISTING).p90Latency;
data.get_existing_p99_latency = calculatedResults.get(ChosenAction.GET_EXISTING).p99Latency;
data.get_existing_std_dev = calculatedResults.get(ChosenAction.GET_EXISTING).stdDeviation;

data.get_non_existing_average_latency =
calculatedResults.get(ChosenAction.GET_NON_EXISTING).avgLatency;
data.get_non_existing_p50_latency =
calculatedResults.get(ChosenAction.GET_NON_EXISTING).p50Latency;
data.get_non_existing_p90_latency =
calculatedResults.get(ChosenAction.GET_NON_EXISTING).p90Latency;
data.get_non_existing_p99_latency =
calculatedResults.get(ChosenAction.GET_NON_EXISTING).p99Latency;
data.get_non_existing_std_dev =
calculatedResults.get(ChosenAction.GET_NON_EXISTING).stdDeviation;

data.set_average_latency = calculatedResults.get(ChosenAction.SET).avgLatency;
data.set_p50_latency = calculatedResults.get(ChosenAction.SET).p50Latency;
data.set_p90_latency = calculatedResults.get(ChosenAction.SET).p90Latency;
data.set_p99_latency = calculatedResults.get(ChosenAction.SET).p99Latency;
data.set_std_dev = calculatedResults.get(ChosenAction.SET).stdDeviation;

recordings.add(data);

Files.write(path, gson.toJson(recordings).getBytes());
}

@Getter
public static class Measurements {
private String client;
private int clientCount;
private int data_size;
private double get_existing_average_latency;
private double get_existing_p50_latency;
private double get_existing_p90_latency;
private double get_existing_p99_latency;
private double get_existing_std_dev;
private double get_non_existing_average_latency;
private double get_non_existing_p50_latency;
private double get_non_existing_p90_latency;
private double get_non_existing_p99_latency;
private double get_non_existing_std_dev;
private boolean is_cluster;
private int num_of_tasks;
private double set_average_latency;
private double set_p50_latency;
private double set_p90_latency;
private double set_p99_latency;
private double set_std_dev;
private double tps;
}
}

0 comments on commit 94441e2

Please sign in to comment.