• 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.auth.credentials.AwsBasicCredentials;
41 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
42 import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
43 import software.amazon.awssdk.http.apache.ApacheHttpClient;
44 import software.amazon.awssdk.regions.Region;
45 import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
46 
47 /**
48  * Benchmark for creating the clients
49  */
50 @State(Scope.Benchmark)
51 @BenchmarkMode(Mode.SampleTime)
52 @OutputTimeUnit(TimeUnit.MILLISECONDS)
53 @Warmup(iterations = 3)
54 @Measurement(iterations = 5)
55 @Fork(3)
56 public class V2OptimizedClientCreationBenchmark implements SdkClientCreationBenchmark {
57 
58     private DynamoDbClient client;
59 
60     @Override
61     @Benchmark
createClient(Blackhole blackhole)62     public void createClient(Blackhole blackhole) throws Exception {
63         client = DynamoDbClient.builder()
64                                         .region(Region.US_WEST_2)
65                                         .credentialsProvider(StaticCredentialsProvider.create(
66                                             AwsBasicCredentials.create("test", "test")))
67                                         .httpClient(ApacheHttpClient.builder().build())
68                                         .overrideConfiguration(ClientOverrideConfiguration.builder().build())
69                                         .endpointDiscoveryEnabled(false)
70                                         .build();
71 
72         blackhole.consume(client);
73     }
74 
75     @TearDown(Level.Trial)
tearDown()76     public void tearDown() throws Exception {
77         if (client != null) {
78             client.close();
79         }
80     }
81 
main(String... args)82     public static void main(String... args) throws RunnerException, CommandLineOptionException {
83         Options opt = new OptionsBuilder()
84             .parent(new CommandLineOptions())
85             .include(V2OptimizedClientCreationBenchmark.class.getSimpleName())
86             .addProfiler(StackProfiler.class)
87             .build();
88         Collection<RunResult> run = new Runner(opt).run();
89     }
90 }
91