Skip to content

Commit c7dff89

Browse files
committed
Revert "fixed checksyle issues"
This reverts commit 99e697e.
1 parent 1d2a5b5 commit c7dff89

File tree

9 files changed

+384
-353
lines changed

9 files changed

+384
-353
lines changed

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

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

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

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

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

18-
import java.time.Duration;
19-
import java.util.ArrayList;
20-
import java.util.List;
18+
2119
import java.util.concurrent.ExecutorService;
2220
import java.util.concurrent.Executors;
2321
import java.util.concurrent.Future;
@@ -36,13 +34,18 @@
3634
import org.openjdk.jmh.annotations.TearDown;
3735
import org.openjdk.jmh.annotations.Warmup;
3836
import org.openjdk.jmh.infra.Blackhole;
37+
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
3938
import software.amazon.awssdk.benchmark.core.CoreBenchmark;
4039
import software.amazon.awssdk.benchmark.core.S3BenchmarkImpl;
4140
import software.amazon.awssdk.http.SdkHttpClient;
4241
import software.amazon.awssdk.http.apache.ApacheHttpClient;
4342
import software.amazon.awssdk.regions.Region;
4443
import software.amazon.awssdk.services.s3.S3Client;
45-
import software.amazon.awssdk.utils.Logger;
44+
45+
import java.time.Duration;
46+
import java.util.ArrayList;
47+
import java.util.List;
48+
import java.util.logging.Logger;
4649

4750
@BenchmarkMode(Mode.Throughput)
4851
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -51,7 +54,7 @@
5154
@Warmup(iterations = 3, time = 15, timeUnit = TimeUnit.SECONDS)
5255
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
5356
public class Apache4Benchmark implements CoreBenchmark {
54-
private static final Logger logger = Logger.loggerFor(Apache4Benchmark.class);
57+
private static final Logger logger = Logger.getLogger(Apache4Benchmark.class.getName());
5558

5659
@Param({"50"})
5760
private int maxConnections;
@@ -60,88 +63,114 @@ public class Apache4Benchmark implements CoreBenchmark {
6063
private int threadCount;
6164

6265
private S3Client s3Client;
63-
private S3BenchmarkImpl s3Benchmark;
64-
private ExecutorService executor;
66+
private S3BenchmarkImpl benchmark;
67+
private ExecutorService platformThreadPool;
6568

6669
@Setup(Level.Trial)
6770
public void setup() {
68-
logger.info(() -> "Setting up Apache4 benchmark with " + threadCount + " threads");
71+
logger.info("Setting up Apache4 benchmark with maxConnections=" + maxConnections);
6972

73+
// Apache 4 HTTP client
7074
SdkHttpClient httpClient = ApacheHttpClient.builder()
75+
.maxConnections(maxConnections)
7176
.connectionTimeout(Duration.ofSeconds(10))
7277
.socketTimeout(Duration.ofSeconds(30))
7378
.connectionAcquisitionTimeout(Duration.ofSeconds(10))
74-
.maxConnections(maxConnections)
79+
.connectionMaxIdleTime(Duration.ofSeconds(60))
80+
.connectionTimeToLive(Duration.ofMinutes(5))
81+
.useIdleConnectionReaper(true)
7582
.build();
7683

84+
// S3 client
7785
s3Client = S3Client.builder()
7886
.region(Region.US_WEST_2)
87+
.credentialsProvider(DefaultCredentialsProvider.create())
7988
.httpClient(httpClient)
8089
.build();
8190

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

85-
executor = Executors.newFixedThreadPool(threadCount);
86-
}
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+
});
87101

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-
}
102+
logger.info("Apache4 benchmark setup complete");
102103
}
103104

104105
@Benchmark
105106
@Override
106107
public void simpleGet(Blackhole blackhole) throws Exception {
107-
s3Benchmark.executeGet("5MB", blackhole);
108+
benchmark.executeGet("medium", blackhole);
108109
}
109110

110111
@Benchmark
111112
@Override
112-
public void simplePut(Blackhole blackhole) {
113-
s3Benchmark.executePut("5MB", blackhole);
113+
public void simplePut(Blackhole blackhole) throws Exception {
114+
benchmark.executePut("medium", blackhole);
114115
}
115116

116117
@Benchmark
117118
@Override
118119
public void multiThreadedGet(Blackhole blackhole) throws Exception {
119-
List<Future<?>> futures = new ArrayList<>();
120-
for (int i = 0; i < threadCount; i++) {
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++) {
121134
futures.add(executor.submit(() -> {
122135
try {
123-
s3Benchmark.executeGet("5MB", blackhole);
136+
if (isGet) {
137+
benchmark.executeGet("medium", blackhole);
138+
} else {
139+
benchmark.executePut("medium", blackhole);
140+
}
124141
} catch (Exception e) {
125-
throw new RuntimeException(e);
142+
throw new RuntimeException("Operation failed", e);
126143
}
127144
}));
128145
}
129146

147+
// Wait for all operations to complete
130148
for (Future<?> future : futures) {
131149
future.get();
132150
}
133151
}
134152

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)));
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+
}
141166
}
142167

143-
for (Future<?> future : futures) {
144-
future.get();
168+
if (benchmark != null) {
169+
benchmark.cleanup();
170+
}
171+
172+
if (s3Client != null) {
173+
s3Client.close();
145174
}
146175
}
147176
}

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

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

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

18-
import java.time.Duration;
19-
import java.util.ArrayList;
20-
import java.util.List;
18+
2119
import java.util.concurrent.ExecutorService;
2220
import java.util.concurrent.Executors;
2321
import java.util.concurrent.Future;
@@ -43,7 +41,25 @@
4341
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
4442
import software.amazon.awssdk.regions.Region;
4543
import software.amazon.awssdk.services.s3.S3Client;
46-
import software.amazon.awssdk.utils.Logger;
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+
*/
4763

4864
@BenchmarkMode(Mode.Throughput)
4965
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -52,83 +68,86 @@
5268
@Warmup(iterations = 3, time = 15, timeUnit = TimeUnit.SECONDS)
5369
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
5470
public class Apache5Benchmark implements CoreBenchmark {
55-
private static final Logger logger = Logger.loggerFor(Apache5Benchmark.class);
71+
private static final Logger logger = Logger.getLogger(Apache5Benchmark.class.getName());
5672

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

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

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

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

90+
// Apache 5 HTTP client
7191
SdkHttpClient httpClient = Apache5HttpClient.builder()
92+
.maxConnections(maxConnections)
7293
.connectionTimeout(Duration.ofSeconds(10))
7394
.socketTimeout(Duration.ofSeconds(30))
7495
.connectionAcquisitionTimeout(Duration.ofSeconds(10))
75-
.maxConnections(maxConnections)
96+
.connectionMaxIdleTime(Duration.ofSeconds(60))
97+
.connectionTimeToLive(Duration.ofMinutes(5))
98+
.useIdleConnectionReaper(true)
7699
.build();
77100

101+
// S3 client
78102
s3Client = S3Client.builder()
79103
.region(Region.US_WEST_2)
80104
.credentialsProvider(DefaultCredentialsProvider.create())
81105
.httpClient(httpClient)
82106
.build();
83107

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

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

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-
}
120+
logger.info("Apache5 benchmark setup complete");
104121
}
105122

106123
@Benchmark
107124
@Override
108125
public void simpleGet(Blackhole blackhole) throws Exception {
109-
s3Benchmark.executeGet("5MB", blackhole);
126+
benchmark.executeGet("medium", blackhole);
110127
}
111128

112129
@Benchmark
113130
@Override
114-
public void simplePut(Blackhole blackhole) {
115-
s3Benchmark.executePut("5MB", blackhole);
131+
public void simplePut(Blackhole blackhole) throws Exception {
132+
benchmark.executePut("medium", blackhole);
116133
}
117134

118135
@Benchmark
119136
@Override
120137
public void multiThreadedGet(Blackhole blackhole) throws Exception {
121-
List<Future<?>> futures = new ArrayList<>();
138+
List<Future<?>> futures = new ArrayList<>(threadCount);
139+
122140
for (int i = 0; i < threadCount; i++) {
123-
futures.add(executor.submit(() -> {
141+
futures.add(executorService.submit(() -> {
124142
try {
125-
s3Benchmark.executeGet("5MB", blackhole);
143+
benchmark.executeGet("medium", blackhole);
126144
} catch (Exception e) {
127-
throw new RuntimeException(e);
145+
throw new RuntimeException("GET operation failed", e);
128146
}
129147
}));
130148
}
131149

150+
// Wait for all operations to complete
132151
for (Future<?> future : futures) {
133152
future.get();
134153
}
@@ -137,13 +156,45 @@ public void multiThreadedGet(Blackhole blackhole) throws Exception {
137156
@Benchmark
138157
@Override
139158
public void multiThreadedPut(Blackhole blackhole) throws Exception {
140-
List<Future<?>> futures = new ArrayList<>();
159+
List<Future<?>> futures = new ArrayList<>(threadCount);
160+
141161
for (int i = 0; i < threadCount; i++) {
142-
futures.add(executor.submit(() -> s3Benchmark.executePut("5MB", blackhole)));
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+
}));
143169
}
144170

171+
// Wait for all operations to complete
145172
for (Future<?> future : futures) {
146173
future.get();
147174
}
148175
}
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+
}
149200
}

0 commit comments

Comments
 (0)