Skip to content

Commit 78ac2e2

Browse files
committed
updated to run on jdk8
1 parent d382185 commit 78ac2e2

File tree

6 files changed

+326
-47
lines changed

6 files changed

+326
-47
lines changed

test/http-client-benchmarks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<properties>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3434
<jmh.version>1.37</jmh.version>
35-
<javac.target>21</javac.target>
35+
<javac.target>8</javac.target>
3636
<uberjar.name>http-client-benchmarks</uberjar.name>
3737
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
3838
</properties>

test/http-client-benchmarks/src/main/java/software/amazon/awssdk/benchmark/UnifiedBenchmarkRunner.java

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,32 @@
3131
import software.amazon.awssdk.benchmark.core.BenchmarkResult;
3232
import software.amazon.awssdk.benchmark.metrics.CloudWatchMetricsPublisher;
3333
import software.amazon.awssdk.regions.Region;
34-
3534
import java.time.Instant;
3635
import java.util.logging.Logger;
3736
import java.util.stream.Collectors;
37+
import software.amazon.awssdk.benchmark.apache5.Apache5VirtualBenchmark;
3838

39-
public class UnifiedBenchmarkRunner {
39+
public final class UnifiedBenchmarkRunner {
4040
private static final Logger logger = Logger.getLogger(UnifiedBenchmarkRunner.class.getName());
4141

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+
4260
public static void main(String[] args) throws Exception {
4361
logger.info("Starting unified benchmark comparison");
4462

@@ -56,12 +74,17 @@ public static void main(String[] args) throws Exception {
5674
allResults.addAll(runBenchmark("Apache4", Apache4Benchmark.class, null));
5775

5876
// 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+
}
6588

6689
// Debug: Print all results to understand the structure
6790
logger.info("All benchmark results:");
@@ -95,10 +118,6 @@ private static List<BenchmarkResult> runBenchmark(String clientType,
95118
.warmupIterations(2)
96119
.measurementIterations(3);
97120

98-
if (executorType != null) {
99-
optBuilder.param("executorType", executorType);
100-
}
101-
102121
Options opt = optBuilder.build();
103122
Collection<RunResult> runResults = new Runner(opt).run();
104123

@@ -176,14 +195,14 @@ private static void printBenchmarkSummary(List<BenchmarkResult> results) {
176195
return;
177196
}
178197

179-
System.out.println("\n" + "=".repeat(140));
198+
System.out.println("\n" + repeatString("=", 140));
180199
System.out.println("BENCHMARK RESULTS SUMMARY");
181-
System.out.println("=".repeat(140));
200+
System.out.println(repeatString("=", 140));
182201

183202
// Print header
184203
System.out.printf("%-20s | %-50s | %-15s | %-15s | %-15s | %-10s%n",
185204
"Client Type", "Benchmark", "Throughput", "Avg Latency", "P99 Latency", "Threads");
186-
System.out.println("-".repeat(140));
205+
System.out.println(repeatString("-", 140));
187206

188207
// Sort results for better readability
189208
List<BenchmarkResult> sortedResults = results.stream()
@@ -206,9 +225,9 @@ private static void printBenchmarkSummary(List<BenchmarkResult> results) {
206225
result.getThreadCount());
207226
}
208227

209-
System.out.println("=".repeat(140));
228+
System.out.println(repeatString("=", 140));
210229
System.out.printf("Total benchmark results: %d%n", sortedResults.size());
211-
System.out.println("=".repeat(140));
230+
System.out.println(repeatString("=", 140));
212231
// Print performance comparison in between Apache clients
213232
printApachePerformanceComparison(results);
214233

@@ -220,7 +239,7 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
220239
}
221240

222241
System.out.println("\nPERFORMANCE COMPARISON (Apache5 vs Apache4):");
223-
System.out.println("=".repeat(80));
242+
System.out.println(repeatString("=", 80));
224243

225244
Map<String, List<BenchmarkResult>> groupedResults = results.stream()
226245
.filter(r -> r != null && r.getBenchmarkName() != null)
@@ -241,7 +260,7 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
241260
}
242261

243262
System.out.printf("\n%s:%n", benchmarkName);
244-
System.out.println("-".repeat(80));
263+
System.out.println(repeatString("-", 80));
245264

246265
for (BenchmarkResult result : benchmarkResults) {
247266
if (result.getClientType() != null && !result.getClientType().equals("Apache4")) {
@@ -258,7 +277,14 @@ private static void printApachePerformanceComparison(List<BenchmarkResult> resul
258277
}
259278
}
260279

261-
System.out.println("\n" + "=".repeat(80));
280+
System.out.println("\n" + repeatString("=", 80));
262281
}
263282

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+
}
264290
}

test/http-client-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apache4/Apache4Benchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class Apache4Benchmark implements CoreBenchmark {
5959
@Param({"50"})
6060
private int maxConnections;
6161

62-
@Param({"10"})
62+
@Param({"20"})
6363
private int threadCount;
6464

6565
private S3Client s3Client;

test/http-client-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apache5/Apache5Benchmark.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@
4646
import java.util.ArrayList;
4747
import java.util.List;
4848
import java.util.logging.Logger;
49+
/*
50+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
51+
*
52+
* Licensed under the Apache License, Version 2.0 (the "License").
53+
* You may not use this file except in compliance with the License.
54+
* A copy of the License is located at
55+
*
56+
* http://aws.amazon.com/apache2.0
57+
*
58+
* or in the "license" file accompanying this file. This file is distributed
59+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
60+
* express or implied. See the License for the specific language governing
61+
* permissions and limitations under the License.
62+
*/
4963

5064
@BenchmarkMode(Mode.Throughput)
5165
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -62,7 +76,7 @@ public class Apache5Benchmark implements CoreBenchmark {
6276
@Param({"10"})
6377
private int threadCount;
6478

65-
@Param({"platform", "virtual"})
79+
@Param({"platform"})
6680
private String executorType;
6781

6882
private S3Client s3Client;
@@ -71,8 +85,7 @@ public class Apache5Benchmark implements CoreBenchmark {
7185

7286
@Setup(Level.Trial)
7387
public void setup() {
74-
logger.info("Setting up Apache5 benchmark with maxConnections=" + maxConnections +
75-
", executorType=" + executorType);
88+
logger.info("Setting up Apache5 benchmark with maxConnections=" + maxConnections);
7689

7790
// Apache 5 HTTP client
7891
SdkHttpClient httpClient = Apache5HttpClient.builder()
@@ -96,18 +109,13 @@ public void setup() {
96109
benchmark = new S3BenchmarkImpl(s3Client);
97110
benchmark.setup();
98111

99-
// Create appropriate executor based on parameter
100-
if ("virtual".equals(executorType)) {
101-
executorService = Executors.newVirtualThreadPerTaskExecutor();
102-
logger.info("Using virtual thread executor");
103-
} else {
104-
executorService = Executors.newFixedThreadPool(threadCount, r -> {
105-
Thread t = new Thread(r);
106-
t.setName("apache5-platform-worker-" + t.getId());
107-
return t;
108-
});
109-
logger.info("Using platform thread executor");
110-
}
112+
// Always use platform threads
113+
executorService = Executors.newFixedThreadPool(threadCount, r -> {
114+
Thread t = new Thread(r);
115+
t.setName("apache5-platform-worker-" + t.getId());
116+
return t;
117+
});
118+
logger.info("Using platform thread executor");
111119

112120
logger.info("Apache5 benchmark setup complete");
113121
}

0 commit comments

Comments
 (0)