Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/java_benchmarks' into java_bench…
Browse files Browse the repository at this point in the history
…marks-add-json

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Oct 13, 2023
2 parents a7395a6 + 540f49a commit de0cd49
Showing 1 changed file with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -120,10 +121,10 @@ public static void testClientSetGet(
Supplier<Client> clientCreator, BenchmarkingApp.RunConfiguration config, boolean async) {
for (int concurrentNum : config.concurrentTasks) {
int iterations = Math.min(Math.max(100000, concurrentNum * 10000), 10000000);
for (int clientNum : config.clientCount) {
for (int clientCount : config.clientCount) {
System.out.printf(
"%n =====> %s <===== %d clients %d concurrent %n%n",
clientCreator.get().getName(), clientNum, concurrentNum);
clientCreator.get().getName(), clientCount, concurrentNum);
AtomicInteger iterationCounter = new AtomicInteger(0);
Map<ChosenAction, ArrayList<Long>> actionResults =
Map.of(
Expand All @@ -132,42 +133,46 @@ public static void testClientSetGet(
ChosenAction.SET, new ArrayList<>());
List<Runnable> tasks = new ArrayList<>();

for (int i = 0; i < concurrentNum; ) {
for (int j = 0; j < clientNum; j++) {
i++;
int finalI = i;
int finalJ = j;
var client = clientCreator.get();
client.connectToRedis(new ConnectionSettings(config.host, config.port, config.tls));
tasks.add(
() -> {
// create clients
List<Client> clients = new LinkedList<>();
for (int cc = 0; cc < clientCount; cc++) {
Client newClient = clientCreator.get();
newClient.connectToRedis(new ConnectionSettings(config.host, config.port, config.tls));
clients.add(newClient);
}

for (int taskNum = 0; taskNum < concurrentNum; taskNum++) {
final int taskNumDebugging = taskNum;
tasks.add(
() -> {
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(
"%n concurrent = %d/%d, client# = %d/%d%n",
finalI, concurrentNum, finalJ + 1, clientNum);
"> iteration = %d/%d, client# = %d/%d%n",
iterationIncrement + 1, iterations, clientIndex + 1, clientCount);
}
int iterationIncrement = iterationCounter.getAndIncrement();
while (iterationIncrement < iterations) {
if (config.debugLogging) {
System.out.printf(
"> iteration = %d/%d, client# = %d/%d%n",
iterationIncrement + 1, iterations, finalJ + 1, clientNum);
}
// operate and calculate tik-tok
Pair<ChosenAction, Long> result =
measurePerformance(client, config.dataSize, async);
actionResults.get(result.getLeft()).add(result.getRight());

iterationIncrement = iterationCounter.getAndIncrement();
}
});
}
// operate and calculate tik-tok
Pair<ChosenAction, Long> result =
measurePerformance(clients.get(clientIndex), config.dataSize, async);
actionResults.get(result.getLeft()).add(result.getRight());

iterationIncrement = iterationCounter.getAndIncrement();
}
});
}
if (config.debugLogging) {
System.out.printf("%s client Benchmarking: %n", clientCreator.get().getName());
System.out.printf(
"===> concurrentNum = %d, clientNum = %d, tasks = %d%n",
concurrentNum, clientNum, tasks.size());
concurrentNum, clientCount, tasks.size());
}
long started = System.nanoTime();
tasks.stream()
Expand All @@ -188,7 +193,7 @@ public static void testClientSetGet(
config.resultsFile,
config.dataSize,
clientCreator.get().getName(),
clientNum,
clientCount,
concurrentNum,
iterationCounter.get() * 1e9 / (System.nanoTime() - started));
}
Expand Down

0 comments on commit de0cd49

Please sign in to comment.