15
15
16
16
package software .amazon .awssdk .benchmark ;
17
17
18
-
18
+ import java . time . Instant ;
19
19
import java .util .ArrayList ;
20
20
import java .util .Collection ;
21
21
import java .util .List ;
22
22
import java .util .Map ;
23
+ import java .util .stream .Collectors ;
23
24
import org .openjdk .jmh .results .RunResult ;
24
25
import org .openjdk .jmh .runner .Runner ;
25
26
import org .openjdk .jmh .runner .RunnerException ;
28
29
import org .openjdk .jmh .runner .options .OptionsBuilder ;
29
30
import software .amazon .awssdk .benchmark .apache4 .Apache4Benchmark ;
30
31
import software .amazon .awssdk .benchmark .apache5 .Apache5Benchmark ;
32
+ import software .amazon .awssdk .benchmark .apache5 .Apache5VirtualBenchmark ;
31
33
import software .amazon .awssdk .benchmark .core .BenchmarkResult ;
32
34
import software .amazon .awssdk .benchmark .metrics .CloudWatchMetricsPublisher ;
33
35
import software .amazon .awssdk .regions .Region ;
34
- import java .time .Instant ;
35
- import java .util .logging .Logger ;
36
- import java .util .stream .Collectors ;
37
- import software .amazon .awssdk .benchmark .apache5 .Apache5VirtualBenchmark ;
36
+ import software .amazon .awssdk .utils .JavaSystemSetting ;
37
+ import software .amazon .awssdk .utils .Logger ;
38
38
39
39
public final class UnifiedBenchmarkRunner {
40
- private static final Logger logger = Logger .getLogger (UnifiedBenchmarkRunner .class . getName () );
40
+ private static final Logger logger = Logger .loggerFor (UnifiedBenchmarkRunner .class );
41
41
42
42
private UnifiedBenchmarkRunner () {
43
43
}
44
44
45
+ private static void printToConsole (String message ) {
46
+ // CHECKSTYLE:OFF - We want the Benchmark results to be printed at the end of the run
47
+ System .out .println (message );
48
+ // CHECKSTYLE:ON
49
+ }
50
+
45
51
private static boolean isJava21OrHigher () {
46
- String version = System .getProperty ("java.version" );
52
+
53
+ String version = JavaSystemSetting .JAVA_VERSION .getStringValueOrThrow ();
47
54
if (version .startsWith ("1." )) {
48
55
version = version .substring (2 );
49
56
}
@@ -58,7 +65,8 @@ private static boolean isJava21OrHigher() {
58
65
}
59
66
60
67
public static void main (String [] args ) throws Exception {
61
- logger .info ("Starting unified benchmark comparison" );
68
+ // Update logging calls to use Supplier<String> pattern
69
+ logger .info (() -> "Starting unified benchmark comparison" );
62
70
63
71
String runId = Instant .now ().toString ();
64
72
CloudWatchMetricsPublisher publisher = new CloudWatchMetricsPublisher (
@@ -70,35 +78,35 @@ public static void main(String[] args) throws Exception {
70
78
71
79
try {
72
80
// Run Apache4 benchmark
73
- logger .info ("Running Apache4 benchmark..." );
74
- allResults .addAll (runBenchmark ("Apache4" , Apache4Benchmark .class , null ));
81
+ logger .info (() -> "Running Apache4 benchmark..." );
82
+ allResults .addAll (runBenchmark ("Apache4" , Apache4Benchmark .class ));
75
83
76
84
// Run Apache5 with platform threads
77
- logger .info ("Running Apache5..." );
78
- allResults .addAll (runBenchmark ("Apache5" , Apache5Benchmark .class , null ));
85
+ logger .info (() -> "Running Apache5..." );
86
+ allResults .addAll (runBenchmark ("Apache5" , Apache5Benchmark .class ));
79
87
80
88
// Only run virtual threads benchmark if Java 21+
81
89
if (isJava21OrHigher ()) {
82
- logger .info ("Running Apache5 with virtual threads..." );
83
- allResults .addAll (runBenchmark ("Apache5-Virtual" , Apache5VirtualBenchmark .class , null ));
90
+ logger .info (() -> "Running Apache5 with virtual threads..." );
91
+ allResults .addAll (runBenchmark ("Apache5-Virtual" , Apache5VirtualBenchmark .class ));
84
92
} else {
85
- logger .info ("Skipping virtual threads benchmark - requires Java 21 or higher (current: " +
86
- System . getProperty ( "java.version" ) + ")" );
93
+ logger .info (() -> "Skipping virtual threads benchmark - requires Java 21 or higher (current: " +
94
+ JavaSystemSetting . JAVA_VERSION . getStringValueOrThrow ( ) + ")" );
87
95
}
88
96
89
97
// Debug: Print all results to understand the structure
90
- logger .info ("All benchmark results:" );
98
+ logger .info (() -> "All benchmark results:" );
91
99
for (BenchmarkResult result : allResults ) {
92
- logger .info (String .format ("Client: %s, Benchmark: %s, Throughput: %.2f" ,
93
- result .getClientType (), result .getBenchmarkName (), result .getThroughput ()));
100
+ logger .info (() -> String .format ("Client: %s, Benchmark: %s, Throughput: %.2f" ,
101
+ result .getClientType (), result .getBenchmarkName (), result .getThroughput ()));
94
102
}
95
103
96
104
// Publish results to CloudWatch
97
- logger .info ("Publishing results to CloudWatch..." );
105
+ logger .info (() -> "Publishing results to CloudWatch..." );
98
106
for (BenchmarkResult result : allResults ) {
99
107
publisher .publishBenchmarkResult (result , runId );
100
108
}
101
- logger .info ("\n Benchmark complete! CloudWatch metrics published with run ID: " + runId );
109
+ logger .info (() -> "\n Benchmark complete! CloudWatch metrics published with run ID: " + runId );
102
110
103
111
// Print benchmark results summary
104
112
printBenchmarkSummary (allResults );
@@ -109,9 +117,7 @@ public static void main(String[] args) throws Exception {
109
117
}
110
118
111
119
private static List <BenchmarkResult > runBenchmark (String clientType ,
112
- Class <?> benchmarkClass ,
113
- String executorType )
114
- throws RunnerException {
120
+ Class <?> benchmarkClass ) throws RunnerException {
115
121
ChainedOptionsBuilder optBuilder = new OptionsBuilder ()
116
122
.include (benchmarkClass .getSimpleName ())
117
123
.forks (1 )
@@ -134,8 +140,8 @@ private static BenchmarkResult convertToBenchmarkResult(String clientType,
134
140
String benchmarkName = extractBenchmarkName (fullBenchmarkName );
135
141
String parameters = extractParameters (fullBenchmarkName );
136
142
137
- // Log for debugging
138
- logger .info (String .format ("Converting: %s -> %s %s" , fullBenchmarkName , benchmarkName , parameters ));
143
+ // Log for debugging - update to use Supplier pattern
144
+ logger .info (() -> String .format ("Converting: %s -> %s %s" , fullBenchmarkName , benchmarkName , parameters ));
139
145
140
146
double throughput = runResult .getPrimaryResult ().getScore ();
141
147
double avgLatency = 1000.0 / throughput ;
@@ -157,7 +163,9 @@ private static BenchmarkResult convertToBenchmarkResult(String clientType,
157
163
}
158
164
159
165
private static String extractBenchmarkName (String fullLabel ) {
160
- if (fullLabel == null ) return "unknown" ;
166
+ if (fullLabel == null ) {
167
+ return "unknown" ;
168
+ }
161
169
162
170
// JMH format: package.ClassName.methodName
163
171
String methodPart = fullLabel ;
@@ -191,44 +199,47 @@ private static String extractParameters(String fullLabel) {
191
199
192
200
private static void printBenchmarkSummary (List <BenchmarkResult > results ) {
193
201
if (results == null || results .isEmpty ()) {
194
- logger .warning ( "No benchmark results to display" );
202
+ logger .warn (() -> "No benchmark results to display" );
195
203
return ;
196
204
}
197
205
198
- System . out . println ("\n " + repeatString ("=" , 140 ));
199
- System . out . println ("BENCHMARK RESULTS SUMMARY" );
200
- System . out . println (repeatString ("=" , 140 ));
206
+ printToConsole ("\n " + repeatString ("=" , 140 ));
207
+ printToConsole ("BENCHMARK RESULTS SUMMARY" );
208
+ printToConsole (repeatString ("=" , 140 ));
201
209
202
210
// Print header
203
- System . out . printf ("%-20s | %-50s | %-15s | %-15s | %-15s | %-10s%n " ,
204
- "Client Type" , "Benchmark" , "Throughput" , "Avg Latency" , "P99 Latency" , "Threads" );
205
- System . out . println (repeatString ("-" , 140 ));
211
+ printToConsole ( String . format ("%-20s | %-50s | %-15s | %-15s | %-15s | %-10s" ,
212
+ "Client Type" , "Benchmark" , "Throughput" , "Avg Latency" , "P99 Latency" , "Threads" ) );
213
+ printToConsole (repeatString ("-" , 140 ));
206
214
207
215
// Sort results for better readability
208
216
List <BenchmarkResult > sortedResults = results .stream ()
209
- .filter (r -> r != null && r .getClientType () != null && r .getBenchmarkName () != null )
217
+ .filter (r -> r != null && r .getClientType () != null
218
+ && r .getBenchmarkName () != null )
210
219
.sorted ((a , b ) -> {
211
220
int clientCompare = a .getClientType ().compareTo (b .getClientType ());
212
- if (clientCompare != 0 ) return clientCompare ;
221
+ if (clientCompare != 0 ) {
222
+ return clientCompare ;
223
+ }
213
224
return a .getBenchmarkName ().compareTo (b .getBenchmarkName ());
214
225
})
215
226
.collect (Collectors .toList ());
216
227
217
228
// Print all results (including parameter variations)
218
229
for (BenchmarkResult result : sortedResults ) {
219
- System . out . printf ("%-20s | %-50s | %,13.2f/s | %13.2f ms | %13.2f ms | %10d%n " ,
220
- result .getClientType (),
221
- result .getBenchmarkName (),
222
- result .getThroughput (),
223
- result .getAvgLatency (),
224
- result .getP99Latency (),
225
- result .getThreadCount ());
230
+ printToConsole ( String . format ("%-20s | %-50s | %,13.2f/s | %13.2f ms | %13.2f ms | %10d" ,
231
+ result .getClientType (),
232
+ result .getBenchmarkName (),
233
+ result .getThroughput (),
234
+ result .getAvgLatency (),
235
+ result .getP99Latency (),
236
+ result .getThreadCount () ));
226
237
}
227
238
228
- System . out . println (repeatString ("=" , 140 ));
229
- System . out . printf ("Total benchmark results: %d%n " , sortedResults .size ());
230
- System . out . println (repeatString ("=" , 140 ));
231
- // Print performance comparison in between Apache clients
239
+ printToConsole (repeatString ("=" , 140 ));
240
+ printToConsole ( String . format ("Total benchmark results: %d" , sortedResults .size () ));
241
+ printToConsole (repeatString ("=" , 140 ));
242
+ // Print performance comparison in between Apache clients for now
232
243
printApachePerformanceComparison (results );
233
244
234
245
}
@@ -238,29 +249,31 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
238
249
return ;
239
250
}
240
251
241
- System . out . println ("\n PERFORMANCE COMPARISON (Apache5 vs Apache4):" );
242
- System . out . println (repeatString ("=" , 80 ));
252
+ printToConsole ("\n PERFORMANCE COMPARISON (Apache5 vs Apache4):" );
253
+ printToConsole (repeatString ("=" , 80 ));
243
254
244
255
Map <String , List <BenchmarkResult >> groupedResults = results .stream ()
245
256
.filter (r -> r != null && r .getBenchmarkName () != null )
246
- .collect (Collectors .groupingBy (BenchmarkResult ::getBenchmarkName ));
257
+ .collect (Collectors
258
+ .groupingBy (BenchmarkResult ::getBenchmarkName ));
247
259
248
260
for (Map .Entry <String , List <BenchmarkResult >> entry : groupedResults .entrySet ()) {
249
261
String benchmarkName = entry .getKey ();
250
262
List <BenchmarkResult > benchmarkResults = entry .getValue ();
251
263
252
264
// Find Apache4 baseline
253
265
BenchmarkResult apache4 = benchmarkResults .stream ()
254
- .filter (r -> r .getClientType () != null && r .getClientType ().equals ("Apache4" ))
266
+ .filter (r -> r .getClientType () != null
267
+ && r .getClientType ().equals ("Apache4" ))
255
268
.findFirst ()
256
269
.orElse (null );
257
270
258
271
if (apache4 == null ) {
259
272
continue ;
260
273
}
261
274
262
- System . out . printf ("\n %s:%n " , benchmarkName );
263
- System . out . println (repeatString ("-" , 80 ));
275
+ printToConsole ( String . format ("\n %s:" , benchmarkName ) );
276
+ printToConsole (repeatString ("-" , 80 ));
264
277
265
278
for (BenchmarkResult result : benchmarkResults ) {
266
279
if (result .getClientType () != null && !result .getClientType ().equals ("Apache4" )) {
@@ -269,15 +282,15 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
269
282
double latencyImprovement = ((apache4 .getAvgLatency () - result .getAvgLatency ())
270
283
/ apache4 .getAvgLatency ()) * 100 ;
271
284
272
- System . out . printf (" %-20s: %+.1f%% throughput, %+.1f%% latency improvement%n " ,
273
- result .getClientType (),
274
- throughputImprovement ,
275
- latencyImprovement );
285
+ printToConsole ( String . format (" %-20s: %+.1f%% throughput, %+.1f%% latency improvement" ,
286
+ result .getClientType (),
287
+ throughputImprovement ,
288
+ latencyImprovement ) );
276
289
}
277
290
}
278
291
}
279
292
280
- System . out . println ("\n " + repeatString ("=" , 80 ));
293
+ printToConsole ("\n " + repeatString ("=" , 80 ));
281
294
}
282
295
283
296
private static String repeatString (String str , int count ) {
0 commit comments