Skip to content

Commit 99e697e

Browse files
committed
fixed checksyle issues
1 parent 29ab8d9 commit 99e697e

File tree

9 files changed

+353
-384
lines changed

9 files changed

+353
-384
lines changed

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

Lines changed: 110 additions & 114 deletions
Large diffs are not rendered by default.

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

Lines changed: 42 additions & 71 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;
@@ -63,114 +60,88 @@ public class Apache4Benchmark implements CoreBenchmark {
6360
private int threadCount;
6461

6562
private S3Client s3Client;
66-
private S3BenchmarkImpl benchmark;
67-
private ExecutorService platformThreadPool;
63+
private S3BenchmarkImpl s3Benchmark;
64+
private ExecutorService executor;
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 " + threadCount + " threads");
7269

73-
// Apache 4 HTTP client
7470
SdkHttpClient httpClient = ApacheHttpClient.builder()
75-
.maxConnections(maxConnections)
7671
.connectionTimeout(Duration.ofSeconds(10))
7772
.socketTimeout(Duration.ofSeconds(30))
7873
.connectionAcquisitionTimeout(Duration.ofSeconds(10))
79-
.connectionMaxIdleTime(Duration.ofSeconds(60))
80-
.connectionTimeToLive(Duration.ofMinutes(5))
81-
.useIdleConnectionReaper(true)
74+
.maxConnections(maxConnections)
8275
.build();
8376

84-
// S3 client
8577
s3Client = S3Client.builder()
8678
.region(Region.US_WEST_2)
87-
.credentialsProvider(DefaultCredentialsProvider.create())
8879
.httpClient(httpClient)
8980
.build();
9081

91-
// Initialize benchmark implementation
92-
benchmark = new S3BenchmarkImpl(s3Client);
93-
benchmark.setup();
82+
s3Benchmark = new S3BenchmarkImpl(s3Client);
83+
s3Benchmark.setup();
9484

95-
// Platform thread pool for multi-threaded tests
96-
platformThreadPool = Executors.newFixedThreadPool(threadCount, r -> {
97-
Thread t = new Thread(r);
98-
t.setName("apache4-platform-worker-" + t.getId());
99-
return t;
100-
});
85+
executor = Executors.newFixedThreadPool(threadCount);
86+
}
10187

102-
logger.info("Apache4 benchmark setup complete");
88+
@TearDown(Level.Trial)
89+
public void teardown() {
90+
logger.info(() -> "Tearing down Apache4 benchmark");
91+
s3Benchmark.cleanup();
92+
s3Client.close();
93+
executor.shutdown();
94+
try {
95+
if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
96+
executor.shutdownNow();
97+
}
98+
} catch (InterruptedException e) {
99+
executor.shutdownNow();
100+
Thread.currentThread().interrupt();
101+
}
103102
}
104103

105104
@Benchmark
106105
@Override
107106
public void simpleGet(Blackhole blackhole) throws Exception {
108-
benchmark.executeGet("medium", blackhole);
107+
s3Benchmark.executeGet("5MB", blackhole);
109108
}
110109

111110
@Benchmark
112111
@Override
113-
public void simplePut(Blackhole blackhole) throws Exception {
114-
benchmark.executePut("medium", blackhole);
112+
public void simplePut(Blackhole blackhole) {
113+
s3Benchmark.executePut("5MB", blackhole);
115114
}
116115

117116
@Benchmark
118117
@Override
119118
public void multiThreadedGet(Blackhole blackhole) throws Exception {
120-
runMultiThreaded(platformThreadPool, threadCount, blackhole, true);
121-
}
122-
123-
@Benchmark
124-
@Override
125-
public void multiThreadedPut(Blackhole blackhole) throws Exception {
126-
runMultiThreaded(platformThreadPool, threadCount, blackhole, false);
127-
}
128-
129-
protected void runMultiThreaded(ExecutorService executor, int threads,
130-
Blackhole blackhole, boolean isGet) throws Exception {
131-
List<Future<?>> futures = new ArrayList<>(threads);
132-
133-
for (int i = 0; i < threads; i++) {
119+
List<Future<?>> futures = new ArrayList<>();
120+
for (int i = 0; i < threadCount; i++) {
134121
futures.add(executor.submit(() -> {
135122
try {
136-
if (isGet) {
137-
benchmark.executeGet("medium", blackhole);
138-
} else {
139-
benchmark.executePut("medium", blackhole);
140-
}
123+
s3Benchmark.executeGet("5MB", blackhole);
141124
} catch (Exception e) {
142-
throw new RuntimeException("Operation failed", e);
125+
throw new RuntimeException(e);
143126
}
144127
}));
145128
}
146129

147-
// Wait for all operations to complete
148130
for (Future<?> future : futures) {
149131
future.get();
150132
}
151133
}
152134

153-
@TearDown(Level.Trial)
154-
public void tearDown() {
155-
logger.info("Tearing down Apache4 benchmark");
156-
157-
if (platformThreadPool != null) {
158-
platformThreadPool.shutdown();
159-
try {
160-
if (!platformThreadPool.awaitTermination(30, TimeUnit.SECONDS)) {
161-
platformThreadPool.shutdownNow();
162-
}
163-
} catch (InterruptedException e) {
164-
platformThreadPool.shutdownNow();
165-
}
166-
}
167-
168-
if (benchmark != null) {
169-
benchmark.cleanup();
135+
@Benchmark
136+
@Override
137+
public void multiThreadedPut(Blackhole blackhole) throws Exception {
138+
List<Future<?>> futures = new ArrayList<>();
139+
for (int i = 0; i < threadCount; i++) {
140+
futures.add(executor.submit(() -> s3Benchmark.executePut("5MB", blackhole)));
170141
}
171142

172-
if (s3Client != null) {
173-
s3Client.close();
143+
for (Future<?> future : futures) {
144+
future.get();
174145
}
175146
}
176147
}

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

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

1616
package software.amazon.awssdk.benchmark.apache5;
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;
@@ -41,25 +43,7 @@
4143
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
4244
import software.amazon.awssdk.regions.Region;
4345
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;
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-
*/
46+
import software.amazon.awssdk.utils.Logger;
6347

6448
@BenchmarkMode(Mode.Throughput)
6549
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -68,86 +52,83 @@
6852
@Warmup(iterations = 3, time = 15, timeUnit = TimeUnit.SECONDS)
6953
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
7054
public class Apache5Benchmark implements CoreBenchmark {
71-
private static final Logger logger = Logger.getLogger(Apache5Benchmark.class.getName());
55+
private static final Logger logger = Logger.loggerFor(Apache5Benchmark.class);
7256

73-
@Param({"50"})
57+
@Param("50")
7458
private int maxConnections;
7559

76-
@Param({"10"})
60+
@Param("20")
7761
private int threadCount;
7862

79-
@Param({"platform"})
80-
private String executorType;
81-
8263
private S3Client s3Client;
83-
private S3BenchmarkImpl benchmark;
84-
private ExecutorService executorService;
64+
private S3BenchmarkImpl s3Benchmark;
65+
private ExecutorService executor;
8566

8667
@Setup(Level.Trial)
8768
public void setup() {
88-
logger.info("Setting up Apache5 benchmark with maxConnections=" + maxConnections);
69+
logger.info(() -> "Setting up Apache5 benchmark with " + threadCount + " threads");
8970

90-
// Apache 5 HTTP client
9171
SdkHttpClient httpClient = Apache5HttpClient.builder()
92-
.maxConnections(maxConnections)
9372
.connectionTimeout(Duration.ofSeconds(10))
9473
.socketTimeout(Duration.ofSeconds(30))
9574
.connectionAcquisitionTimeout(Duration.ofSeconds(10))
96-
.connectionMaxIdleTime(Duration.ofSeconds(60))
97-
.connectionTimeToLive(Duration.ofMinutes(5))
98-
.useIdleConnectionReaper(true)
75+
.maxConnections(maxConnections)
9976
.build();
10077

101-
// S3 client
10278
s3Client = S3Client.builder()
10379
.region(Region.US_WEST_2)
10480
.credentialsProvider(DefaultCredentialsProvider.create())
10581
.httpClient(httpClient)
10682
.build();
10783

108-
// Initialize benchmark implementation
109-
benchmark = new S3BenchmarkImpl(s3Client);
110-
benchmark.setup();
84+
s3Benchmark = new S3BenchmarkImpl(s3Client);
85+
s3Benchmark.setup();
11186

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");
87+
executor = Executors.newFixedThreadPool(threadCount);
88+
}
11989

120-
logger.info("Apache5 benchmark setup complete");
90+
@TearDown(Level.Trial)
91+
public void teardown() {
92+
logger.info(() -> "Tearing down Apache5 benchmark");
93+
s3Benchmark.cleanup();
94+
s3Client.close();
95+
executor.shutdown();
96+
try {
97+
if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
98+
executor.shutdownNow();
99+
}
100+
} catch (InterruptedException e) {
101+
executor.shutdownNow();
102+
Thread.currentThread().interrupt();
103+
}
121104
}
122105

123106
@Benchmark
124107
@Override
125108
public void simpleGet(Blackhole blackhole) throws Exception {
126-
benchmark.executeGet("medium", blackhole);
109+
s3Benchmark.executeGet("5MB", blackhole);
127110
}
128111

129112
@Benchmark
130113
@Override
131-
public void simplePut(Blackhole blackhole) throws Exception {
132-
benchmark.executePut("medium", blackhole);
114+
public void simplePut(Blackhole blackhole) {
115+
s3Benchmark.executePut("5MB", blackhole);
133116
}
134117

135118
@Benchmark
136119
@Override
137120
public void multiThreadedGet(Blackhole blackhole) throws Exception {
138-
List<Future<?>> futures = new ArrayList<>(threadCount);
139-
121+
List<Future<?>> futures = new ArrayList<>();
140122
for (int i = 0; i < threadCount; i++) {
141-
futures.add(executorService.submit(() -> {
123+
futures.add(executor.submit(() -> {
142124
try {
143-
benchmark.executeGet("medium", blackhole);
125+
s3Benchmark.executeGet("5MB", blackhole);
144126
} catch (Exception e) {
145-
throw new RuntimeException("GET operation failed", e);
127+
throw new RuntimeException(e);
146128
}
147129
}));
148130
}
149131

150-
// Wait for all operations to complete
151132
for (Future<?> future : futures) {
152133
future.get();
153134
}
@@ -156,45 +137,13 @@ public void multiThreadedGet(Blackhole blackhole) throws Exception {
156137
@Benchmark
157138
@Override
158139
public void multiThreadedPut(Blackhole blackhole) throws Exception {
159-
List<Future<?>> futures = new ArrayList<>(threadCount);
160-
140+
List<Future<?>> futures = new ArrayList<>();
161141
for (int i = 0; i < threadCount; i++) {
162-
futures.add(executorService.submit(() -> {
163-
try {
164-
benchmark.executePut("medium", blackhole);
165-
} catch (Exception e) {
166-
throw new RuntimeException("PUT operation failed", e);
167-
}
168-
}));
142+
futures.add(executor.submit(() -> s3Benchmark.executePut("5MB", blackhole)));
169143
}
170144

171-
// Wait for all operations to complete
172145
for (Future<?> future : futures) {
173146
future.get();
174147
}
175148
}
176-
177-
@TearDown(Level.Trial)
178-
public void tearDown() {
179-
logger.info("Tearing down Apache5 benchmark");
180-
181-
if (executorService != null) {
182-
executorService.shutdown();
183-
try {
184-
if (!executorService.awaitTermination(30, TimeUnit.SECONDS)) {
185-
executorService.shutdownNow();
186-
}
187-
} catch (InterruptedException e) {
188-
executorService.shutdownNow();
189-
}
190-
}
191-
192-
if (benchmark != null) {
193-
benchmark.cleanup();
194-
}
195-
196-
if (s3Client != null) {
197-
s3Client.close();
198-
}
199-
}
200149
}

0 commit comments

Comments
 (0)