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