From 06ca6b4e1598e980e8f2ab2fbac5356e4a83fd7e Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 16 Nov 2023 19:08:49 -0800 Subject: [PATCH] Rename2 Signed-off-by: Yury-Fridlyand --- .../clients/babushka/JniNettyClient.java | 5 +- .../benchmarks/utils/Benchmarking.java | 138 +++++++++--------- .../src/main/java/javababushka/Client.java | 3 +- java/src/lib.rs | 4 +- 4 files changed, 77 insertions(+), 73 deletions(-) diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniNettyClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniNettyClient.java index 1e2bb05201..a4fc37f4d9 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniNettyClient.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniNettyClient.java @@ -41,7 +41,10 @@ public void connectToRedis(ConnectionSettings connectionSettings) { @Override public Future asyncConnectToRedis(ConnectionSettings connectionSettings) { return testClient.asyncConnectToRedis( - connectionSettings.host, connectionSettings.port, connectionSettings.useSsl, connectionSettings.clusterMode); + connectionSettings.host, + connectionSettings.port, + connectionSettings.useSsl, + connectionSettings.clusterMode); } @Override diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/utils/Benchmarking.java b/java/benchmarks/src/main/java/javababushka/benchmarks/utils/Benchmarking.java index 440f93d2ca..5ea846c438 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/utils/Benchmarking.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/utils/Benchmarking.java @@ -1,5 +1,7 @@ package javababushka.benchmarks.utils; +import static java.util.concurrent.CompletableFuture.runAsync; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -7,22 +9,18 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.stream.Collectors; - import javababushka.benchmarks.BenchmarkingApp; import javababushka.benchmarks.clients.AsyncClient; import javababushka.benchmarks.clients.Client; import javababushka.benchmarks.clients.SyncClient; import org.apache.commons.lang3.tuple.Pair; -import static java.util.concurrent.CompletableFuture.runAsync; - /** Class to calculate latency on client-actions */ public class Benchmarking { static final double PROB_GET = 0.8; @@ -151,81 +149,83 @@ public static void printResults( } public static void testClientSetGet( - Supplier clientCreator, BenchmarkingApp.RunConfiguration config, boolean async) { + Supplier clientCreator, BenchmarkingApp.RunConfiguration config, boolean async) { for (int concurrentNum : config.concurrentTasks) { int iterations = - Math.min(Math.max(LATENCY_MIN, concurrentNum * LATENCY_MULTIPLIER), LATENCY_MAX); + Math.min(Math.max(LATENCY_MIN, concurrentNum * LATENCY_MULTIPLIER), LATENCY_MAX); for (int clientCount : config.clientCount) { for (int dataSize : config.dataSize) { AtomicInteger iterationCounter = new AtomicInteger(0); Map> actionResults = - Map.of( - ChosenAction.GET_EXISTING, new ArrayList<>(), - ChosenAction.GET_NON_EXISTING, new ArrayList<>(), - ChosenAction.SET, new ArrayList<>()); + Map.of( + ChosenAction.GET_EXISTING, new ArrayList<>(), + ChosenAction.GET_NON_EXISTING, new ArrayList<>(), + ChosenAction.SET, new ArrayList<>()); List tasks = new ArrayList<>(); // create clients List clients = new LinkedList<>(); for (int cc = 0; cc < clientCount; cc++) { Client newClient = clientCreator.get(); - newClient.connectToRedis(new ConnectionSettings(config.host, config.port, config.tls, config.clusterModeEnabled)); + newClient.connectToRedis( + new ConnectionSettings( + config.host, config.port, config.tls, config.clusterModeEnabled)); clients.add(newClient); } String clientName = clients.get(0).getName(); System.out.printf( - "%n =====> %s <===== %d clients %d concurrent %d data %n%n", - clientName, clientCount, concurrentNum, dataSize); + "%n =====> %s <===== %d clients %d concurrent %d data %n%n", + clientName, clientCount, concurrentNum, dataSize); for (int taskNum = 0; taskNum < concurrentNum; taskNum++) { final int taskNumDebugging = taskNum; tasks.add( - () -> { - int iterationIncrement = iterationCounter.getAndIncrement(); - int clientIndex = iterationIncrement % clients.size(); + () -> { + int iterationIncrement = iterationCounter.getAndIncrement(); + int clientIndex = iterationIncrement % clients.size(); - if (config.debugLogging) { - System.out.printf( - "%n concurrent = %d/%d, client# = %d/%d%n", - taskNumDebugging, concurrentNum, clientIndex + 1, clientCount); - } - while (iterationIncrement < iterations) { - if (config.debugLogging) { - System.out.printf( - "> task = %d, iteration = %d/%d, client# = %d/%d%n", - taskNumDebugging, - iterationIncrement + 1, - iterations, - clientIndex + 1, - clientCount); - } - var actions = getActionMap(clients.get(clientIndex), dataSize, async); - // operate and calculate tik-tok - Pair result = measurePerformance(actions); - if (config.debugLogging) { - System.out.printf( - "> task = %d, iteration = %d/%d, client# = %d/%d - DONE%n", - taskNumDebugging, - iterationIncrement + 1, - iterations, - clientIndex + 1, - clientCount); - } - if (result != null) { - actionResults.get(result.getLeft()).add(result.getRight()); - } - iterationIncrement = iterationCounter.getAndIncrement(); - } - }); + if (config.debugLogging) { + System.out.printf( + "%n concurrent = %d/%d, client# = %d/%d%n", + taskNumDebugging, concurrentNum, clientIndex + 1, clientCount); + } + while (iterationIncrement < iterations) { + if (config.debugLogging) { + System.out.printf( + "> task = %d, iteration = %d/%d, client# = %d/%d%n", + taskNumDebugging, + iterationIncrement + 1, + iterations, + clientIndex + 1, + clientCount); + } + var actions = getActionMap(clients.get(clientIndex), dataSize, async); + // operate and calculate tik-tok + Pair result = measurePerformance(actions); + if (config.debugLogging) { + System.out.printf( + "> task = %d, iteration = %d/%d, client# = %d/%d - DONE%n", + taskNumDebugging, + iterationIncrement + 1, + iterations, + clientIndex + 1, + clientCount); + } + if (result != null) { + actionResults.get(result.getLeft()).add(result.getRight()); + } + iterationIncrement = iterationCounter.getAndIncrement(); + } + }); } if (config.debugLogging) { System.out.printf("%s client Benchmarking: %n", clientName); System.out.printf( - "===> concurrentNum = %d, clientNum = %d, tasks = %d%n", - concurrentNum, clientCount, tasks.size()); + "===> concurrentNum = %d, clientNum = %d, tasks = %d%n", + concurrentNum, clientCount, tasks.size()); } long before = System.nanoTime(); ExecutorService threadPool = Executors.newFixedThreadPool(concurrentNum); @@ -233,9 +233,9 @@ public static void testClientSetGet( // create threads and add them to the async pool. // This will start execution of all the concurrent tasks. List asyncTasks = - tasks.stream() - .map((runnable) -> runAsync(runnable, threadPool)) - .collect(Collectors.toList()); + tasks.stream() + .map((runnable) -> runAsync(runnable, threadPool)) + .collect(Collectors.toList()); // close pool and await for tasks to complete threadPool.shutdown(); while (!threadPool.isTerminated()) { @@ -248,13 +248,13 @@ public static void testClientSetGet( } // wait for all futures to complete asyncTasks.forEach( - future -> { - try { - future.get(); - } catch (Exception e) { - e.printStackTrace(); - } - }); + future -> { + try { + future.get(); + } catch (Exception e) { + e.printStackTrace(); + } + }); long after = System.nanoTime(); clients.forEach(Client::closeConnection); @@ -262,14 +262,14 @@ public static void testClientSetGet( var calculatedResults = calculateResults(actionResults); if (config.resultsFile.isPresent()) { JsonWriter.Write( - calculatedResults, - config.resultsFile.get(), - config.clusterModeEnabled, - dataSize, - clientName, - clientCount, - concurrentNum, - iterations / ((after - before) / TPS_NORMALIZATION)); + calculatedResults, + config.resultsFile.get(), + config.clusterModeEnabled, + dataSize, + clientName, + clientCount, + concurrentNum, + iterations / ((after - before) / TPS_NORMALIZATION)); } printResults(calculatedResults, (after - before) / TPS_NORMALIZATION, iterations); try { diff --git a/java/client/src/main/java/javababushka/Client.java b/java/client/src/main/java/javababushka/Client.java index b42db3ae65..34760f7086 100644 --- a/java/client/src/main/java/javababushka/Client.java +++ b/java/client/src/main/java/javababushka/Client.java @@ -382,7 +382,8 @@ public Future asyncGet(String key) { .thenApply( response -> response.getRespPointer() != 0 - ? BabushkaCoreNativeDefinitions.valueFromPointer(response.getRespPointer()).toString() + ? BabushkaCoreNativeDefinitions.valueFromPointer(response.getRespPointer()) + .toString() : null); } diff --git a/java/src/lib.rs b/java/src/lib.rs index cef7526b5a..aa29e734f5 100644 --- a/java/src/lib.rs +++ b/java/src/lib.rs @@ -38,7 +38,7 @@ fn redis_value_to_java(mut env: JNIEnv, val: Value) -> JObject { } #[no_mangle] -pub extern "system" fn Java_javababushka_RustWrapper_valueFromPointer<'local>( +pub extern "system" fn Java_javababushka_BabushkaCoreNativeDefinitions_valueFromPointer<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, pointer: jlong @@ -48,7 +48,7 @@ pub extern "system" fn Java_javababushka_RustWrapper_valueFromPointer<'local>( } #[no_mangle] -pub extern "system" fn Java_javababushka_RustWrapper_startSocketListenerExternal<'local>( +pub extern "system" fn Java_javababushka_BabushkaCoreNativeDefinitions_startSocketListenerExternal<'local>( mut env: JNIEnv<'local>, _class: JClass<'local> ) -> JObject<'local> {