Skip to content

Commit

Permalink
Java benchmarks clusters (#34)
Browse files Browse the repository at this point in the history
* Add lettuce cluster client when cluster mode enabled

---------

Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto authored Nov 14, 2023
1 parent 30f2f62 commit 05590b0
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 79 deletions.
9 changes: 6 additions & 3 deletions benchmarks/install_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ chosenClients="all"
host="localhost"
port=6379
tlsFlag="--tls"
javaTlsFlag="-tls"

function runPythonBenchmark(){
# generate protobuf files
Expand Down Expand Up @@ -72,9 +73,8 @@ function runCSharpBenchmark(){

function runJavaBenchmark(){
cd ${BENCH_FOLDER}/../java
echo "./gradlew run --args=\"-resultsFile ${BENCH_FOLDER}/$1 -dataSize $2 -concurrentTasks $concurrentTasks -clientCount $clientCount -clients $chosenClients -host $host $portFlag $tlsFlag $clusterFlag\""
./gradlew run --args="-resultsFile \"${BENCH_FOLDER}/$1\" -dataSize $2 -concurrentTasks $concurrentTasks -clients $chosenClients -host $host -clientCount $clientCount $tlsFlag $clusterFlag $portFlag"
cd ${BENCH_FOLDER}/java
echo "./gradlew run --args=\"-resultsFile ${BENCH_FOLDER}/$1 -dataSize \"$2\" -concurrentTasks \"$concurrentTasks\" -clientCount \"$clientCount\" -clients $chosenClients -host $host $javaPortFlag $javaTlsFlag $javaClusterFlag\""
./gradlew run --args="-resultsFile \"${BENCH_FOLDER}/$1\" -dataSize \"$2\" -concurrentTasks \"$concurrentTasks\" -clients \"$chosenClients\" -host $host $javaPortFlag -clientCount \"$clientCount\" $javaTlsFlag $javaClusterFlag"
}

function runRustBenchmark(){
Expand Down Expand Up @@ -229,12 +229,15 @@ do
-no-csv) writeResultsCSV=0 ;;
-no-tls)
tlsFlag=
javaTlsFlag=
;;
-is-cluster)
clusterFlag="--clusterModeEnabled"
javaClusterFlag="-clusterModeEnabled"
;;
-port)
portFlag="--port "$2
javaPortFlag="-port "$2
shift
;;
esac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public interface AsyncClient extends Client {

long DEFAULT_TIMEOUT = 1000;
long DEFAULT_TIMEOUT = 1000; // Milliseconds

Future<?> asyncSet(String key, String value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javababushka.benchmarks.jedis.JedisClient;
import javababushka.benchmarks.jedis.JedisPseudoAsyncClient;
import javababushka.benchmarks.lettuce.LettuceAsyncClient;
import javababushka.benchmarks.lettuce.LettuceAsyncClusterClient;
import javababushka.benchmarks.lettuce.LettuceClient;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand All @@ -17,7 +18,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/** Benchmarking app for reporting performance of various redis-rs Java-clients */
/** Benchmarking app for reporting performance of various Redis Java-clients */
public class BenchmarkingApp {

// main application entrypoint
Expand Down Expand Up @@ -56,10 +57,14 @@ public static void main(String[] args) {
testClientSetGet(LettuceClient::new, runConfiguration, false);
break;
case LETTUCE_ASYNC:
testClientSetGet(LettuceAsyncClient::new, runConfiguration, true);
if (runConfiguration.clusterModeEnabled) {
testClientSetGet(LettuceAsyncClusterClient::new, runConfiguration, true);
} else {
testClientSetGet(LettuceAsyncClient::new, runConfiguration, true);
}
break;
case BABUSHKA:
System.out.println("Babushka not yet configured");
case BABUSHKA_ASYNC:
System.out.println("Babushka async not yet configured");
break;
}
}
Expand Down Expand Up @@ -96,6 +101,13 @@ private static Options getOptions() {
options.addOption(
Option.builder("clientCount").hasArg(true).desc("Number of clients to run [1]").build());
options.addOption(Option.builder("tls").hasArg(false).desc("TLS [false]").build());
options.addOption(
Option.builder("clusterModeEnabled")
.hasArg(false)
.desc("Is cluster-mode enabled, other standalone mode is used [false]")
.build());
options.addOption(
Option.builder("debugLogging").hasArg(false).desc("Verbose logs [false]").build());

return options;
}
Expand Down Expand Up @@ -137,20 +149,16 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
return Stream.of(
ClientName.JEDIS,
ClientName.JEDIS_ASYNC,
ClientName.BABUSHKA,
// ClientName.BABUSHKA_ASYNC,
ClientName.BABUSHKA_ASYNC,
ClientName.LETTUCE,
ClientName.LETTUCE_ASYNC);
case ALL_ASYNC:
return Stream.of(
ClientName.JEDIS_ASYNC,
// ClientName.BABUSHKA_ASYNC,
ClientName.BABUSHKA_ASYNC,
ClientName.LETTUCE_ASYNC);
case ALL_SYNC:
return Stream.of(
ClientName.JEDIS,
// ClientName.BABUSHKA,
ClientName.LETTUCE);
return Stream.of(ClientName.JEDIS, ClientName.LETTUCE);
default:
return Stream.of(e);
}
Expand All @@ -171,6 +179,8 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
}

runConfiguration.tls = line.hasOption("tls");
runConfiguration.clusterModeEnabled = line.hasOption("clusterModeEnabled");
runConfiguration.debugLogging = line.hasOption("debugLogging");

return runConfiguration;
}
Expand All @@ -182,8 +192,12 @@ private static int[] parseIntListOption(String line) throws ParseException {
if (lineValue.startsWith("[") && lineValue.endsWith("]")) {
lineValue = lineValue.substring(1, lineValue.length() - 1);
}

// trim whitespace
lineValue = lineValue.trim();

// check if it's the correct format
if (!lineValue.matches("\\d+(\\s+\\d+)?")) {
if (!lineValue.matches("\\d+(\\s+\\d+)*")) {
throw new ParseException("Invalid option: " + line);
}
// split the string into a list of integers
Expand All @@ -195,7 +209,6 @@ public enum ClientName {
JEDIS_ASYNC("Jedis async"),
LETTUCE("Lettuce"),
LETTUCE_ASYNC("Lettuce async"),
BABUSHKA("Babushka"),
BABUSHKA_ASYNC("Babushka async"),
ALL("All"),
ALL_SYNC("All sync"),
Expand Down Expand Up @@ -227,6 +240,7 @@ public static class RunConfiguration {
public int port;
public int[] clientCount;
public boolean tls;
public boolean clusterModeEnabled;
public boolean debugLogging = false;

public RunConfiguration() {
Expand All @@ -237,12 +251,13 @@ public RunConfiguration() {
clients =
new ClientName[] {
// ClientName.BABUSHKA_ASYNC,
ClientName.JEDIS, ClientName.JEDIS_ASYNC, ClientName.LETTUCE, ClientName.LETTUCE_ASYNC
ClientName.LETTUCE_ASYNC
};
host = "localhost";
port = 6379;
clientCount = new int[] {1, 2};
tls = false;
clusterModeEnabled = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

public class LettuceAsyncClient implements AsyncClient {

RedisClient client;
RedisAsyncCommands asyncCommands;
StatefulRedisConnection<String, String> connection;
private RedisClient client;
private RedisAsyncCommands asyncCommands;
private StatefulRedisConnection<String, String> connection;

@Override
public void connectToRedis() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package javababushka.benchmarks.lettuce;

import io.lettuce.core.RedisFuture;
import io.lettuce.core.RedisURI;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands;
import javababushka.benchmarks.utils.ConnectionSettings;

public class LettuceAsyncClusterClient extends LettuceAsyncClient {

private RedisClusterClient clusterClient;
private RedisAdvancedClusterAsyncCommands clusterAsyncCommands;
private StatefulRedisClusterConnection<String, String> clusterConnection;

@Override
public void connectToRedis() {
connectToRedis(new ConnectionSettings("localhost", 6379, false));
}

@Override
public void connectToRedis(ConnectionSettings connectionSettings) {
RedisURI uri =
RedisURI.builder()
.withHost(connectionSettings.host)
.withPort(connectionSettings.port)
.withSsl(connectionSettings.useSsl)
.build();
clusterClient = RedisClusterClient.create(uri);
clusterConnection = clusterClient.connect();
clusterAsyncCommands = clusterConnection.async();
}

@Override
public RedisFuture<?> asyncSet(String key, String value) {
return clusterAsyncCommands.set(key, value);
}

@Override
public RedisFuture<String> asyncGet(String key) {
return clusterAsyncCommands.get(key);
}

@Override
public void closeConnection() {
clusterConnection.close();
clusterClient.shutdown();
}

@Override
public String getName() {
return "Lettuce Cluster Async";
}
}
Loading

0 comments on commit 05590b0

Please sign in to comment.