• 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.apicall.protocol;
17 
18 import static software.amazon.awssdk.benchmark.utils.BenchmarkConstant.ERROR_XML_BODY;
19 import static software.amazon.awssdk.benchmark.utils.BenchmarkConstant.XML_ALL_TYPES_REQUEST;
20 import static software.amazon.awssdk.benchmark.utils.BenchmarkConstant.XML_BODY;
21 
22 import java.util.concurrent.TimeUnit;
23 import org.openjdk.jmh.annotations.Benchmark;
24 import org.openjdk.jmh.annotations.BenchmarkMode;
25 import org.openjdk.jmh.annotations.Fork;
26 import org.openjdk.jmh.annotations.Level;
27 import org.openjdk.jmh.annotations.Measurement;
28 import org.openjdk.jmh.annotations.Mode;
29 import org.openjdk.jmh.annotations.Scope;
30 import org.openjdk.jmh.annotations.Setup;
31 import org.openjdk.jmh.annotations.State;
32 import org.openjdk.jmh.annotations.Warmup;
33 import org.openjdk.jmh.infra.Blackhole;
34 import org.openjdk.jmh.profile.StackProfiler;
35 import org.openjdk.jmh.runner.Runner;
36 import org.openjdk.jmh.runner.options.Options;
37 import org.openjdk.jmh.runner.options.OptionsBuilder;
38 import software.amazon.awssdk.benchmark.utils.MockHttpClient;
39 import software.amazon.awssdk.services.protocolrestxml.ProtocolRestXmlClient;
40 
41 /**
42  * Benchmarking for running with different protocols.
43  */
44 @State(Scope.Benchmark)
45 @Warmup(iterations = 3, time = 15, timeUnit = TimeUnit.SECONDS)
46 @Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
47 @Fork(2) // To reduce difference between each run
48 @BenchmarkMode(Mode.Throughput)
49 public class XmlProtocolBenchmark implements SdkProtocolBenchmark {
50 
51     private ProtocolRestXmlClient client;
52 
53     @Setup(Level.Trial)
setup()54     public void setup() {
55         client = ProtocolRestXmlClient.builder()
56                                       .httpClient(new MockHttpClient(XML_BODY, ERROR_XML_BODY))
57                                       .build();
58     }
59 
60     @Override
61     @Benchmark
successfulResponse(Blackhole blackhole)62     public void successfulResponse(Blackhole blackhole) {
63         blackhole.consume(client.allTypes(XML_ALL_TYPES_REQUEST));
64     }
65 
main(String... args)66     public static void main(String... args) throws Exception {
67         Options opt = new OptionsBuilder()
68             .include(XmlProtocolBenchmark.class.getSimpleName())
69             .addProfiler(StackProfiler.class)
70             .build();
71         new Runner(opt).run();
72     }
73 }
74