• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.benchmark.coldstart;
17 
18 import java.util.Collection;
19 import java.util.concurrent.TimeUnit;
20 import org.openjdk.jmh.annotations.Benchmark;
21 import org.openjdk.jmh.annotations.BenchmarkMode;
22 import org.openjdk.jmh.annotations.Fork;
23 import org.openjdk.jmh.annotations.Level;
24 import org.openjdk.jmh.annotations.Measurement;
25 import org.openjdk.jmh.annotations.Mode;
26 import org.openjdk.jmh.annotations.OutputTimeUnit;
27 import org.openjdk.jmh.annotations.Scope;
28 import org.openjdk.jmh.annotations.State;
29 import org.openjdk.jmh.annotations.TearDown;
30 import org.openjdk.jmh.annotations.Warmup;
31 import org.openjdk.jmh.infra.Blackhole;
32 import org.openjdk.jmh.profile.StackProfiler;
33 import org.openjdk.jmh.results.RunResult;
34 import org.openjdk.jmh.runner.Runner;
35 import org.openjdk.jmh.runner.RunnerException;
36 import org.openjdk.jmh.runner.options.CommandLineOptionException;
37 import org.openjdk.jmh.runner.options.CommandLineOptions;
38 import org.openjdk.jmh.runner.options.Options;
39 import org.openjdk.jmh.runner.options.OptionsBuilder;
40 import software.amazon.awssdk.http.apache.ApacheHttpClient;
41 import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
42 
43 /**
44  * Benchmark for creating the clients
45  */
46 @State(Scope.Benchmark)
47 @BenchmarkMode(Mode.SampleTime)
48 @OutputTimeUnit(TimeUnit.MILLISECONDS)
49 @Warmup(iterations = 3)
50 @Measurement(iterations = 5)
51 @Fork(3)
52 public class V2DefaultClientCreationBenchmark implements SdkClientCreationBenchmark {
53 
54     private DynamoDbClient client;
55 
56     @Override
57     @Benchmark
createClient(Blackhole blackhole)58     public void createClient(Blackhole blackhole) throws Exception {
59         client = DynamoDbClient.builder()
60                                .endpointDiscoveryEnabled(false)
61                                .httpClient(ApacheHttpClient.builder().build()).build();
62         blackhole.consume(client);
63     }
64 
65     @TearDown(Level.Trial)
tearDown()66     public void tearDown() throws Exception {
67         if (client != null) {
68             client.close();
69         }
70     }
71 
main(String... args)72     public static void main(String... args) throws RunnerException, CommandLineOptionException {
73         Options opt = new OptionsBuilder()
74             .parent(new CommandLineOptions())
75             .include(V2DefaultClientCreationBenchmark.class.getSimpleName())
76             .addProfiler(StackProfiler.class)
77             .build();
78         Collection<RunResult> run = new Runner(opt).run();
79     }
80 }
81