Skip to content

Commit e81fa5a

Browse files
auto commit
1 parent 6d28b94 commit e81fa5a

File tree

3 files changed

+152
-76
lines changed

3 files changed

+152
-76
lines changed

db-esdk-performance-testing/benchmarks/java/src/main/java/com/amazon/esdk/benchmark/ESDKBenchmark.java

Lines changed: 94 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private DynamoDbItemEncryptor setupItemEncryptorClient() {
151151
/**
152152
* Run a single batch put-get cycle and measure performance
153153
*/
154-
public Result runBatchPutGetCycle(final byte[] data) {
154+
public Result runItemEncryptorCycle(final byte[] data) {
155155
// Create 25 items with same data, different sort_key
156156
final Map<String, AttributeValue> item = new HashMap<>();
157157
item.put("partition_key", AttributeValue.builder().s("benchmark-test").build());
@@ -187,7 +187,7 @@ public Result runBatchPutGetCycle(final byte[] data) {
187187
}
188188

189189
public List<TestResult> runAllBenchmarks() {
190-
System.out.println("Starting comprehensive DB-ESDK benchmark suite");
190+
System.out.println("Starting comprehensive ESDK benchmark suite");
191191
final List<TestResult> allResults = new ArrayList<>();
192192

193193
// Get test parameters from config
@@ -212,46 +212,113 @@ public List<TestResult> runAllBenchmarks() {
212212

213213
System.out.println("Running " + totalTests + " total tests");
214214

215-
try (ProgressBar pb = new ProgressBar("DB-ESDK Benchmark", totalTests)) {
216-
// Run throughput tests
217-
for (final Integer dataSize : dataSizes) {
218-
final TestResult result = Tests.runThroughputTest(
219-
this,
220-
dataSize,
221-
config.iterations.measurement
222-
);
223-
allResults.add(result);
215+
try (
216+
final ProgressBar pb = new ProgressBar("Running benchmarks", totalTests)
217+
) {
218+
// Throughput tests
219+
for (final int dataSize : dataSizes) {
220+
try {
221+
final TestResult result = Tests.runThroughputTest(
222+
this,
223+
dataSize,
224+
config.iterations.measurement
225+
);
226+
if (result != null) {
227+
allResults.add(result);
228+
System.out.println(
229+
"Throughput test completed: " +
230+
String.format("%.2f", result.opsPerSecond) +
231+
" ops/sec"
232+
);
233+
System.out.flush();
234+
System.out.println(
235+
"Throughput test completed - Ops/sec: " +
236+
String.format("%.2f", result.opsPerSecond) +
237+
", MB/sec: " +
238+
String.format("%.2f", result.bytesPerSecond / (1024 * 1024))
239+
);
240+
}
241+
} catch (final Exception e) {
242+
System.err.println(
243+
"Throughput test failed for data size " +
244+
dataSize +
245+
" bytes: " +
246+
e.getMessage()
247+
);
248+
}
249+
System.out.flush();
224250
pb.step();
251+
System.out.flush();
225252
}
226253

227-
// Run memory tests
228-
for (final Integer dataSize : dataSizes) {
229-
final TestResult result = Tests.runMemoryTest(this, dataSize);
230-
allResults.add(result);
254+
// Memory tests
255+
for (final int dataSize : dataSizes) {
256+
try {
257+
final TestResult result = Tests.runMemoryTest(this, dataSize);
258+
allResults.add(result);
259+
System.out.println(
260+
"Memory test completed: " +
261+
String.format("%.2f", result.peakMemoryMb) +
262+
" MB peak"
263+
);
264+
System.out.flush();
265+
} catch (final Exception e) {
266+
System.err.println(
267+
"Memory test failed for data size " +
268+
dataSize +
269+
" bytes: " +
270+
e.getMessage()
271+
);
272+
}
273+
System.out.flush();
231274
pb.step();
275+
System.out.flush();
232276
}
233277

234-
// Run concurrency tests
235-
for (final Integer dataSize : dataSizes) {
236-
for (final Integer concurrency : config.concurrencyLevels) {
237-
if (concurrency > 1) {
238-
final TestResult result = Tests.runConcurrentTest(
239-
this,
240-
dataSize,
241-
concurrency,
242-
config.iterations.measurement
243-
);
244-
allResults.add(result);
278+
// Concurrent tests
279+
for (final int dataSize : dataSizes) {
280+
for (final int concurrency : config.concurrencyLevels) {
281+
if (concurrency > 1) { // Skip single-threaded for concurrent tests
282+
try {
283+
final TestResult result = Tests.runConcurrentTest(
284+
this,
285+
dataSize,
286+
concurrency,
287+
5
288+
);
289+
allResults.add(result);
290+
System.out.println(
291+
"Concurrent test completed: " +
292+
String.format("%.2f", result.opsPerSecond) +
293+
" ops/sec @ " +
294+
concurrency +
295+
" threads"
296+
);
297+
} catch (final Exception e) {
298+
System.err.println(
299+
"Concurrent test failed for data size " +
300+
dataSize +
301+
" bytes with " +
302+
concurrency +
303+
" threads: " +
304+
e.getMessage()
305+
);
306+
}
307+
System.out.flush();
245308
pb.step();
309+
System.out.flush();
246310
}
247311
}
248312
}
249313
}
250314

251-
System.out.println("Benchmark suite completed successfully");
315+
System.out.println(
316+
"Benchmark suite completed. Total results: " + allResults.size()
317+
);
252318
return allResults;
253319
}
254320

321+
255322
public record Result(
256323
double putLatencyMs,
257324
double getLatencyMs

db-esdk-performance-testing/benchmarks/java/src/main/java/com/amazon/esdk/benchmark/Tests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static MeasurementResults runMeasurementIterations(
9393
for (int i = 0; i < iterations; i++) {
9494
try {
9595
final long iterationStart = System.nanoTime();
96-
final var result = benchmark.runBatchPutGetCycle(data);
96+
final var result = benchmark.runItemEncryptorCycle(data);
9797
final double totalMs =
9898
(System.nanoTime() - iterationStart) / 1_000_000.0;
9999

@@ -257,7 +257,7 @@ private static IterationResult runSingleMemoryIteration(
257257

258258
// Run the actual operation
259259
try {
260-
benchmark.runBatchPutGetCycle(data);
260+
benchmark.runItemEncryptorCycle(data);
261261
} catch (final Exception e) {
262262
System.out.println(
263263
"Memory test iteration " + iteration + " failed: " + e.getMessage()
@@ -397,7 +397,7 @@ public static TestResult runConcurrentTest(
397397
for (int j = 0; j < iterationsPerThread; j++) {
398398
try {
399399
final long threadStartTime = System.nanoTime();
400-
benchmark.runBatchPutGetCycle(data);
400+
benchmark.runItemEncryptorCycle(data);
401401
final double elapsed =
402402
(System.nanoTime() - threadStartTime) / 1_000_000.0;
403403
allTimes.add(elapsed);

db-esdk-performance-testing/benchmarks/java/src/main/java/com/amazon/esdk/benchmark/model/TestResult.java

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@ public final class TestResult {
1818
@JsonProperty("concurrency")
1919
public int concurrency = 1;
2020

21-
@JsonProperty("put_latency_ms")
22-
public double putLatencyMs;
23-
24-
@JsonProperty("get_latency_ms")
25-
public double getLatencyMs;
26-
27-
@JsonProperty("end_to_end_latency_ms")
28-
public double endToEndLatencyMs;
29-
30-
@JsonProperty("ops_per_second")
21+
@JsonProperty("operations_per_second")
3122
public double opsPerSecond;
3223

3324
@JsonProperty("bytes_per_second")
@@ -39,14 +30,23 @@ public final class TestResult {
3930
@JsonProperty("memory_efficiency_ratio")
4031
public double memoryEfficiencyRatio;
4132

42-
@JsonProperty("p50_latency")
43-
public double p50Latency;
33+
@JsonProperty("avg_latency_ms")
34+
public double avgLatencyMs;
35+
36+
@JsonProperty("p50_latency_ms")
37+
public double p50LatencyMs;
4438

45-
@JsonProperty("p95_latency")
46-
public double p95Latency;
39+
@JsonProperty("p95_latency_ms")
40+
public double p95LatencyMs;
4741

48-
@JsonProperty("p99_latency")
49-
public double p99Latency;
42+
@JsonProperty("p99_latency_ms")
43+
public double p99LatencyMs;
44+
45+
@JsonProperty("encrypt_latency_ms")
46+
public double encryptLatencyMs;
47+
48+
@JsonProperty("decrypt_latency_ms")
49+
public double decryptLatencyMs;
5050

5151
@JsonProperty("timestamp")
5252
public String timestamp = "";
@@ -88,24 +88,29 @@ public static TestResult createThroughputResult(
8888
result.concurrency = 1;
8989
result.opsPerSecond = opsPerSecond;
9090
result.bytesPerSecond = opsPerSecond * dataSize;
91-
result.endToEndLatencyMs = avgTotalLatency;
92-
result.p50Latency = calculatePercentile(totalLatencies, 50);
93-
result.p95Latency = calculatePercentile(totalLatencies, 95);
94-
result.p99Latency = calculatePercentile(totalLatencies, 99);
95-
result.putLatencyMs = putLatencies
96-
.stream()
97-
.mapToDouble(Double::doubleValue)
98-
.average()
99-
.orElse(0.0);
100-
result.getLatencyMs = getLatencies
101-
.stream()
102-
.mapToDouble(Double::doubleValue)
103-
.average()
104-
.orElse(0.0);
91+
result.avgLatencyMs = avgTotalLatency;
92+
result.p50LatencyMs = calculatePercentile(totalLatencies, 50);
93+
result.p95LatencyMs = calculatePercentile(totalLatencies, 95);
94+
result.p99LatencyMs = calculatePercentile(totalLatencies, 99);
95+
result.encryptLatencyMs =
96+
putLatencies
97+
.stream()
98+
.mapToDouble(Double::doubleValue)
99+
.average()
100+
.orElse(0.0);
101+
result.decryptLatencyMs =
102+
getLatencies
103+
.stream()
104+
.mapToDouble(Double::doubleValue)
105+
.average()
106+
.orElse(0.0);
105107
result.iterations = putLatencies.size();
106-
result.timestamp = java.time.LocalDateTime
107-
.now()
108-
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
108+
result.timestamp =
109+
java.time.LocalDateTime
110+
.now()
111+
.format(
112+
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
113+
);
109114
result.javaVersion = System.getProperty("java.version");
110115
result.cpuCount = cpuCount;
111116
result.totalMemoryGb = totalMemoryMB / 1024.0;
@@ -130,9 +135,12 @@ public static TestResult createMemoryResult(
130135
result.concurrency = 1;
131136
result.peakMemoryMb = peakMemoryMb;
132137
result.memoryEfficiencyRatio = memoryEfficiency;
133-
result.timestamp = java.time.LocalDateTime
134-
.now()
135-
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
138+
result.timestamp =
139+
java.time.LocalDateTime
140+
.now()
141+
.format(
142+
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
143+
);
136144
result.javaVersion = System.getProperty("java.version");
137145
result.cpuCount = cpuCount;
138146
result.totalMemoryGb = totalMemoryMB / 1024.0;
@@ -153,23 +161,24 @@ public static TestResult createConcurrentResult(
153161
.mapToDouble(Double::doubleValue)
154162
.average()
155163
.orElse(0.0);
156-
final double totalTimeSeconds = allTimes
157-
.stream()
158-
.mapToDouble(Double::doubleValue)
159-
.sum() / 1000.0;
160-
final double opsPerSecond = totalTimeSeconds > 0 ? totalOps / totalTimeSeconds : 0.0;
164+
final double opsPerSecond =
165+
totalOps /
166+
(allTimes.stream().mapToDouble(Double::doubleValue).sum() / 1000.0);
161167

162168
final var result = new TestResult();
163169
result.testName = "concurrent";
164170
result.dataSize = dataSize;
165171
result.concurrency = concurrency;
166172
result.opsPerSecond = opsPerSecond;
167173
result.bytesPerSecond = opsPerSecond * dataSize;
168-
result.endToEndLatencyMs = avgLatency;
174+
result.avgLatencyMs = avgLatency;
169175
result.iterations = totalOps;
170-
result.timestamp = java.time.LocalDateTime
171-
.now()
172-
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
176+
result.timestamp =
177+
java.time.LocalDateTime
178+
.now()
179+
.format(
180+
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
181+
);
173182
result.javaVersion = System.getProperty("java.version");
174183
result.cpuCount = cpuCount;
175184
result.totalMemoryGb = totalMemoryMB / 1024.0;
@@ -187,4 +196,4 @@ private static double calculatePercentile(
187196
final int clampedIndex = Math.max(0, Math.min(index, values.size() - 1));
188197
return values.get(clampedIndex);
189198
}
190-
}
199+
}

0 commit comments

Comments
 (0)