1515
1616package software .amazon .awssdk .benchmark .apache5 ;
1717
18-
18+ import java .time .Duration ;
19+ import java .util .ArrayList ;
20+ import java .util .List ;
1921import java .util .concurrent .ExecutorService ;
2022import java .util .concurrent .Executors ;
2123import java .util .concurrent .Future ;
4143import software .amazon .awssdk .http .apache5 .Apache5HttpClient ;
4244import software .amazon .awssdk .regions .Region ;
4345import 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 )
6852@ Warmup (iterations = 3 , time = 15 , timeUnit = TimeUnit .SECONDS )
6953@ Measurement (iterations = 5 , time = 10 , timeUnit = TimeUnit .SECONDS )
7054public 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