Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<!-- Allow non-java.base usage in tests -->
<suppress checks="software.amazon.awssdk.buildtools.checkstyle.NonJavaBaseModuleCheck" files=".*testutils.*"/>

<!-- Allow javax.xml.stream in benchmark protocol files (needed for V1 StAX unmarshalling) -->
<suppress checks="software.amazon.awssdk.buildtools.checkstyle.NonJavaBaseModuleCheck"
files=".*benchmark[\\/]protocol[\\/]V1.*\.java$"/>

<!-- Allow private field declaration before public, to have correct initialization order -->
<suppress checks="DeclarationOrder"
files=".*SdkAdvancedClientOption\.java$"/>
Expand Down
42 changes: 41 additions & 1 deletion test/sdk-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
-->
<uberjar.name>benchmarks</uberjar.name>

<sdk-v1.version>1.11.404</sdk-v1.version>
<sdk-v1.version>1.12.797</sdk-v1.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
</properties>

Expand Down Expand Up @@ -87,18 +87,58 @@
<artifactId>aws-java-sdk-ec2</artifactId>
<version>${sdk-v1.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudfront</artifactId>
<version>${sdk-v1.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>${sdk-v1.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-lambda</artifactId>
<version>${sdk-v1.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudwatch</artifactId>
<version>${sdk-v1.version}</version>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ec2</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>cloudfront</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sts</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>lambda</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>smithy-rpcv2-protocol</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.benchmark.protocol;

import com.amazonaws.protocol.rpcv2cbor.RpcV2CborClientMetadata;
import com.amazonaws.protocol.rpcv2cbor.SdkRpcV2CborProtocolFactory;
import com.amazonaws.protocol.rpcv2cbor.SdkStructuredCborFactory;
import com.amazonaws.protocol.rpcv2cbor.StructuredRpcV2CborGenerator;
import com.amazonaws.services.cloudwatch.model.GetMetricDataRequest;
import com.amazonaws.services.cloudwatch.model.Metric;
import com.amazonaws.services.cloudwatch.model.MetricDataQuery;
import com.amazonaws.services.cloudwatch.model.MetricStat;
import com.amazonaws.services.cloudwatch.model.transform.GetMetricDataRequestProtocolMarshaller;
import com.amazonaws.services.cloudwatch.model.transform.GetMetricDataResultRpcV2CborUnmarshaller;
import com.amazonaws.transform.rpcv2cbor.RpcV2CborUnmarshallerContextImpl;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.dataformat.cbor.CBORParser;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
@Fork(2)
public class V1CborProtocolBenchmark {

private static final CBORFactory CBOR_FACTORY = new CBORFactory();

private SdkRpcV2CborProtocolFactory protocolFactory;
private byte[] responseBytes;
private GetMetricDataRequest request;

@Setup
public void setup() throws Exception {

Check warning on line 60 in test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/protocol/V1CborProtocolBenchmark.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZzbtRsdUoaLmg3Mkihb&open=AZzbtRsdUoaLmg3Mkihb&pullRequest=6776

Check warning on line 60 in test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/protocol/V1CborProtocolBenchmark.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZzbtRsdUoaLmg3Mkihc&open=AZzbtRsdUoaLmg3Mkihc&pullRequest=6776
protocolFactory = new SdkRpcV2CborProtocolFactory(new RpcV2CborClientMetadata());
responseBytes = createCborResponseFixture();
request = createRequest();
}

@Benchmark
public void getMetricDataDeser(Blackhole bh) throws Exception {
CBORParser parser = CBOR_FACTORY.createParser(responseBytes);
RpcV2CborUnmarshallerContextImpl ctx = new RpcV2CborUnmarshallerContextImpl(
parser, SdkStructuredCborFactory.CBOR_SCALAR_UNMARSHALLERS, null);
ctx.nextToken();
bh.consume(GetMetricDataResultRpcV2CborUnmarshaller.getInstance().unmarshall(ctx));
}

@Benchmark
public void getMetricDataSer(Blackhole bh) {
bh.consume(new GetMetricDataRequestProtocolMarshaller(protocolFactory).marshall(request));
}

private static GetMetricDataRequest createRequest() {
Date end = Date.from(java.time.Instant.parse("2026-03-09T00:00:00Z"));
Date start = Date.from(java.time.Instant.parse("2026-03-09T00:00:00Z").minusSeconds(3600));
return new GetMetricDataRequest()
.withStartTime(start)
.withEndTime(end)
.withMaxDatapoints(1000)
.withMetricDataQueries(
new MetricDataQuery()
.withId("cpu")
.withMetricStat(new MetricStat()
.withMetric(new Metric()
.withNamespace("AWS/EC2")
.withMetricName("CPUUtilization"))
.withPeriod(300)
.withStat("Average"))
.withReturnData(true));
}

private static byte[] createCborResponseFixture() {
StructuredRpcV2CborGenerator gen =
SdkStructuredCborFactory.SDK_CBOR_FACTORY.createWriter("application/cbor");
gen.writeStartObject();
gen.writeFieldName("MetricDataResults");
gen.writeStartArray();
gen.writeStartObject();
gen.writeFieldName("Id");
gen.writeValue("cpu");
gen.writeFieldName("Label");
gen.writeValue("CPUUtilization");
gen.writeFieldName("StatusCode");
gen.writeValue("Complete");
gen.writeFieldName("Timestamps");
gen.writeStartArray();
long base = 1772611200L;
for (int i = 0; i < 12; i++) {
gen.writeValue((double) ((base + i * 300) * 1000));
}
gen.writeEndArray();
gen.writeFieldName("Values");
gen.writeStartArray();
for (int i = 0; i < 12; i++) {
gen.writeValue(45.2 + i * 1.1);
}
gen.writeEndArray();
gen.writeFieldName("Messages");
gen.writeStartArray();
gen.writeEndArray();
gen.writeEndObject();
gen.writeEndArray();
gen.writeFieldName("Messages");
gen.writeStartArray();
gen.writeEndArray();
gen.writeEndObject();
return gen.getBytes();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.benchmark.protocol;

import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
import com.amazonaws.services.ec2.model.Filter;
import com.amazonaws.services.ec2.model.transform.DescribeInstancesRequestMarshaller;
import com.amazonaws.services.ec2.model.transform.DescribeInstancesResultStaxUnmarshaller;
import com.amazonaws.transform.StaxUnmarshallerContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
@Fork(2)
public class V1Ec2ProtocolBenchmark {

private static final XMLInputFactory XML_INPUT_FACTORY =
XMLInputFactory.newInstance();

private byte[] responseBytes;
private Map<String, String> responseHeaders;
private DescribeInstancesRequestMarshaller marshaller;
private DescribeInstancesRequest request;

@Setup
public void setup() throws Exception {

Check warning on line 59 in test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/protocol/V1Ec2ProtocolBenchmark.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZzbtRsuUoaLmg3Mkihi&open=AZzbtRsuUoaLmg3Mkihi&pullRequest=6776
responseBytes = loadFixture("fixtures/ec2-protocol/describe-instances-response.xml");
responseHeaders = new HashMap<>();
marshaller = new DescribeInstancesRequestMarshaller();
request = createRequest();
}

@Benchmark
public void describeInstancesDeser(Blackhole bh) throws Exception {
XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(new ByteArrayInputStream(responseBytes));
StaxUnmarshallerContext ctx = new StaxUnmarshallerContext(reader, responseHeaders);
ctx.registerMetadataExpression("ResponseMetadata/RequestId", 2, "AWS_REQUEST_ID");

bh.consume(DescribeInstancesResultStaxUnmarshaller.getInstance().unmarshall(ctx));
}

@Benchmark
public void describeInstancesSer(Blackhole bh) {
bh.consume(marshaller.marshall(request));
}

private static DescribeInstancesRequest createRequest() {
return new DescribeInstancesRequest()
.withInstanceIds("i-0abcdef1234567890")
.withFilters(
new Filter("instance-state-name").withValues("running"),
new Filter("instance-type").withValues("m5.xlarge"))
.withMaxResults(100);
}

private static byte[] loadFixture(String path) throws IOException {
return com.amazonaws.util.IOUtils.toByteArray(
V1Ec2ProtocolBenchmark.class.getClassLoader()
.getResourceAsStream(path));
}
}
Loading
Loading