Skip to content

Commit

Permalink
Add option to run tests on multiple clients in concurrency (#16)
Browse files Browse the repository at this point in the history
* Add option to run tests on multiple clients in concurrency

* Common pool of iterations.
* Awaiting result from async methods.

Signed-off-by: Yury-Fridlyand <[email protected]>

* minor fix

Signed-off-by: Yury-Fridlyand <[email protected]>

* Change while-loop; Spotless Apply

Signed-off-by: acarbonetto <[email protected]>

---------

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: acarbonetto <[email protected]>
Co-authored-by: acarbonetto <[email protected]>
  • Loading branch information
Yury-Fridlyand and acarbonetto authored Oct 5, 2023
1 parent b15f93e commit 1bab56a
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package javababushka.benchmarks;

import static javababushka.benchmarks.utils.Benchmarking.testClientSetGet;

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 java.util.stream.Stream;
import javababushka.benchmarks.jedis.JedisClient;
import javababushka.benchmarks.jedis.JedisPseudoAsyncClient;
import javababushka.benchmarks.lettuce.LettuceAsyncClient;
import javababushka.benchmarks.lettuce.LettuceClient;
import javababushka.benchmarks.utils.Benchmarking;
import javababushka.benchmarks.jedis.JedisPseudoAsyncClient;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -38,34 +40,17 @@ public static void main(String[] args) {

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);
testClientSetGet(JedisClient::new, runConfiguration, false);
break;
case JEDIS_ASYNC:
testAsyncClientSetGet(new JedisPseudoAsyncClient(), runConfiguration);
testClientSetGet(JedisPseudoAsyncClient::new, runConfiguration, true);
break;
case LETTUCE:
testClientSetGet(new LettuceClient(), runConfiguration);
testClientSetGet(LettuceClient::new, runConfiguration, false);
break;
case LETTUCE_ASYNC:
testAsyncClientSetGet(new LettuceAsyncClient(), runConfiguration);
testClientSetGet(LettuceAsyncClient::new, runConfiguration, true);
break;
case BABUSHKA:
System.out.println("Babushka not yet configured");
Expand All @@ -90,7 +75,8 @@ private static Options getOptions() {
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(
"l", "clients", true, "one of: all|jedis|jedis_async|lettuce|lettuce_async|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]");
Expand Down Expand Up @@ -146,6 +132,30 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
runConfiguration.clients =
Arrays.stream(clients)
.map(c -> Enum.valueOf(ClientName.class, c.toUpperCase()))
.flatMap(
e -> {
switch (e) {
case ALL:
return Stream.of(
ClientName.JEDIS,
ClientName.JEDIS_ASYNC,
ClientName.BABUSHKA,
ClientName.LETTUCE,
ClientName.LETTUCE_ASYNC);
case ALL_ASYNC:
return Stream.of(
ClientName.JEDIS_ASYNC,
// ClientName.BABUSHKA,
ClientName.LETTUCE_ASYNC);
case ALL_SYNC:
return Stream.of(
ClientName.JEDIS,
// ClientName.BABUSHKA,
ClientName.LETTUCE);
default:
return Stream.of(e);
}
})
.toArray(ClientName[]::new);
}

Expand All @@ -154,7 +164,15 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
}

if (line.hasOption("clientCount")) {
runConfiguration.clientCount = Integer.parseInt(line.getOptionValue("clientCount"));
String clientCount = line.getOptionValue("clientCount");

// check if it's the correct format
if (!clientCount.matches("\\d+(\\s+\\d+)?")) {
throw new ParseException("Invalid concurrentTasks");
}
// split the string into a list of integers
runConfiguration.clientCount =
Arrays.stream(clientCount.split("\\s+")).mapToInt(Integer::parseInt).toArray();
}

if (line.hasOption("tls")) {
Expand All @@ -164,18 +182,6 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
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"),
Expand Down Expand Up @@ -210,18 +216,23 @@ public static class RunConfiguration {
public ClientName[] clients;
public String host;
public int port;
public int clientCount;
public int[] clientCount;
public boolean tls;
public boolean debugLogging = false;

public RunConfiguration() {
configuration = "Release";
resultsFile = Optional.empty();
dataSize = 20;
concurrentTasks = List.of(1, 10, 100);
clients = new ClientName[] {ClientName.ALL};
concurrentTasks = List.of(10, 100);
clients =
new ClientName[] {
// ClientName.BABUSHKA,
ClientName.JEDIS, ClientName.JEDIS_ASYNC, ClientName.LETTUCE, ClientName.LETTUCE_ASYNC
};
host = "localhost";
port = 6379;
clientCount = 1;
clientCount = new int[] {1, 2};
tls = false;
}
}
Expand Down
Loading

0 comments on commit 1bab56a

Please sign in to comment.