-
Notifications
You must be signed in to change notification settings - Fork 992
Add Ser/De + roundtrip protocol benchmarks #6776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RanVaknin
wants to merge
7
commits into
master
Choose a base branch
from
rvaknin/isolated-protocol-benchmarks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
36ca8df
Add isolated protocol ser/de benchmarks for V1 vs V2
RanVaknin 5c6e794
Change benchmark mode to throughput
RanVaknin 0537ec7
Fix inconsistencies, checkstyle suppressions
RanVaknin 6d4ba3b
Add http servlet roundtrip benchmarks
RanVaknin 29cdadb
Change timeunit to seconds
RanVaknin fa0445c
Simplify servlet
RanVaknin 0497541
Move request creation into the benchmark runner
RanVaknin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
.../main/java/software/amazon/awssdk/benchmark/apicall/protocol/ProtocolRoundtripServer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * 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.apicall.protocol; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.net.URI; | ||
| import org.eclipse.jetty.server.Connector; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.ServerConnector; | ||
| import org.eclipse.jetty.servlet.ServletContextHandler; | ||
| import org.eclipse.jetty.servlet.ServletHolder; | ||
| import software.amazon.awssdk.benchmark.utils.BenchmarkUtils; | ||
| import software.amazon.awssdk.utils.IoUtils; | ||
|
|
||
| /** | ||
| * Lightweight Jetty server for protocol roundtrip benchmarks. | ||
| */ | ||
| class ProtocolRoundtripServer { | ||
|
|
||
| private final Server server; | ||
| private final int port; | ||
|
|
||
| ProtocolRoundtripServer(ProtocolRoundtripServlet servlet) throws IOException { | ||
| port = BenchmarkUtils.getUnusedPort(); | ||
| server = new Server(); | ||
| ServerConnector connector = new ServerConnector(server); | ||
|
Check failure on line 40 in test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/ProtocolRoundtripServer.java
|
||
| connector.setPort(port); | ||
| server.setConnectors(new Connector[] {connector}); | ||
|
|
||
| ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); | ||
| context.addServlet(new ServletHolder(servlet), "/*"); | ||
| server.setHandler(context); | ||
| } | ||
|
|
||
| void start() throws Exception { | ||
| server.start(); | ||
| } | ||
|
|
||
| void stop() throws Exception { | ||
| server.stop(); | ||
| } | ||
|
|
||
| URI getHttpUri() { | ||
| return URI.create("http://localhost:" + port); | ||
| } | ||
|
|
||
| static byte[] loadFixture(String path) throws IOException { | ||
| try (InputStream is = ProtocolRoundtripServer.class.getClassLoader() | ||
| .getResourceAsStream("fixtures/" + path)) { | ||
| if (is == null) { | ||
| throw new IOException("Fixture not found: fixtures/" + path); | ||
| } | ||
| return IoUtils.toByteArray(is); | ||
| } | ||
| } | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
...main/java/software/amazon/awssdk/benchmark/apicall/protocol/ProtocolRoundtripServlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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.apicall.protocol; | ||
|
|
||
| import java.io.IOException; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| class ProtocolRoundtripServlet extends HttpServlet { | ||
| private final byte[] body; | ||
| private final String contentType; | ||
|
|
||
| ProtocolRoundtripServlet(byte[] body, String contentType) { | ||
| this.body = body; | ||
| this.contentType = contentType; | ||
| } | ||
|
|
||
| @Override | ||
| protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
| resp.setStatus(200); | ||
| resp.setContentLength(body.length); | ||
| resp.setContentType(contentType); | ||
| resp.getOutputStream().write(body); | ||
| } | ||
| } | ||
140 changes: 140 additions & 0 deletions
140
...main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1CborRoundtripBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * 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.apicall.protocol; | ||
|
|
||
| import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
| import com.amazonaws.auth.BasicAWSCredentials; | ||
| import com.amazonaws.client.builder.AwsClientBuilder; | ||
| import com.amazonaws.protocol.rpcv2cbor.SdkStructuredCborFactory; | ||
| import com.amazonaws.protocol.rpcv2cbor.StructuredRpcV2CborGenerator; | ||
| import com.amazonaws.services.cloudwatch.AmazonCloudWatch; | ||
| import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder; | ||
| 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 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.Level; | ||
| 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.TearDown; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
|
|
||
| /** | ||
| * V1 roundtrip benchmark for SmithyRpcV2 CBOR protocol using CloudWatch GetMetricData via HTTP servlet. | ||
| */ | ||
| @State(Scope.Benchmark) | ||
| @Warmup(iterations = 5) | ||
| @Measurement(iterations = 5) | ||
| @Fork(2) | ||
| @BenchmarkMode(Mode.Throughput) | ||
| @OutputTimeUnit(TimeUnit.SECONDS) | ||
| public class V1CborRoundtripBenchmark { | ||
|
|
||
| private ProtocolRoundtripServer server; | ||
| private AmazonCloudWatch client; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setup() throws Exception { | ||
| byte[] response = createCborResponseFixture(); | ||
|
|
||
| ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "application/cbor"); | ||
|
|
||
| server = new ProtocolRoundtripServer(servlet); | ||
| server.start(); | ||
|
|
||
| client = AmazonCloudWatchClientBuilder.standard() | ||
| .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration( | ||
| server.getHttpUri().toString(), "us-east-1")) | ||
| .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test"))) | ||
| .build(); | ||
| } | ||
|
|
||
| @TearDown(Level.Trial) | ||
| public void tearDown() throws Exception { | ||
| client.shutdown(); | ||
| server.stop(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void getMetricData(Blackhole bh) { | ||
| 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)); | ||
| GetMetricDataRequest request = 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)); | ||
|
|
||
| bh.consume(client.getMetricData(request)); | ||
| } | ||
|
|
||
| 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(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also probably be setting content-type? I'm not quite sure if it matters or not