Skip to content

Commit ad00477

Browse files
committed
Fixed checkstyle issues
1 parent c7dff89 commit ad00477

File tree

10 files changed

+171
-185
lines changed

10 files changed

+171
-185
lines changed

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

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
package software.amazon.awssdk.benchmark;
1717

18-
18+
import java.time.Instant;
1919
import java.util.ArrayList;
2020
import java.util.Collection;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.stream.Collectors;
2324
import org.openjdk.jmh.results.RunResult;
2425
import org.openjdk.jmh.runner.Runner;
2526
import org.openjdk.jmh.runner.RunnerException;
@@ -28,22 +29,28 @@
2829
import org.openjdk.jmh.runner.options.OptionsBuilder;
2930
import software.amazon.awssdk.benchmark.apache4.Apache4Benchmark;
3031
import software.amazon.awssdk.benchmark.apache5.Apache5Benchmark;
32+
import software.amazon.awssdk.benchmark.apache5.Apache5VirtualBenchmark;
3133
import software.amazon.awssdk.benchmark.core.BenchmarkResult;
3234
import software.amazon.awssdk.benchmark.metrics.CloudWatchMetricsPublisher;
3335
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;
3838

3939
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);
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("\nBenchmark complete! CloudWatch metrics published with run ID: " + runId);
109+
logger.info(() -> "\nBenchmark 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("\nPERFORMANCE COMPARISON (Apache5 vs Apache4):");
242-
System.out.println(repeatString("=", 80));
252+
printToConsole("\nPERFORMANCE 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) {

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
package software.amazon.awssdk.benchmark.apache4;
1717

18-
18+
import java.time.Duration;
19+
import java.util.ArrayList;
20+
import java.util.List;
1921
import java.util.concurrent.ExecutorService;
2022
import java.util.concurrent.Executors;
2123
import java.util.concurrent.Future;
@@ -34,18 +36,13 @@
3436
import org.openjdk.jmh.annotations.TearDown;
3537
import org.openjdk.jmh.annotations.Warmup;
3638
import org.openjdk.jmh.infra.Blackhole;
37-
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
3839
import software.amazon.awssdk.benchmark.core.CoreBenchmark;
3940
import software.amazon.awssdk.benchmark.core.S3BenchmarkImpl;
4041
import software.amazon.awssdk.http.SdkHttpClient;
4142
import software.amazon.awssdk.http.apache.ApacheHttpClient;
4243
import software.amazon.awssdk.regions.Region;
4344
import software.amazon.awssdk.services.s3.S3Client;
44-
45-
import java.time.Duration;
46-
import java.util.ArrayList;
47-
import java.util.List;
48-
import java.util.logging.Logger;
45+
import software.amazon.awssdk.utils.Logger;
4946

5047
@BenchmarkMode(Mode.Throughput)
5148
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -54,7 +51,7 @@
5451
@Warmup(iterations = 3, time = 15, timeUnit = TimeUnit.SECONDS)
5552
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
5653
public class Apache4Benchmark implements CoreBenchmark {
57-
private static final Logger logger = Logger.getLogger(Apache4Benchmark.class.getName());
54+
private static final Logger logger = Logger.loggerFor(Apache4Benchmark.class);
5855

5956
@Param({"50"})
6057
private int maxConnections;
@@ -68,23 +65,19 @@ public class Apache4Benchmark implements CoreBenchmark {
6865

6966
@Setup(Level.Trial)
7067
public void setup() {
71-
logger.info("Setting up Apache4 benchmark with maxConnections=" + maxConnections);
68+
logger.info(() -> "Setting up Apache4 benchmark with maxConnections=" + maxConnections);
7269

7370
// Apache 4 HTTP client
7471
SdkHttpClient httpClient = ApacheHttpClient.builder()
75-
.maxConnections(maxConnections)
7672
.connectionTimeout(Duration.ofSeconds(10))
7773
.socketTimeout(Duration.ofSeconds(30))
7874
.connectionAcquisitionTimeout(Duration.ofSeconds(10))
79-
.connectionMaxIdleTime(Duration.ofSeconds(60))
80-
.connectionTimeToLive(Duration.ofMinutes(5))
81-
.useIdleConnectionReaper(true)
75+
.maxConnections(maxConnections)
8276
.build();
8377

8478
// S3 client
8579
s3Client = S3Client.builder()
8680
.region(Region.US_WEST_2)
87-
.credentialsProvider(DefaultCredentialsProvider.create())
8881
.httpClient(httpClient)
8982
.build();
9083

@@ -99,7 +92,8 @@ public void setup() {
9992
return t;
10093
});
10194

102-
logger.info("Apache4 benchmark setup complete");
95+
// Update logging call to use Supplier pattern
96+
logger.info(() -> "Apache4 benchmark setup complete");
10397
}
10498

10599
@Benchmark
@@ -152,7 +146,7 @@ protected void runMultiThreaded(ExecutorService executor, int threads,
152146

153147
@TearDown(Level.Trial)
154148
public void tearDown() {
155-
logger.info("Tearing down Apache4 benchmark");
149+
logger.info(() -> "Tearing down Apache4 benchmark");
156150

157151
if (platformThreadPool != null) {
158152
platformThreadPool.shutdown();

0 commit comments

Comments
 (0)