diff --git a/java/jabushka/benchmarks/build.gradle b/java/jabushka/benchmarks/build.gradle index 5e21fe3ea6..733f6b79b8 100644 --- a/java/jabushka/benchmarks/build.gradle +++ b/java/jabushka/benchmarks/build.gradle @@ -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. diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java index c0341c8da3..579d84c9bc 100644 --- a/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java @@ -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; @@ -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() { @@ -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")) { @@ -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 actions = new HashMap<>(); actions.put(ChosenAction.GET_EXISTING, () -> jedisClient.get(Benchmarking.generateKeySet())); @@ -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 actions = new HashMap<>(); actions.put(ChosenAction.GET_EXISTING, () -> lettuceClient.get(Benchmarking.generateKeySet())); @@ -231,7 +208,7 @@ public boolean isEqual(String other) { public static class RunConfiguration { public String configuration; - public Optional resultsFile; + public String resultsFile; public List concurrentTasks; public ClientName clients; public String host; @@ -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"; diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Benchmarking.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Benchmarking.java index 182b062c99..acf8b8446f 100644 --- a/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Benchmarking.java +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Benchmarking.java @@ -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 { @@ -103,27 +101,11 @@ public static Map calculateResults( } public static void printResults( - Map calculatedResults, Optional resultsFile) - throws IOException { - if (resultsFile.isPresent()) { - printResults(calculatedResults, resultsFile.get()); - } else { - printResults(calculatedResults); - } - } - - public static void printResults( - Map resultsMap, FileWriter resultsFile) throws IOException { - for (Map.Entry 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 calculatedResults, String resultsFile) throws IOException { + if (resultsFile != null) { + Reporting.WriteJson(calculatedResults, resultsFile); } + printResults(calculatedResults); } public static void printResults(Map resultsMap) { diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Reporting.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Reporting.java new file mode 100644 index 0000000000..463e348fa8 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Reporting.java @@ -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 calculatedResults, String resultsFile) throws IOException { + + Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + Collection recordings = new ArrayList<>(); + + Path path = Path.of(resultsFile); + if (Files.exists(path)) { + TypeToken> 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; + } +}