Skip to content

Commit 0497541

Browse files
committed
Move request creation into the benchmark runner
1 parent fa0445c commit 0497541

13 files changed

+203
-194
lines changed

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/ProtocolRoundtripServlet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222

2323
class ProtocolRoundtripServlet extends HttpServlet {
2424
private final byte[] body;
25+
private final String contentType;
2526

26-
ProtocolRoundtripServlet(byte[] body) {
27+
ProtocolRoundtripServlet(byte[] body, String contentType) {
2728
this.body = body;
29+
this.contentType = contentType;
2830
}
2931

3032
@Override
3133
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
3234
resp.setStatus(200);
3335
resp.setContentLength(body.length);
36+
resp.setContentType(contentType);
3437
resp.getOutputStream().write(body);
3538
}
3639
}

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1CborRoundtripBenchmark.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ public class V1CborRoundtripBenchmark {
5555

5656
private ProtocolRoundtripServer server;
5757
private AmazonCloudWatch client;
58-
private GetMetricDataRequest request;
5958

6059
@Setup(Level.Trial)
6160
public void setup() throws Exception {
6261
byte[] response = createCborResponseFixture();
6362

64-
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response);
63+
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "application/cbor");
6564

6665
server = new ProtocolRoundtripServer(servlet);
6766
server.start();
@@ -71,33 +70,33 @@ public void setup() throws Exception {
7170
server.getHttpUri().toString(), "us-east-1"))
7271
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test")))
7372
.build();
73+
}
7474

75+
@TearDown(Level.Trial)
76+
public void tearDown() throws Exception {
77+
client.shutdown();
78+
server.stop();
79+
}
80+
81+
@Benchmark
82+
public void getMetricData(Blackhole bh) {
7583
Date end = Date.from(java.time.Instant.parse("2026-03-09T00:00:00Z"));
7684
Date start = Date.from(java.time.Instant.parse("2026-03-09T00:00:00Z").minusSeconds(3600));
77-
request = new GetMetricDataRequest()
85+
GetMetricDataRequest request = new GetMetricDataRequest()
7886
.withStartTime(start)
7987
.withEndTime(end)
8088
.withMaxDatapoints(1000)
8189
.withMetricDataQueries(
8290
new MetricDataQuery()
8391
.withId("cpu")
8492
.withMetricStat(new MetricStat()
85-
.withMetric(new Metric()
86-
.withNamespace("AWS/EC2")
87-
.withMetricName("CPUUtilization"))
88-
.withPeriod(300)
89-
.withStat("Average"))
93+
.withMetric(new Metric()
94+
.withNamespace("AWS/EC2")
95+
.withMetricName("CPUUtilization"))
96+
.withPeriod(300)
97+
.withStat("Average"))
9098
.withReturnData(true));
91-
}
9299

93-
@TearDown(Level.Trial)
94-
public void tearDown() throws Exception {
95-
client.shutdown();
96-
server.stop();
97-
}
98-
99-
@Benchmark
100-
public void getMetricData(Blackhole bh) {
101100
bh.consume(client.getMetricData(request));
102101
}
103102

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1Ec2RoundtripBenchmark.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ public class V1Ec2RoundtripBenchmark {
5050

5151
private ProtocolRoundtripServer server;
5252
private AmazonEC2 client;
53-
private DescribeInstancesRequest request;
5453

5554
@Setup(Level.Trial)
5655
public void setup() throws Exception {
5756
byte[] response = ProtocolRoundtripServer.loadFixture("ec2-protocol/describe-instances-response.xml");
5857

59-
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response);
58+
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "text/xml");
6059

6160
server = new ProtocolRoundtripServer(servlet);
6261
server.start();
@@ -66,13 +65,6 @@ public void setup() throws Exception {
6665
server.getHttpUri().toString(), "us-east-1"))
6766
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test")))
6867
.build();
69-
70-
request = new DescribeInstancesRequest()
71-
.withInstanceIds("i-0abcdef1234567890")
72-
.withFilters(
73-
new Filter("instance-state-name").withValues("running"),
74-
new Filter("instance-type").withValues("m5.xlarge"))
75-
.withMaxResults(100);
7668
}
7769

7870
@TearDown(Level.Trial)
@@ -83,6 +75,13 @@ public void tearDown() throws Exception {
8375

8476
@Benchmark
8577
public void describeInstances(Blackhole bh) {
78+
DescribeInstancesRequest request = new DescribeInstancesRequest()
79+
.withInstanceIds("i-0abcdef1234567890")
80+
.withFilters(
81+
new Filter("instance-state-name").withValues("running"),
82+
new Filter("instance-type").withValues("m5.xlarge"))
83+
.withMaxResults(100);
84+
8685
bh.consume(client.describeInstances(request));
8786
}
8887
}

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1JsonRoundtripBenchmark.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ public class V1JsonRoundtripBenchmark {
5353

5454
private ProtocolRoundtripServer server;
5555
private AmazonDynamoDB client;
56-
private PutItemRequest putItemRequest;
5756

5857
@Setup(Level.Trial)
5958
public void setup() throws Exception {
6059
byte[] response = ProtocolRoundtripServer.loadFixture("json-protocol/putitem-response.json");
6160

62-
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response);
61+
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "application/x-amz-json-1.0");
6362

6463
server = new ProtocolRoundtripServer(servlet);
6564
server.start();
@@ -69,10 +68,6 @@ public void setup() throws Exception {
6968
server.getHttpUri().toString(), "us-east-1"))
7069
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test")))
7170
.build();
72-
73-
putItemRequest = new PutItemRequest()
74-
.withTableName("benchmark-table")
75-
.withItem(itemMap());
7671
}
7772

7873
@TearDown(Level.Trial)
@@ -83,6 +78,10 @@ public void tearDown() throws Exception {
8378

8479
@Benchmark
8580
public void putItem(Blackhole bh) {
81+
PutItemRequest putItemRequest = new PutItemRequest()
82+
.withTableName("benchmark-table")
83+
.withItem(itemMap());
84+
8685
bh.consume(client.putItem(putItemRequest));
8786
}
8887

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1QueryRoundtripBenchmark.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ public class V1QueryRoundtripBenchmark {
4949

5050
private ProtocolRoundtripServer server;
5151
private AWSSecurityTokenService client;
52-
private AssumeRoleRequest request;
5352

5453
@Setup(Level.Trial)
5554
public void setup() throws Exception {
5655
byte[] response = ProtocolRoundtripServer.loadFixture("query-protocol/assumerole-response.xml");
5756

58-
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response);
57+
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "text/xml");
5958

6059
server = new ProtocolRoundtripServer(servlet);
6160
server.start();
@@ -65,13 +64,6 @@ public void setup() throws Exception {
6564
server.getHttpUri().toString(), "us-east-1"))
6665
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test")))
6766
.build();
68-
69-
request = new AssumeRoleRequest()
70-
.withRoleArn("arn:aws:iam::123456789012:role/benchmark-role")
71-
.withRoleSessionName("benchmark-session")
72-
.withDurationSeconds(3600)
73-
.withExternalId("benchmark-external-id")
74-
.withPolicy("{\"Version\":\"2012-10-17\"}");
7567
}
7668

7769
@TearDown(Level.Trial)
@@ -82,6 +74,13 @@ public void tearDown() throws Exception {
8274

8375
@Benchmark
8476
public void assumeRole(Blackhole bh) {
77+
AssumeRoleRequest request = new AssumeRoleRequest()
78+
.withRoleArn("arn:aws:iam::123456789012:role/benchmark-role")
79+
.withRoleSessionName("benchmark-session")
80+
.withDurationSeconds(3600)
81+
.withExternalId("benchmark-external-id")
82+
.withPolicy("{\"Version\":\"2012-10-17\"}");
83+
8584
bh.consume(client.assumeRole(request));
8685
}
8786
}

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1RestJsonRoundtripBenchmark.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ public class V1RestJsonRoundtripBenchmark {
5656

5757
private ProtocolRoundtripServer server;
5858
private AWSLambda client;
59-
private CreateFunctionRequest request;
6059

6160
@Setup(Level.Trial)
6261
public void setup() throws Exception {
6362
byte[] response = ProtocolRoundtripServer.loadFixture("rest-json-protocol/createfunction-response.json");
6463

65-
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response);
64+
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "application/json");
6665

6766
server = new ProtocolRoundtripServer(servlet);
6867
server.start();
@@ -72,34 +71,34 @@ public void setup() throws Exception {
7271
server.getHttpUri().toString(), "us-east-1"))
7372
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test")))
7473
.build();
74+
}
7575

76+
@TearDown(Level.Trial)
77+
public void tearDown() throws Exception {
78+
client.shutdown();
79+
server.stop();
80+
}
81+
82+
@Benchmark
83+
public void createFunction(Blackhole bh) {
7684
Map<String, String> envVars = new HashMap<>();
7785
envVars.put("ENV_VAR_1", "value1");
7886

79-
request = new CreateFunctionRequest()
87+
CreateFunctionRequest request = new CreateFunctionRequest()
8088
.withFunctionName("benchmark-function")
8189
.withRuntime(Runtime.Java8)
8290
.withRole("arn:aws:iam::123456789012:role/lambda-role")
8391
.withHandler("com.example.Handler::handleRequest")
8492
.withCode(new FunctionCode()
85-
.withS3Bucket("my-deploy-bucket")
86-
.withS3Key("code/function.zip"))
93+
.withS3Bucket("my-deploy-bucket")
94+
.withS3Key("code/function.zip"))
8795
.withDescription("Benchmark test function")
8896
.withTimeout(30)
8997
.withMemorySize(512)
9098
.withPublish(false)
9199
.withEnvironment(new Environment().withVariables(envVars))
92100
.withTracingConfig(new TracingConfig().withMode(TracingMode.Active));
93-
}
94101

95-
@TearDown(Level.Trial)
96-
public void tearDown() throws Exception {
97-
client.shutdown();
98-
server.stop();
99-
}
100-
101-
@Benchmark
102-
public void createFunction(Blackhole bh) {
103102
bh.consume(client.createFunction(request));
104103
}
105104
}

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/protocol/V1RestXmlRoundtripBenchmark.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ public class V1RestXmlRoundtripBenchmark {
5959

6060
private ProtocolRoundtripServer server;
6161
private AmazonCloudFront client;
62-
private CreateDistributionRequest request;
6362

6463
@Setup(Level.Trial)
6564
public void setup() throws Exception {
6665
byte[] response = ProtocolRoundtripServer.loadFixture("rest-xml-protocol/create-distribution-response.xml");
6766

68-
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response);
67+
ProtocolRoundtripServlet servlet = new ProtocolRoundtripServlet(response, "text/xml");
6968

7069
server = new ProtocolRoundtripServer(servlet);
7170
server.start();
@@ -75,32 +74,6 @@ public void setup() throws Exception {
7574
server.getHttpUri().toString(), "us-east-1"))
7675
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("test", "test")))
7776
.build();
78-
79-
request = new CreateDistributionRequest()
80-
.withDistributionConfig(new DistributionConfig()
81-
.withCallerReference("benchmark-ref-2024")
82-
.withAliases(new Aliases()
83-
.withQuantity(2)
84-
.withItems("www.example.com", "cdn.example.com"))
85-
.withDefaultRootObject("index.html")
86-
.withOrigins(new Origins()
87-
.withQuantity(1)
88-
.withItems(new Origin()
89-
.withId("myS3Origin")
90-
.withDomainName("mybucket.s3.amazonaws.com")
91-
.withOriginPath("/production")
92-
.withS3OriginConfig(new S3OriginConfig()
93-
.withOriginAccessIdentity("origin-access-identity/cloudfront/E127EXAMPLE51Z"))))
94-
.withDefaultCacheBehavior(new DefaultCacheBehavior()
95-
.withTargetOriginId("myS3Origin")
96-
.withViewerProtocolPolicy(ViewerProtocolPolicy.RedirectToHttps)
97-
.withAllowedMethods(new AllowedMethods()
98-
.withQuantity(3)
99-
.withItems(Method.GET, Method.HEAD, Method.OPTIONS)
100-
.withCachedMethods(new CachedMethods()
101-
.withQuantity(2)
102-
.withItems(Method.GET, Method.HEAD)))
103-
.withCompress(true)));
10477
}
10578

10679
@TearDown(Level.Trial)
@@ -111,6 +84,32 @@ public void tearDown() throws Exception {
11184

11285
@Benchmark
11386
public void createDistribution(Blackhole bh) {
87+
CreateDistributionRequest request = new CreateDistributionRequest()
88+
.withDistributionConfig(new DistributionConfig()
89+
.withCallerReference("benchmark-ref-2024")
90+
.withAliases(new Aliases()
91+
.withQuantity(2)
92+
.withItems("www.example.com", "cdn.example.com"))
93+
.withDefaultRootObject("index.html")
94+
.withOrigins(new Origins()
95+
.withQuantity(1)
96+
.withItems(new Origin()
97+
.withId("myS3Origin")
98+
.withDomainName("mybucket.s3.amazonaws.com")
99+
.withOriginPath("/production")
100+
.withS3OriginConfig(new S3OriginConfig()
101+
.withOriginAccessIdentity("origin-access-identity/cloudfront/E127EXAMPLE51Z"))))
102+
.withDefaultCacheBehavior(new DefaultCacheBehavior()
103+
.withTargetOriginId("myS3Origin")
104+
.withViewerProtocolPolicy(ViewerProtocolPolicy.RedirectToHttps)
105+
.withAllowedMethods(new AllowedMethods()
106+
.withQuantity(3)
107+
.withItems(Method.GET, Method.HEAD, Method.OPTIONS)
108+
.withCachedMethods(new CachedMethods()
109+
.withQuantity(2)
110+
.withItems(Method.GET, Method.HEAD)))
111+
.withCompress(true)));
112+
114113
bh.consume(client.createDistribution(request));
115114
}
116115
}

0 commit comments

Comments
 (0)