31
31
import software .amazon .awssdk .benchmark .core .BenchmarkResult ;
32
32
import software .amazon .awssdk .benchmark .metrics .CloudWatchMetricsPublisher ;
33
33
import software .amazon .awssdk .regions .Region ;
34
-
35
34
import java .time .Instant ;
36
35
import java .util .logging .Logger ;
37
36
import java .util .stream .Collectors ;
37
+ import software .amazon .awssdk .benchmark .apache5 .Apache5VirtualBenchmark ;
38
38
39
- public class UnifiedBenchmarkRunner {
39
+ public final class UnifiedBenchmarkRunner {
40
40
private static final Logger logger = Logger .getLogger (UnifiedBenchmarkRunner .class .getName ());
41
41
42
+ private UnifiedBenchmarkRunner () {
43
+ }
44
+
45
+ private static boolean isJava21OrHigher () {
46
+ String version = System .getProperty ("java.version" );
47
+ if (version .startsWith ("1." )) {
48
+ version = version .substring (2 );
49
+ }
50
+ int dotPos = version .indexOf ('.' );
51
+ int majorVersion ;
52
+ if (dotPos != -1 ) {
53
+ majorVersion = Integer .parseInt (version .substring (0 , dotPos ));
54
+ } else {
55
+ majorVersion = Integer .parseInt (version );
56
+ }
57
+ return majorVersion >= 21 ;
58
+ }
59
+
42
60
public static void main (String [] args ) throws Exception {
43
61
logger .info ("Starting unified benchmark comparison" );
44
62
@@ -56,12 +74,17 @@ public static void main(String[] args) throws Exception {
56
74
allResults .addAll (runBenchmark ("Apache4" , Apache4Benchmark .class , null ));
57
75
58
76
// Run Apache5 with platform threads
59
- logger .info ("Running Apache5 with platform threads..." );
60
- allResults .addAll (runBenchmark ("Apache5-Platform" , Apache5Benchmark .class , "platform" ));
61
-
62
- // Run Apache5 with virtual threads
63
- logger .info ("Running Apache5 with virtual threads..." );
64
- allResults .addAll (runBenchmark ("Apache5-Virtual" , Apache5Benchmark .class , "virtual" ));
77
+ logger .info ("Running Apache5..." );
78
+ allResults .addAll (runBenchmark ("Apache5" , Apache5Benchmark .class , null ));
79
+
80
+ // Only run virtual threads benchmark if Java 21+
81
+ if (isJava21OrHigher ()) {
82
+ logger .info ("Running Apache5 with virtual threads..." );
83
+ allResults .addAll (runBenchmark ("Apache5-Virtual" , Apache5VirtualBenchmark .class , null ));
84
+ } else {
85
+ logger .info ("Skipping virtual threads benchmark - requires Java 21 or higher (current: " +
86
+ System .getProperty ("java.version" ) + ")" );
87
+ }
65
88
66
89
// Debug: Print all results to understand the structure
67
90
logger .info ("All benchmark results:" );
@@ -95,10 +118,6 @@ private static List<BenchmarkResult> runBenchmark(String clientType,
95
118
.warmupIterations (2 )
96
119
.measurementIterations (3 );
97
120
98
- if (executorType != null ) {
99
- optBuilder .param ("executorType" , executorType );
100
- }
101
-
102
121
Options opt = optBuilder .build ();
103
122
Collection <RunResult > runResults = new Runner (opt ).run ();
104
123
@@ -176,14 +195,14 @@ private static void printBenchmarkSummary(List<BenchmarkResult> results) {
176
195
return ;
177
196
}
178
197
179
- System .out .println ("\n " + "=" . repeat ( 140 ));
198
+ System .out .println ("\n " + repeatString ( "=" , 140 ));
180
199
System .out .println ("BENCHMARK RESULTS SUMMARY" );
181
- System .out .println ("=" . repeat ( 140 ));
200
+ System .out .println (repeatString ( "=" , 140 ));
182
201
183
202
// Print header
184
203
System .out .printf ("%-20s | %-50s | %-15s | %-15s | %-15s | %-10s%n" ,
185
204
"Client Type" , "Benchmark" , "Throughput" , "Avg Latency" , "P99 Latency" , "Threads" );
186
- System .out .println ("-" . repeat ( 140 ));
205
+ System .out .println (repeatString ( "-" , 140 ));
187
206
188
207
// Sort results for better readability
189
208
List <BenchmarkResult > sortedResults = results .stream ()
@@ -206,9 +225,9 @@ private static void printBenchmarkSummary(List<BenchmarkResult> results) {
206
225
result .getThreadCount ());
207
226
}
208
227
209
- System .out .println ("=" . repeat ( 140 ));
228
+ System .out .println (repeatString ( "=" , 140 ));
210
229
System .out .printf ("Total benchmark results: %d%n" , sortedResults .size ());
211
- System .out .println ("=" . repeat ( 140 ));
230
+ System .out .println (repeatString ( "=" , 140 ));
212
231
// Print performance comparison in between Apache clients
213
232
printApachePerformanceComparison (results );
214
233
@@ -220,7 +239,7 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
220
239
}
221
240
222
241
System .out .println ("\n PERFORMANCE COMPARISON (Apache5 vs Apache4):" );
223
- System .out .println ("=" . repeat ( 80 ));
242
+ System .out .println (repeatString ( "=" , 80 ));
224
243
225
244
Map <String , List <BenchmarkResult >> groupedResults = results .stream ()
226
245
.filter (r -> r != null && r .getBenchmarkName () != null )
@@ -241,7 +260,7 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
241
260
}
242
261
243
262
System .out .printf ("\n %s:%n" , benchmarkName );
244
- System .out .println ("-" . repeat ( 80 ));
263
+ System .out .println (repeatString ( "-" , 80 ));
245
264
246
265
for (BenchmarkResult result : benchmarkResults ) {
247
266
if (result .getClientType () != null && !result .getClientType ().equals ("Apache4" )) {
@@ -258,7 +277,14 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
258
277
}
259
278
}
260
279
261
- System .out .println ("\n " + "=" . repeat ( 80 ));
280
+ System .out .println ("\n " + repeatString ( "=" , 80 ));
262
281
}
263
282
283
+ private static String repeatString (String str , int count ) {
284
+ StringBuilder sb = new StringBuilder (str .length () * count );
285
+ for (int i = 0 ; i < count ; i ++) {
286
+ sb .append (str );
287
+ }
288
+ return sb .toString ();
289
+ }
264
290
}
0 commit comments