-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add benchmarking application. No test clients yet. #629
Merged
Yury-Fridlyand
merged 11 commits into
valkey-io:main
from
Bit-Quill:integ-java-client-milestone-1-benchmarking
Dec 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5b31ff9
Add benchmarking application. No test clients yet.
Yury-Fridlyand 842a222
Address PR feedback.
Yury-Fridlyand 58f3684
Restore Jedis async.
Yury-Fridlyand 28e5fe0
refactor
Yury-Fridlyand 3138a7a
Add exception handling.
Yury-Fridlyand 859c9e6
Typo fix.
Yury-Fridlyand f7dbd3d
Rework `getActionMap`.
Yury-Fridlyand c83d4f3
remaning
Yury-Fridlyand 199ed5a
Revert some renamings.
Yury-Fridlyand d3f707f
Address PR feedback.
Yury-Fridlyand 26e786d
Merge branch 'main' into integ-java-client-milestone-1-benchmarking
Yury-Fridlyand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package javababushka.benchmarks.utils; | ||
|
||
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; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Supplier; | ||
import javababushka.benchmarks.BenchmarkingApp; | ||
|
@@ -23,14 +21,6 @@ public class Benchmarking { | |
static final double PROB_GET_EXISTING_KEY = 0.8; | ||
static final int SIZE_GET_KEYSPACE = 3750000; | ||
static final int SIZE_SET_KEYSPACE = 3000000; | ||
static final int ASYNC_OPERATION_TIMEOUT_SEC = 1; | ||
static final double LATENCY_NORMALIZATION = 1000000.0; | ||
static final int LATENCY_MIN = 100000; | ||
static final int LATENCY_MAX = 10000000; | ||
static final int LATENCY_MULTIPLIER = 10000; | ||
static final double TPS_NORMALIZATION = 1000000000.0; // nano to seconds | ||
// measurements are done in nano-seconds, but it should be converted to seconds later | ||
static final double SECONDS_IN_NANO = 1e-9; | ||
public static final double NANO_TO_SECONDS = 1e9; | ||
shachlanAmazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static ChosenAction randomAction() { | ||
|
@@ -69,52 +59,17 @@ public static Pair<ChosenAction, Long> measurePerformance(Map<ChosenAction, Oper | |
return Pair.of(action, after - before); | ||
} | ||
|
||
// Assumption: latencies is sorted in ascending order | ||
private static Long percentile(List<Long> 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(List<Long> 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<ChosenAction, LatencyResults> calculateResults( | ||
Map<ChosenAction, List<Long>> actionLatencies) { | ||
Map<ChosenAction, LatencyResults> results = new HashMap<>(); | ||
|
||
for (Map.Entry<ChosenAction, List<Long>> entry : actionLatencies.entrySet()) { | ||
ChosenAction action = entry.getKey(); | ||
List<Long> latencies = entry.getValue(); | ||
|
||
if (latencies.size() == 0) { | ||
results.put(action, new LatencyResults(0, 0, 0, 0, 0, 0)); | ||
} else { | ||
double avgLatency = | ||
SECONDS_IN_NANO | ||
* latencies.stream().mapToLong(Long::longValue).sum() | ||
/ latencies.size(); | ||
double[] latencies = entry.getValue().stream().mapToDouble(Long::doubleValue).toArray(); | ||
|
||
Collections.sort(latencies); | ||
results.put( | ||
action, | ||
new LatencyResults( | ||
avgLatency, | ||
SECONDS_IN_NANO * percentile(latencies, 50), | ||
SECONDS_IN_NANO * percentile(latencies, 90), | ||
SECONDS_IN_NANO * percentile(latencies, 99), | ||
SECONDS_IN_NANO * stdDeviation(latencies, avgLatency), | ||
latencies.size())); | ||
if (latencies.length != 0) { | ||
results.put(action, new LatencyResults(latencies)); | ||
} | ||
} | ||
|
||
|
@@ -162,8 +117,8 @@ public static void testClientSetGet( | |
var clientName = clients.get(0).getName(); | ||
|
||
System.out.printf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please log data size too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 842a222 |
||
"%n =====> %s <===== %d clients %d concurrent %n%n", | ||
clientName, clientCount, concurrentNum); | ||
"%n =====> %s <===== %d clients %d concurrent %d data size %n%n", | ||
clientName, clientCount, concurrentNum, dataSize); | ||
AtomicInteger iterationCounter = new AtomicInteger(0); | ||
|
||
long started = System.nanoTime(); | ||
|
@@ -260,7 +215,7 @@ public static void testClientSetGet( | |
concurrentNum, | ||
tps); | ||
} | ||
printResults(calculatedResults, (after - started) / TPS_NORMALIZATION, iterations); | ||
printResults(calculatedResults, (after - started) / NANO_TO_SECONDS, iterations); | ||
} | ||
} | ||
} | ||
|
@@ -276,26 +231,17 @@ public static Map<ChosenAction, Operation> getActionMap( | |
actions.put( | ||
ChosenAction.GET_EXISTING, | ||
async | ||
? () -> | ||
((AsyncClient) client) | ||
.asyncGet(generateKeySet()) | ||
.get(ASYNC_OPERATION_TIMEOUT_SEC, TimeUnit.SECONDS) | ||
? () -> ((AsyncClient) client).asyncGet(generateKeySet()).get() | ||
: () -> ((SyncClient) client).get(generateKeySet())); | ||
actions.put( | ||
ChosenAction.GET_NON_EXISTING, | ||
async | ||
? () -> | ||
((AsyncClient) client) | ||
.asyncGet(generateKeyGet()) | ||
.get(ASYNC_OPERATION_TIMEOUT_SEC, TimeUnit.SECONDS) | ||
? () -> ((AsyncClient) client).asyncGet(generateKeyGet()).get() | ||
: () -> ((SyncClient) client).get(generateKeyGet())); | ||
actions.put( | ||
ChosenAction.SET, | ||
async | ||
? () -> | ||
((AsyncClient) client) | ||
.asyncSet(generateKeySet(), value) | ||
.get(ASYNC_OPERATION_TIMEOUT_SEC, TimeUnit.SECONDS) | ||
? () -> ((AsyncClient) client).asyncSet(generateKeySet(), value).get() | ||
: () -> ((SyncClient) client).set(generateKeySet(), value)); | ||
return actions; | ||
} | ||
|
10 changes: 7 additions & 3 deletions
10
java/benchmarks/src/main/java/javababushka/benchmarks/utils/ConnectionSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package javababushka.benchmarks.utils; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
/** Redis-client settings */ | ||
@AllArgsConstructor | ||
public class ConnectionSettings { | ||
public final String host; | ||
public final int port; | ||
public final boolean useSsl; | ||
public final boolean clusterMode; | ||
|
||
public ConnectionSettings(String host, int port, boolean useSsl, boolean clusterMode) { | ||
this.host = host; | ||
this.port = port; | ||
this.useSsl = useSsl; | ||
this.clusterMode = clusterMode; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's an async client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I deleted the wrong reference. Restored.