15
15
16
16
package software .amazon .awssdk .benchmark .apache5 ;
17
17
18
- import java .time .Duration ;
19
- import java .util .ArrayList ;
20
- import java .util .List ;
18
+
21
19
import java .util .concurrent .ExecutorService ;
22
20
import java .util .concurrent .Executors ;
23
21
import java .util .concurrent .Future ;
43
41
import software .amazon .awssdk .http .apache5 .Apache5HttpClient ;
44
42
import software .amazon .awssdk .regions .Region ;
45
43
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
+ */
47
63
48
64
@ BenchmarkMode (Mode .Throughput )
49
65
@ OutputTimeUnit (TimeUnit .SECONDS )
52
68
@ Warmup (iterations = 3 , time = 15 , timeUnit = TimeUnit .SECONDS )
53
69
@ Measurement (iterations = 5 , time = 10 , timeUnit = TimeUnit .SECONDS )
54
70
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 () );
56
72
57
- @ Param ("50" )
73
+ @ Param ({ "50" } )
58
74
private int maxConnections ;
59
75
60
- @ Param ("20" )
76
+ @ Param ({ "10" } )
61
77
private int threadCount ;
62
78
79
+ @ Param ({"platform" })
80
+ private String executorType ;
81
+
63
82
private S3Client s3Client ;
64
- private S3BenchmarkImpl s3Benchmark ;
65
- private ExecutorService executor ;
83
+ private S3BenchmarkImpl benchmark ;
84
+ private ExecutorService executorService ;
66
85
67
86
@ Setup (Level .Trial )
68
87
public void setup () {
69
- logger .info (() -> "Setting up Apache5 benchmark with " + threadCount + " threads" );
88
+ logger .info ("Setting up Apache5 benchmark with maxConnections= " + maxConnections );
70
89
90
+ // Apache 5 HTTP client
71
91
SdkHttpClient httpClient = Apache5HttpClient .builder ()
92
+ .maxConnections (maxConnections )
72
93
.connectionTimeout (Duration .ofSeconds (10 ))
73
94
.socketTimeout (Duration .ofSeconds (30 ))
74
95
.connectionAcquisitionTimeout (Duration .ofSeconds (10 ))
75
- .maxConnections (maxConnections )
96
+ .connectionMaxIdleTime (Duration .ofSeconds (60 ))
97
+ .connectionTimeToLive (Duration .ofMinutes (5 ))
98
+ .useIdleConnectionReaper (true )
76
99
.build ();
77
100
101
+ // S3 client
78
102
s3Client = S3Client .builder ()
79
103
.region (Region .US_WEST_2 )
80
104
.credentialsProvider (DefaultCredentialsProvider .create ())
81
105
.httpClient (httpClient )
82
106
.build ();
83
107
84
- s3Benchmark = new S3BenchmarkImpl (s3Client );
85
- s3Benchmark .setup ();
108
+ // Initialize benchmark implementation
109
+ benchmark = new S3BenchmarkImpl (s3Client );
110
+ benchmark .setup ();
86
111
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" );
89
119
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" );
104
121
}
105
122
106
123
@ Benchmark
107
124
@ Override
108
125
public void simpleGet (Blackhole blackhole ) throws Exception {
109
- s3Benchmark .executeGet ("5MB " , blackhole );
126
+ benchmark .executeGet ("medium " , blackhole );
110
127
}
111
128
112
129
@ Benchmark
113
130
@ 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 );
116
133
}
117
134
118
135
@ Benchmark
119
136
@ Override
120
137
public void multiThreadedGet (Blackhole blackhole ) throws Exception {
121
- List <Future <?>> futures = new ArrayList <>();
138
+ List <Future <?>> futures = new ArrayList <>(threadCount );
139
+
122
140
for (int i = 0 ; i < threadCount ; i ++) {
123
- futures .add (executor .submit (() -> {
141
+ futures .add (executorService .submit (() -> {
124
142
try {
125
- s3Benchmark .executeGet ("5MB " , blackhole );
143
+ benchmark .executeGet ("medium " , blackhole );
126
144
} catch (Exception e ) {
127
- throw new RuntimeException (e );
145
+ throw new RuntimeException ("GET operation failed" , e );
128
146
}
129
147
}));
130
148
}
131
149
150
+ // Wait for all operations to complete
132
151
for (Future <?> future : futures ) {
133
152
future .get ();
134
153
}
@@ -137,13 +156,45 @@ public void multiThreadedGet(Blackhole blackhole) throws Exception {
137
156
@ Benchmark
138
157
@ Override
139
158
public void multiThreadedPut (Blackhole blackhole ) throws Exception {
140
- List <Future <?>> futures = new ArrayList <>();
159
+ List <Future <?>> futures = new ArrayList <>(threadCount );
160
+
141
161
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
+ }));
143
169
}
144
170
171
+ // Wait for all operations to complete
145
172
for (Future <?> future : futures ) {
146
173
future .get ();
147
174
}
148
175
}
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
+ }
149
200
}
0 commit comments