1515
1616package software .amazon .awssdk .benchmark ;
1717
18-
18+ import java . time . Instant ;
1919import java .util .ArrayList ;
2020import java .util .Collection ;
2121import java .util .List ;
2222import java .util .Map ;
23+ import java .util .stream .Collectors ;
2324import org .openjdk .jmh .results .RunResult ;
2425import org .openjdk .jmh .runner .Runner ;
2526import org .openjdk .jmh .runner .RunnerException ;
2829import org .openjdk .jmh .runner .options .OptionsBuilder ;
2930import software .amazon .awssdk .benchmark .apache4 .Apache4Benchmark ;
3031import software .amazon .awssdk .benchmark .apache5 .Apache5Benchmark ;
32+ import software .amazon .awssdk .benchmark .apache5 .Apache5VirtualBenchmark ;
3133import software .amazon .awssdk .benchmark .core .BenchmarkResult ;
3234import software .amazon .awssdk .benchmark .metrics .CloudWatchMetricsPublisher ;
3335import 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 ;
3838
3939public final class UnifiedBenchmarkRunner {
40- private static final Logger logger = Logger .getLogger (UnifiedBenchmarkRunner .class . getName () );
40+ private static final Logger logger = Logger .loggerFor (UnifiedBenchmarkRunner .class );
4141
4242 private UnifiedBenchmarkRunner () {
4343 }
4444
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+
4551 private static boolean isJava21OrHigher () {
46- String version = System .getProperty ("java.version" );
52+
53+ String version = JavaSystemSetting .JAVA_VERSION .getStringValueOrThrow ();
4754 if (version .startsWith ("1." )) {
4855 version = version .substring (2 );
4956 }
@@ -58,7 +65,8 @@ private static boolean isJava21OrHigher() {
5865 }
5966
6067 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" );
6270
6371 String runId = Instant .now ().toString ();
6472 CloudWatchMetricsPublisher publisher = new CloudWatchMetricsPublisher (
@@ -70,35 +78,35 @@ public static void main(String[] args) throws Exception {
7078
7179 try {
7280 // 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 ));
7583
7684 // 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 ));
7987
8088 // Only run virtual threads benchmark if Java 21+
8189 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 ));
8492 } 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 ( ) + ")" );
8795 }
8896
8997 // Debug: Print all results to understand the structure
90- logger .info ("All benchmark results:" );
98+ logger .info (() -> "All benchmark results:" );
9199 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 ()));
94102 }
95103
96104 // Publish results to CloudWatch
97- logger .info ("Publishing results to CloudWatch..." );
105+ logger .info (() -> "Publishing results to CloudWatch..." );
98106 for (BenchmarkResult result : allResults ) {
99107 publisher .publishBenchmarkResult (result , runId );
100108 }
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 );
102110
103111 // Print benchmark results summary
104112 printBenchmarkSummary (allResults );
@@ -109,9 +117,7 @@ public static void main(String[] args) throws Exception {
109117 }
110118
111119 private static List <BenchmarkResult > runBenchmark (String clientType ,
112- Class <?> benchmarkClass ,
113- String executorType )
114- throws RunnerException {
120+ Class <?> benchmarkClass ) throws RunnerException {
115121 ChainedOptionsBuilder optBuilder = new OptionsBuilder ()
116122 .include (benchmarkClass .getSimpleName ())
117123 .forks (1 )
@@ -134,8 +140,8 @@ private static BenchmarkResult convertToBenchmarkResult(String clientType,
134140 String benchmarkName = extractBenchmarkName (fullBenchmarkName );
135141 String parameters = extractParameters (fullBenchmarkName );
136142
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 ));
139145
140146 double throughput = runResult .getPrimaryResult ().getScore ();
141147 double avgLatency = 1000.0 / throughput ;
@@ -157,7 +163,9 @@ private static BenchmarkResult convertToBenchmarkResult(String clientType,
157163 }
158164
159165 private static String extractBenchmarkName (String fullLabel ) {
160- if (fullLabel == null ) return "unknown" ;
166+ if (fullLabel == null ) {
167+ return "unknown" ;
168+ }
161169
162170 // JMH format: package.ClassName.methodName
163171 String methodPart = fullLabel ;
@@ -191,44 +199,47 @@ private static String extractParameters(String fullLabel) {
191199
192200 private static void printBenchmarkSummary (List <BenchmarkResult > results ) {
193201 if (results == null || results .isEmpty ()) {
194- logger .warning ( "No benchmark results to display" );
202+ logger .warn (() -> "No benchmark results to display" );
195203 return ;
196204 }
197205
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 ));
201209
202210 // 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 ));
206214
207215 // Sort results for better readability
208216 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 )
210219 .sorted ((a , b ) -> {
211220 int clientCompare = a .getClientType ().compareTo (b .getClientType ());
212- if (clientCompare != 0 ) return clientCompare ;
221+ if (clientCompare != 0 ) {
222+ return clientCompare ;
223+ }
213224 return a .getBenchmarkName ().compareTo (b .getBenchmarkName ());
214225 })
215226 .collect (Collectors .toList ());
216227
217228 // Print all results (including parameter variations)
218229 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 () ));
226237 }
227238
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
232243 printApachePerformanceComparison (results );
233244
234245 }
@@ -238,29 +249,31 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
238249 return ;
239250 }
240251
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 ));
243254
244255 Map <String , List <BenchmarkResult >> groupedResults = results .stream ()
245256 .filter (r -> r != null && r .getBenchmarkName () != null )
246- .collect (Collectors .groupingBy (BenchmarkResult ::getBenchmarkName ));
257+ .collect (Collectors
258+ .groupingBy (BenchmarkResult ::getBenchmarkName ));
247259
248260 for (Map .Entry <String , List <BenchmarkResult >> entry : groupedResults .entrySet ()) {
249261 String benchmarkName = entry .getKey ();
250262 List <BenchmarkResult > benchmarkResults = entry .getValue ();
251263
252264 // Find Apache4 baseline
253265 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" ))
255268 .findFirst ()
256269 .orElse (null );
257270
258271 if (apache4 == null ) {
259272 continue ;
260273 }
261274
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 ));
264277
265278 for (BenchmarkResult result : benchmarkResults ) {
266279 if (result .getClientType () != null && !result .getClientType ().equals ("Apache4" )) {
@@ -269,15 +282,15 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
269282 double latencyImprovement = ((apache4 .getAvgLatency () - result .getAvgLatency ())
270283 / apache4 .getAvgLatency ()) * 100 ;
271284
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 ) );
276289 }
277290 }
278291 }
279292
280- System . out . println ("\n " + repeatString ("=" , 80 ));
293+ printToConsole ("\n " + repeatString ("=" , 80 ));
281294 }
282295
283296 private static String repeatString (String str , int count ) {
0 commit comments