diff --git a/benchmarks/install_and_test.sh b/benchmarks/install_and_test.sh index ecccf0a737..28c88178ae 100755 --- a/benchmarks/install_and_test.sh +++ b/benchmarks/install_and_test.sh @@ -271,7 +271,7 @@ do runJavaBenchmark $javaResults $currentDataSize fi - if [ $runAllBenchmarks == 1 ] || [ $runRust == 1 ]; + if [ $runAllBenchmarks == 1 ] || [ $runRust == 1 ]; then rustResults=$(resultFileName rust $currentDataSize) resultFiles+=$rustResults" " @@ -279,8 +279,6 @@ do fi done - - flushDB if [ $writeResultsCSV == 1 ]; diff --git a/java/.cargo/config.toml b/java/.cargo/config.toml new file mode 100644 index 0000000000..24a6f21533 --- /dev/null +++ b/java/.cargo/config.toml @@ -0,0 +1,3 @@ +[env] +BABUSHKA_NAME = { value = "BabushkaPy", force = true } +BABUSHKA_VERSION = "0.1.0" diff --git a/java/Cargo.toml b/java/Cargo.toml new file mode 100644 index 0000000000..ccde88c26d --- /dev/null +++ b/java/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "jabushka" +version = "0.0.0" +edition = "2021" +license = "BSD-3-Clause" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "jabushka" +crate-type = ["cdylib"] + +[dependencies] +redis = { path = "../submodules/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager", "tls", "tokio-rustls-comp"] } +babushka = { path = "../babushka-core" } +tokio = { version = "^1", features = ["rt", "macros", "rt-multi-thread", "time"] } +logger_core = {path = "../logger_core"} +tracing-subscriber = "0.3.16" + +[profile.release] +lto = true +debug = true diff --git a/java/jabushka/benchmarks/build.gradle b/java/jabushka/benchmarks/build.gradle new file mode 100644 index 0000000000..b6c89b2695 --- /dev/null +++ b/java/jabushka/benchmarks/build.gradle @@ -0,0 +1,41 @@ +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'application' +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + // Use JUnit test framework. + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2' + + // This dependency is used internally, and not exposed to consumers on their own compile classpath. + implementation 'com.google.guava:guava:32.1.1-jre' + 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: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +application { + // Define the main class for the application. + mainClass = 'javabushka.client.BenchmarkingApp' +} + +tasks.withType(Test) { + testLogging { + exceptionFormat "full" + events "started", "skipped", "passed", "failed" + showStandardStreams true + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/AsyncClient.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/AsyncClient.java new file mode 100644 index 0000000000..da06e6b234 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/AsyncClient.java @@ -0,0 +1,16 @@ +package javabushka.client; + +import java.util.concurrent.Future; + +public interface AsyncClient extends Client { + + long DEFAULT_TIMEOUT = 1000; + + Future asyncSet(String key, String value); + + Future asyncGet(String key); + + T waitForResult(Future future); + + T waitForResult(Future future, long timeout); +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java new file mode 100644 index 0000000000..6f8f23f1f9 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/BenchmarkingApp.java @@ -0,0 +1,228 @@ +package javabushka.client; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import javabushka.client.jedis.JedisClient; +import javabushka.client.jedis.JedisPseudoAsyncClient; +import javabushka.client.lettuce.LettuceAsyncClient; +import javabushka.client.lettuce.LettuceClient; +import javabushka.client.utils.Benchmarking; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + +/** Benchmarking app for reporting performance of various redis-rs Java-clients */ +public class BenchmarkingApp { + + // main application entrypoint + public static void main(String[] args) { + + // create the parser + CommandLineParser parser = new DefaultParser(); + Options options = getOptions(); + RunConfiguration runConfiguration = new RunConfiguration(); + try { + // parse the command line arguments + CommandLine line = parser.parse(options, args); + runConfiguration = verifyOptions(line); + } catch (ParseException exp) { + // oops, something went wrong + System.err.println("Parsing failed. Reason: " + exp.getMessage()); + } + + for (ClientName client : runConfiguration.clients) { + switch (client) { + case ALL: + testClientSetGet(new JedisClient(), runConfiguration); + testClientSetGet(new LettuceClient(), runConfiguration); + testAsyncClientSetGet(new JedisPseudoAsyncClient(), runConfiguration); + testAsyncClientSetGet(new LettuceAsyncClient(), runConfiguration); + System.out.println("Babushka not yet configured"); + break; + case ALL_ASYNC: + testAsyncClientSetGet(new JedisPseudoAsyncClient(), runConfiguration); + testAsyncClientSetGet(new LettuceAsyncClient(), runConfiguration); + System.out.println("Babushka not yet configured"); + break; + case ALL_SYNC: + testClientSetGet(new JedisClient(), runConfiguration); + testClientSetGet(new LettuceClient(), runConfiguration); + System.out.println("Babushka not yet configured"); + break; + case JEDIS: + testClientSetGet(new JedisClient(), runConfiguration); + break; + case JEDIS_ASYNC: + testAsyncClientSetGet(new JedisPseudoAsyncClient(), runConfiguration); + break; + case LETTUCE: + testClientSetGet(new LettuceClient(), runConfiguration); + break; + case LETTUCE_ASYNC: + testAsyncClientSetGet(new LettuceAsyncClient(), runConfiguration); + break; + case BABUSHKA: + System.out.println("Babushka not yet configured"); + break; + } + } + + if (runConfiguration.resultsFile.isPresent()) { + try { + runConfiguration.resultsFile.get().close(); + } catch (IOException ioException) { + System.out.println("Error closing results file"); + } + } + } + + private static Options getOptions() { + // create the Options + Options options = new Options(); + + options.addOption("c", "configuration", true, "Configuration flag [Release]"); + options.addOption("f", "resultsFile", true, "Result filepath []"); + options.addOption("d", "dataSize", true, "Data block size [20]"); + options.addOption("C", "concurrentTasks", true, "Number of concurrent tasks [1 10 100]"); + options.addOption("l", "clients", true, "one of: all|jedis|lettuce|babushka [all]"); + options.addOption("h", "host", true, "host url [localhost]"); + options.addOption("p", "port", true, "port number [6379]"); + options.addOption("n", "clientCount", true, "Client count [1]"); + options.addOption("t", "tls", false, "TLS [true]"); + + return options; + } + + private static RunConfiguration verifyOptions(CommandLine line) throws ParseException { + RunConfiguration runConfiguration = new RunConfiguration(); + if (line.hasOption("configuration")) { + String configuration = line.getOptionValue("configuration"); + if (configuration.equalsIgnoreCase("Release") || configuration.equalsIgnoreCase("Debug")) { + runConfiguration.configuration = configuration; + } else { + throw new ParseException("Invalid run configuration (Release|Debug)"); + } + } + + 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."); + } + } + + if (line.hasOption("dataSize")) { + runConfiguration.dataSize = Integer.parseInt(line.getOptionValue("dataSize")); + } + + if (line.hasOption("concurrentTasks")) { + String concurrentTasks = line.getOptionValue("concurrentTasks"); + + // remove optional square brackets + if (concurrentTasks.startsWith("[") && concurrentTasks.endsWith("]")) { + concurrentTasks = concurrentTasks.substring(1, concurrentTasks.length() - 1); + } + // check if it's the correct format + if (!concurrentTasks.matches("\\d+(\\s+\\d+)?")) { + throw new ParseException("Invalid concurrentTasks"); + } + // split the string into a list of integers + runConfiguration.concurrentTasks = + Arrays.stream(concurrentTasks.split("\\s+")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + } + + if (line.hasOption("clients")) { + String[] clients = line.getOptionValue("clients").split(","); + runConfiguration.clients = + Arrays.stream(clients) + .map(c -> Enum.valueOf(ClientName.class, c.toUpperCase())) + .toArray(ClientName[]::new); + } + + if (line.hasOption("host")) { + runConfiguration.host = line.getOptionValue("host"); + } + + if (line.hasOption("clientCount")) { + runConfiguration.clientCount = Integer.parseInt(line.getOptionValue("clientCount")); + } + + if (line.hasOption("tls")) { + runConfiguration.tls = Boolean.parseBoolean(line.getOptionValue("tls")); + } + + return runConfiguration; + } + + private static void testClientSetGet(Client client, RunConfiguration runConfiguration) { + System.out.printf("%n =====> %s <===== %n%n", client.getName()); + Benchmarking.printResults(Benchmarking.measurePerformance(client, runConfiguration, false)); + System.out.println(); + } + + private static void testAsyncClientSetGet(AsyncClient client, RunConfiguration runConfiguration) { + System.out.printf("%n =====> %s <===== %n%n", client.getName()); + Benchmarking.printResults(Benchmarking.measurePerformance(client, runConfiguration, true)); + System.out.println(); + } + + public enum ClientName { + JEDIS("Jedis"), + JEDIS_ASYNC("Jedis async"), + LETTUCE("Lettuce"), + LETTUCE_ASYNC("Lettuce async"), + BABUSHKA("Babushka"), + ALL("All"), + ALL_SYNC("All sync"), + ALL_ASYNC("All async"); + + private String name; + + private ClientName(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + + public boolean isEqual(String other) { + return this.toString().equalsIgnoreCase(other); + } + } + + public static class RunConfiguration { + public String configuration; + public Optional resultsFile; + public int dataSize; + public List concurrentTasks; + public ClientName[] clients; + public String host; + public int port; + public int clientCount; + public boolean tls; + + public RunConfiguration() { + configuration = "Release"; + resultsFile = Optional.empty(); + dataSize = 20; + concurrentTasks = List.of(1, 10, 100); + clients = new ClientName[] {ClientName.ALL}; + host = "localhost"; + port = 6379; + clientCount = 1; + tls = false; + } + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/Client.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/Client.java new file mode 100644 index 0000000000..91b97b56cd --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/Client.java @@ -0,0 +1,13 @@ +package javabushka.client; + +import javabushka.client.utils.ConnectionSettings; + +public interface Client { + void connectToRedis(); + + void connectToRedis(ConnectionSettings connectionSettings); + + default void closeConnection() {} + + String getName(); +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/SyncClient.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/SyncClient.java new file mode 100644 index 0000000000..f14bdce5e1 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/SyncClient.java @@ -0,0 +1,7 @@ +package javabushka.client; + +public interface SyncClient extends Client { + void set(String key, String value); + + String get(String key); +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/jedis/JedisClient.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/jedis/JedisClient.java new file mode 100644 index 0000000000..30ba659b87 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/jedis/JedisClient.java @@ -0,0 +1,65 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javabushka.client.jedis; + +import javabushka.client.SyncClient; +import javabushka.client.utils.ConnectionSettings; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +public class JedisClient implements SyncClient { + + public static final String DEFAULT_HOST = "localhost"; + public static final int DEFAULT_PORT = 6379; + + protected Jedis jedisResource; + + public boolean someLibraryMethod() { + return true; + } + + @Override + public void connectToRedis() { + JedisPool pool = new JedisPool(DEFAULT_HOST, DEFAULT_PORT); + jedisResource = pool.getResource(); + } + + @Override + public void closeConnection() { + try { + jedisResource.close(); + } catch (Exception ignored) { + } + } + + @Override + public String getName() { + return "Jedis"; + } + + @Override + public void connectToRedis(ConnectionSettings connectionSettings) { + jedisResource = + new Jedis(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); + jedisResource.connect(); + } + + public String info() { + return jedisResource.info(); + } + + public String info(String section) { + return jedisResource.info(section); + } + + @Override + public void set(String key, String value) { + jedisResource.set(key, value); + } + + @Override + public String get(String key) { + return jedisResource.get(key); + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/jedis/JedisPseudoAsyncClient.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/jedis/JedisPseudoAsyncClient.java new file mode 100644 index 0000000000..2f6bcd7611 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/jedis/JedisPseudoAsyncClient.java @@ -0,0 +1,39 @@ +package javabushka.client.jedis; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import javabushka.client.AsyncClient; + +// Jedis doesn't provide async API +// https://github.com/redis/jedis/issues/241 +public class JedisPseudoAsyncClient extends JedisClient implements AsyncClient { + @Override + public Future asyncSet(String key, String value) { + return CompletableFuture.runAsync(() -> super.set(key, value)); + } + + @Override + public Future asyncGet(String key) { + return CompletableFuture.supplyAsync(() -> super.get(key)); + } + + @Override + public T waitForResult(Future future) { + return waitForResult(future, DEFAULT_TIMEOUT); + } + + @Override + public T waitForResult(Future future, long timeout) { + try { + return future.get(timeout, TimeUnit.MILLISECONDS); + } catch (Exception ignored) { + return null; + } + } + + @Override + public String getName() { + return "Jedis pseudo-async"; + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/lettuce/LettuceAsyncClient.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/lettuce/LettuceAsyncClient.java new file mode 100644 index 0000000000..f93ae104d1 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/lettuce/LettuceAsyncClient.java @@ -0,0 +1,73 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javabushka.client.lettuce; + +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.async.RedisAsyncCommands; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import javabushka.client.AsyncClient; +import javabushka.client.utils.ConnectionSettings; + +public class LettuceAsyncClient implements AsyncClient { + + RedisClient client; + RedisAsyncCommands asyncCommands; + StatefulRedisConnection connection; + + @Override + public void connectToRedis() { + connectToRedis(new ConnectionSettings("localhost", 6379, false)); + } + + @Override + public void connectToRedis(ConnectionSettings connectionSettings) { + client = + RedisClient.create( + String.format( + "%s://%s:%d", + connectionSettings.useSsl ? "rediss" : "redis", + connectionSettings.host, + connectionSettings.port)); + connection = client.connect(); + asyncCommands = connection.async(); + } + + @Override + public RedisFuture asyncSet(String key, String value) { + return asyncCommands.set(key, value); + } + + @Override + public RedisFuture asyncGet(String key) { + return asyncCommands.get(key); + } + + @Override + public Object waitForResult(Future future) { + return waitForResult(future, DEFAULT_TIMEOUT); + } + + @Override + public Object waitForResult(Future future, long timeoutMS) { + try { + return future.get(timeoutMS, TimeUnit.MILLISECONDS); + } catch (Exception ignored) { + return null; + } + } + + @Override + public void closeConnection() { + connection.close(); + client.shutdown(); + } + + @Override + public String getName() { + return "Lettuce Async"; + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/lettuce/LettuceClient.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/lettuce/LettuceClient.java new file mode 100644 index 0000000000..6fa237666d --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/lettuce/LettuceClient.java @@ -0,0 +1,56 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javabushka.client.lettuce; + +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.RedisStringCommands; +import javabushka.client.SyncClient; +import javabushka.client.utils.ConnectionSettings; + +public class LettuceClient implements SyncClient { + + RedisClient client; + RedisStringCommands syncCommands; + StatefulRedisConnection connection; + + @Override + public void connectToRedis() { + connectToRedis(new ConnectionSettings("localhost", 6379, false)); + } + + @Override + public void connectToRedis(ConnectionSettings connectionSettings) { + client = + RedisClient.create( + String.format( + "%s://%s:%d", + connectionSettings.useSsl ? "rediss" : "redis", + connectionSettings.host, + connectionSettings.port)); + connection = client.connect(); + syncCommands = connection.sync(); + } + + @Override + public void set(String key, String value) { + syncCommands.set(key, value); + } + + @Override + public String get(String key) { + return (String) syncCommands.get(key); + } + + @Override + public void closeConnection() { + connection.close(); + client.shutdown(); + } + + @Override + public String getName() { + return "Lettuce"; + } +} 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 new file mode 100644 index 0000000000..9555bba2cc --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/Benchmarking.java @@ -0,0 +1,190 @@ +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; +import javabushka.client.AsyncClient; +import javabushka.client.BenchmarkingApp; +import javabushka.client.Client; +import javabushka.client.SyncClient; +import org.apache.commons.lang3.RandomStringUtils; + +public class Benchmarking { + static final double PROB_GET = 0.8; + static final double PROB_GET_EXISTING_KEY = 0.8; + static final int SIZE_GET_KEYSPACE = 3750000; + static final int SIZE_SET_KEYSPACE = 3000000; + + private static ChosenAction randomAction() { + if (Math.random() > PROB_GET) { + return ChosenAction.SET; + } + if (Math.random() > PROB_GET_EXISTING_KEY) { + return ChosenAction.GET_NON_EXISTING; + } + return ChosenAction.GET_EXISTING; + } + + public static String generateKeyGet() { + int range = SIZE_GET_KEYSPACE - SIZE_SET_KEYSPACE; + return Math.floor(Math.random() * range + SIZE_SET_KEYSPACE + 1) + ""; + } + + public static String generateKeySet() { + return (Math.floor(Math.random() * SIZE_SET_KEYSPACE) + 1) + ""; + } + + public interface Operation { + void go(); + } + + public static Map> getLatencies( + int iterations, Map actions) { + Map> latencies = new HashMap>(); + for (ChosenAction action : actions.keySet()) { + latencies.put(action, new ArrayList()); + } + + for (int i = 0; i < iterations; i++) { + ChosenAction action = randomAction(); + Operation op = actions.get(action); + ArrayList actionLatencies = latencies.get(action); + addLatency(op, actionLatencies); + } + + return latencies; + } + + private static void addLatency(Operation op, ArrayList latencies) { + long before = System.nanoTime(); + op.go(); + long after = System.nanoTime(); + latencies.add(after - before); + } + + // Assumption: latencies is sorted in ascending order + private static Long percentile(ArrayList latencies, int percentile) { + int N = latencies.size(); + double n = (N - 1) * percentile / 100. + 1; + if (n == 1d) return latencies.get(0); + else if (n == N) return latencies.get(N - 1); + int k = (int) n; + double d = n - k; + return Math.round(latencies.get(k - 1) + d * (latencies.get(k) - latencies.get(k - 1))); + } + + private static double stdDeviation(ArrayList latencies, Double avgLatency) { + double stdDeviation = + latencies.stream() + .mapToDouble(Long::doubleValue) + .reduce(0.0, (stdDev, latency) -> stdDev + Math.pow(latency - avgLatency, 2)); + return Math.sqrt(stdDeviation / latencies.size()); + } + + // This has the side-effect of sorting each latencies ArrayList + public static Map calculateResults( + Map> actionLatencies) { + Map results = new HashMap(); + + for (Map.Entry> entry : actionLatencies.entrySet()) { + ChosenAction action = entry.getKey(); + ArrayList latencies = entry.getValue(); + + Double avgLatency = + latencies.stream().collect(Collectors.summingLong(Long::longValue)) + / Double.valueOf(latencies.size()); + + Collections.sort(latencies); + results.put( + action, + new LatencyResults( + avgLatency, + percentile(latencies, 50), + percentile(latencies, 90), + percentile(latencies, 99), + stdDeviation(latencies, avgLatency))); + } + + return results; + } + + 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); + } + } + + public static void printResults(Map resultsMap) { + for (Map.Entry entry : resultsMap.entrySet()) { + ChosenAction action = entry.getKey(); + LatencyResults results = entry.getValue(); + + System.out.println("Avg. time in ms per " + action + ": " + results.avgLatency / 1000000.0); + System.out.println(action + " p50 latency in ms: " + results.p50Latency / 1000000.0); + System.out.println(action + " p90 latency in ms: " + results.p90Latency / 1000000.0); + System.out.println(action + " p99 latency in ms: " + results.p99Latency / 1000000.0); + System.out.println(action + " std dev in ms: " + results.stdDeviation / 1000000.0); + } + } + + public static Map measurePerformance( + Client client, BenchmarkingApp.RunConfiguration config, boolean async) { + client.connectToRedis(new ConnectionSettings(config.host, config.port, config.tls)); + + int iterations = 10000; + String value = RandomStringUtils.randomAlphanumeric(config.dataSize); + + if (config.resultsFile.isPresent()) { + try { + config.resultsFile.get().write(client.getName() + " client Benchmarking: "); + } catch (Exception ignored) { + } + } else { + System.out.printf("%s client Benchmarking: %n", client.getName()); + } + + Map actions = new HashMap<>(); + actions.put( + ChosenAction.GET_EXISTING, + async + ? () -> ((AsyncClient) client).asyncGet(Benchmarking.generateKeySet()) + : () -> ((SyncClient) client).get(Benchmarking.generateKeySet())); + actions.put( + ChosenAction.GET_NON_EXISTING, + async + ? () -> ((AsyncClient) client).asyncGet(Benchmarking.generateKeyGet()) + : () -> ((SyncClient) client).get(Benchmarking.generateKeyGet())); + actions.put( + ChosenAction.SET, + async + ? () -> ((AsyncClient) client).asyncSet(Benchmarking.generateKeySet(), value) + : () -> ((SyncClient) client).set(Benchmarking.generateKeySet(), value)); + + var results = Benchmarking.calculateResults(Benchmarking.getLatencies(iterations, actions)); + client.closeConnection(); + return results; + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/ChosenAction.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/ChosenAction.java new file mode 100644 index 0000000000..0bded99ddc --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/ChosenAction.java @@ -0,0 +1,7 @@ +package javabushka.client.utils; + +public enum ChosenAction { + GET_NON_EXISTING, + GET_EXISTING, + SET +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/ConnectionSettings.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/ConnectionSettings.java new file mode 100644 index 0000000000..725f604ce7 --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/ConnectionSettings.java @@ -0,0 +1,13 @@ +package javabushka.client.utils; + +public class ConnectionSettings { + public String host; + public int port; + public boolean useSsl; + + public ConnectionSettings(String host, int port, boolean useSsl) { + this.host = host; + this.port = port; + this.useSsl = useSsl; + } +} diff --git a/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/LatencyResults.java b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/LatencyResults.java new file mode 100644 index 0000000000..d81deaa7fe --- /dev/null +++ b/java/jabushka/benchmarks/src/main/java/javabushka/client/utils/LatencyResults.java @@ -0,0 +1,19 @@ +package javabushka.client.utils; + +// Raw timing results in nanoseconds +public class LatencyResults { + public final double avgLatency; + public final long p50Latency; + public final long p90Latency; + public final long p99Latency; + public final double stdDeviation; + + public LatencyResults( + double avgLatency, long p50Latency, long p90Latency, long p99Latency, double stdDeviation) { + this.avgLatency = avgLatency; + this.p50Latency = p50Latency; + this.p90Latency = p90Latency; + this.p99Latency = p99Latency; + this.stdDeviation = stdDeviation; + } +} diff --git a/java/jabushka/benchmarks/src/test/java/javabushka/client/jedis/JedisClientIT.java b/java/jabushka/benchmarks/src/test/java/javabushka/client/jedis/JedisClientIT.java new file mode 100644 index 0000000000..09a0e7ef35 --- /dev/null +++ b/java/jabushka/benchmarks/src/test/java/javabushka/client/jedis/JedisClientIT.java @@ -0,0 +1,61 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javabushka.client.jedis; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.HashMap; +import java.util.Map; +import javabushka.client.utils.Benchmarking; +import javabushka.client.utils.ChosenAction; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class JedisClientIT { + + private static JedisClient jedisClient; + + @BeforeAll + static void initializeJedisClient() { + jedisClient = new JedisClient(); + jedisClient.connectToRedis(); + } + + @Test + public void someLibraryMethodReturnsTrue() { + JedisClient classUnderTest = new JedisClient(); + assertTrue(classUnderTest.someLibraryMethod(), "someLibraryMethod should return 'true'"); + } + + @Test + public void testResourceInfo() { + String result = jedisClient.info(); + + assertTrue(result.length() > 0); + } + + @Test + public void testResourceInfoBySection() { + String section = "Server"; + String result = jedisClient.info(section); + + assertTrue(result.length() > 0); + assertTrue(result.startsWith("# " + section)); + } + + @Test + public void testResourceSetGet() { + int iterations = 100000; + String value = "my-value"; + + Map actions = new HashMap<>(); + actions.put(ChosenAction.GET_EXISTING, () -> jedisClient.get(Benchmarking.generateKeySet())); + actions.put( + ChosenAction.GET_NON_EXISTING, () -> jedisClient.get(Benchmarking.generateKeyGet())); + actions.put(ChosenAction.SET, () -> jedisClient.set(Benchmarking.generateKeySet(), value)); + + Benchmarking.printResults( + Benchmarking.calculateResults(Benchmarking.getLatencies(iterations, actions))); + } +} diff --git a/java/jabushka/benchmarks/src/test/java/javabushka/client/lettuce/LettuceAsyncClientIT.java b/java/jabushka/benchmarks/src/test/java/javabushka/client/lettuce/LettuceAsyncClientIT.java new file mode 100644 index 0000000000..336f1f92ec --- /dev/null +++ b/java/jabushka/benchmarks/src/test/java/javabushka/client/lettuce/LettuceAsyncClientIT.java @@ -0,0 +1,77 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javabushka.client.lettuce; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import io.lettuce.core.RedisFuture; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class LettuceAsyncClientIT { + + private static LettuceAsyncClient lettuceClient; + + private static LettuceAsyncClient otherLettuceClient; + + @BeforeAll + static void initializeJedisClient() { + lettuceClient = new LettuceAsyncClient(); + lettuceClient.connectToRedis(); + + otherLettuceClient = new LettuceAsyncClient(); + otherLettuceClient.connectToRedis(); + } + + @AfterAll + static void closeConnection() { + lettuceClient.closeConnection(); + otherLettuceClient.closeConnection(); + } + + @Test + public void testResourceSetGet() { + String key = "key1"; + String value = "my-value-1"; + + String otherKey = "key2"; + String otherValue = "my-value-2"; + + RedisFuture setResult = lettuceClient.asyncSet(key, value); + RedisFuture otherSetResult = otherLettuceClient.asyncSet(otherKey, otherValue); + + // and wait for both clients + try { + lettuceClient.waitForResult(setResult); + } catch (Exception e) { + fail("Can SET redis result without Exception"); + } + try { + otherLettuceClient.waitForResult(otherSetResult); + } catch (Exception e) { + fail("Can SET other redis result without Exception"); + } + + RedisFuture getResult = lettuceClient.asyncGet(key); + RedisFuture otherGetResult = otherLettuceClient.asyncGet(otherKey); + String result = "invalid"; + String otherResult = "invalid"; + try { + result = (String) lettuceClient.waitForResult(getResult); + } catch (Exception e) { + fail("Can GET redis result without Exception"); + } + + try { + otherResult = (String) otherLettuceClient.waitForResult(otherGetResult); + } catch (Exception e) { + fail("Can GET other redis result without Exception"); + } + + assertEquals(value, result); + assertEquals(otherValue, otherResult); + } +} diff --git a/java/jabushka/benchmarks/src/test/java/javabushka/client/lettuce/LettuceClientIT.java b/java/jabushka/benchmarks/src/test/java/javabushka/client/lettuce/LettuceClientIT.java new file mode 100644 index 0000000000..5180489876 --- /dev/null +++ b/java/jabushka/benchmarks/src/test/java/javabushka/client/lettuce/LettuceClientIT.java @@ -0,0 +1,39 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javabushka.client.lettuce; + +import java.util.HashMap; +import javabushka.client.utils.Benchmarking; +import javabushka.client.utils.ChosenAction; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class LettuceClientIT { + + private static LettuceClient lettuceClient; + + @BeforeAll + static void initializeJedisClient() { + lettuceClient = new LettuceClient(); + lettuceClient.connectToRedis(); + } + + @AfterAll + static void closeConnection() { + lettuceClient.closeConnection(); + } + + @Test + public void testResourceSetGet() { + int iterations = 100000; + String value = "my-value"; + + HashMap actions = new HashMap<>(); + actions.put(ChosenAction.GET_EXISTING, () -> lettuceClient.get(Benchmarking.generateKeySet())); + actions.put( + ChosenAction.GET_NON_EXISTING, () -> lettuceClient.get(Benchmarking.generateKeyGet())); + actions.put(ChosenAction.SET, () -> lettuceClient.set(Benchmarking.generateKeySet(), value)); + } +} diff --git a/java/jabushka/build.gradle b/java/jabushka/build.gradle new file mode 100644 index 0000000000..340f2c98cb --- /dev/null +++ b/java/jabushka/build.gradle @@ -0,0 +1,100 @@ +plugins { + id 'java' + id 'java-library' + id 'io.freefair.lombok' version '6.4.0' + id 'jacoco' + id 'com.diffplug.spotless' version '6.19.0' +} + +repositories { + mavenCentral() +} + +subprojects { + repositories { + mavenCentral() + } + // minimal java compatibility level + plugins.withId('java') { + sourceCompatibility = targetCompatibility = "11" + } + tasks.withType(Test) { + useJUnitPlatform() + + testLogging { + exceptionFormat "full" + events "started", "skipped", "passed", "failed" + showStandardStreams true + } + // TODO: add jacoco with code coverage + // finalizedBy jacocoTestReport, jacocoTestCoverageVerification + } +} + +dependencies { + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.9.2' +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +// JaCoCo section (code coverage by unit tests) +jacoco { + toolVersion = "0.8.9" +} +jacocoTestReport { + reports { + xml.configure { enabled false } + csv.configure { enabled false } + } + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it) + })) + } +} +jacocoTestCoverageVerification { + violationRules { + rule { + element = 'CLASS' + excludes = [ + ] + limit { + counter = 'LINE' + minimum = 1.0 + } + limit { + counter = 'BRANCH' + minimum = 1.0 + } + } + } + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it) + })) + } +} +// TODO: add jacoco with code coverage +// check.dependsOn jacocoTestCoverageVerification +// End of JaCoCo section + +// Spotless section (code style) +spotless { + java { + target fileTree('.') { + include '**/*.java' + exclude '**/build/**', '**/build-*/**', '**/generated/**' + } + importOrder() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') + } +} +// End of Spotless section diff --git a/java/jabushka/gradle.properties b/java/jabushka/gradle.properties new file mode 100644 index 0000000000..3013c32a31 --- /dev/null +++ b/java/jabushka/gradle.properties @@ -0,0 +1,2 @@ +version=1.13.0 +org.gradle.jvmargs=-Duser.language=en -Duser.country=US diff --git a/java/jabushka/gradle/wrapper/gradle-wrapper.jar b/java/jabushka/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..7f93135c49 Binary files /dev/null and b/java/jabushka/gradle/wrapper/gradle-wrapper.jar differ diff --git a/java/jabushka/gradle/wrapper/gradle-wrapper.properties b/java/jabushka/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..ac72c34e8a --- /dev/null +++ b/java/jabushka/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/java/jabushka/gradlew b/java/jabushka/gradlew new file mode 100755 index 0000000000..0adc8e1a53 --- /dev/null +++ b/java/jabushka/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/java/jabushka/gradlew.bat b/java/jabushka/gradlew.bat new file mode 100755 index 0000000000..93e3f59f13 --- /dev/null +++ b/java/jabushka/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/java/jabushka/integTest/build.gradle b/java/jabushka/integTest/build.gradle new file mode 100644 index 0000000000..e69de29bb2 diff --git a/java/jabushka/jabushka/build.gradle b/java/jabushka/jabushka/build.gradle new file mode 100644 index 0000000000..b60dc6adfc --- /dev/null +++ b/java/jabushka/jabushka/build.gradle @@ -0,0 +1,46 @@ +import java.nio.file.Paths + +plugins { + id 'java-library' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.24.3' +} + +tasks.register('protobuf', Exec) { + doFirst { + project.mkdir(Paths.get(project.projectDir.path, 'src/main/java/org/babushka/jabushka/generated').toString()) + } + commandLine 'protoc', + '-Iprotobuf=babushka-core/src/protobuf/', + '--java_out=java/jabushka/jabushka/src/main/java/org/babushka/jabushka/generated', + 'babushka-core/src/protobuf/connection_request.proto', + 'babushka-core/src/protobuf/redis_request.proto', + 'babushka-core/src/protobuf/response.proto' + workingDir Paths.get(project.rootDir.path, '../..').toFile() +} + +tasks.register('buildRust', Exec) { + commandLine 'cargo', 'build' + workingDir project.rootDir +} + +tasks.register('buildWithRust') { + dependsOn 'buildRust' + finalizedBy 'build' +} + +tasks.register('buildWithProto') { + dependsOn 'protobuf' + finalizedBy 'build' +} + +tasks.register('buildAll') { + dependsOn 'protobuf', 'buildRust' + finalizedBy 'build' +} diff --git a/java/jabushka/settings.gradle b/java/jabushka/settings.gradle new file mode 100644 index 0000000000..f549b8010a --- /dev/null +++ b/java/jabushka/settings.gradle @@ -0,0 +1,5 @@ +rootProject.name = 'babushka' + +include 'jabushka' +include 'integTest' +include 'benchmarks' diff --git a/java/src/lib.rs b/java/src/lib.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/submodules/redis-rs b/submodules/redis-rs index bfdf58859e..694fb7b1ec 160000 --- a/submodules/redis-rs +++ b/submodules/redis-rs @@ -1 +1 @@ -Subproject commit bfdf58859eba504bae3c22c67488f3ee997cb635 +Subproject commit 694fb7b1ec1a826cc5a8e936a6c6eb7610b3ec65