-
Notifications
You must be signed in to change notification settings - Fork 199
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
Add benchmark for DynamoDB serialization/deserialization #507
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9cd8d3e
Add benchmark for DynamoDB serialization/deserialization
jdisanti 82f332e
CR feedback
jdisanti e0b4711
Merge remote-tracking branch 'upstream/main' into dynamo-bench
jdisanti 1438edb
Remove async from benches and add benches to CI
jdisanti 8755f6c
Update cargo check command in CI
jdisanti cc89989
Merge branch 'main' into dynamo-bench
jdisanti 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 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
42 changes: 42 additions & 0 deletions
42
aws/sdk/integration-tests/dynamodb/benches/deserialization_bench.rs
This file contains 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,42 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_sdk_dynamodb::operation::Query; | ||
use bytes::Bytes; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use smithy_http::body::SdkBody; | ||
use smithy_http::response::ParseHttpResponse; | ||
use tokio::runtime::Builder as RuntimeBuilder; | ||
|
||
async fn do_bench() { | ||
let response = http::Response::builder() | ||
.header("server", "Server") | ||
.header("date", "Mon, 08 Mar 2021 15:51:23 GMT") | ||
.header("content-type", "application/x-amz-json-1.0") | ||
.header("content-length", "1231") | ||
.header("connection", "keep-alive") | ||
.header("x-amzn-requestid", "A5FGSJ9ET4OKB8183S9M47RQQBVV4KQNSO5AEMVJF66Q9ASUAAJG") | ||
.header("x-amz-crc32", "624725176") | ||
.status(http::StatusCode::from_u16(200).unwrap()) | ||
.body(Bytes::copy_from_slice(br#"{"Count":2,"Items":[{"year":{"N":"2013"},"info":{"M":{"actors":{"L":[{"S":"Daniel Bruhl"},{"S":"Chris Hemsworth"},{"S":"Olivia Wilde"}]},"plot":{"S":"A re-creation of the merciless 1970s rivalry between Formula One rivals James Hunt and Niki Lauda."},"release_date":{"S":"2013-09-02T00:00:00Z"},"image_url":{"S":"http://ia.media-imdb.com/images/M/MV5BMTQyMDE0MTY0OV5BMl5BanBnXkFtZTcwMjI2OTI0OQ@@._V1_SX400_.jpg"},"genres":{"L":[{"S":"Action"},{"S":"Biography"},{"S":"Drama"},{"S":"Sport"}]},"directors":{"L":[{"S":"Ron Howard"}]},"rating":{"N":"8.3"},"rank":{"N":"2"},"running_time_secs":{"N":"7380"}}},"title":{"S":"Rush"}},{"year":{"N":"2013"},"info":{"M":{"actors":{"L":[{"S":"David Matthewman"},{"S":"Ann Thomas"},{"S":"Jonathan G. Neff"}]},"release_date":{"S":"2013-01-18T00:00:00Z"},"plot":{"S":"A rock band plays their music at high volumes, annoying the neighbors."},"genres":{"L":[{"S":"Comedy"},{"S":"Drama"}]},"image_url":{"S":"http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg"},"directors":{"L":[{"S":"Alice Smith"},{"S":"Bob Jones"}]},"rating":{"N":"6.2"},"rank":{"N":"11"},"running_time_secs":{"N":"5215"}}},"title":{"S":"Turn It Down, Or Else!"}}],"ScannedCount":2}"#)) | ||
.unwrap(); | ||
|
||
let parser = Query::new(); | ||
let output = <Query as ParseHttpResponse<SdkBody>>::parse_loaded(&parser, &response).unwrap(); | ||
assert_eq!(2, output.count); | ||
} | ||
|
||
fn bench_group(c: &mut Criterion) { | ||
let runtime = RuntimeBuilder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
c.bench_function("deserialization_bench", |b| { | ||
b.to_async(&runtime).iter(do_bench) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_group); | ||
criterion_main!(benches); |
79 changes: 79 additions & 0 deletions
79
aws/sdk/integration-tests/dynamodb/benches/serialization_bench.rs
This file contains 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,79 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_sdk_dynamodb::input::PutItemInput; | ||
use aws_sdk_dynamodb::model::AttributeValue; | ||
use aws_sdk_dynamodb::Config; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use tokio::runtime::Builder as RuntimeBuilder; | ||
|
||
macro_rules! attr_s { | ||
($str_val:expr) => { | ||
AttributeValue::S($str_val.into()) | ||
}; | ||
} | ||
macro_rules! attr_n { | ||
($str_val:expr) => { | ||
AttributeValue::N($str_val.into()) | ||
}; | ||
} | ||
macro_rules! attr_list { | ||
( $($attr_val:expr),* ) => { | ||
AttributeValue::L(vec![$($attr_val),*]) | ||
} | ||
} | ||
macro_rules! attr_obj { | ||
{ $($str_val:expr => $attr_val:expr),* } => { | ||
AttributeValue::M( | ||
vec![ | ||
$(($str_val.to_string(), $attr_val)),* | ||
].into_iter().collect() | ||
) | ||
}; | ||
} | ||
|
||
async fn do_bench(config: &Config, input: &PutItemInput) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also doesn't need to be async anymore |
||
let operation = input | ||
.make_operation(&config) | ||
.expect("operation failed to build"); | ||
let (http_request, _parts) = operation.into_request_response().0.into_parts(); | ||
let body = http_request.body().bytes().unwrap(); | ||
assert_eq!(body[0], b'{'); | ||
} | ||
|
||
fn bench_group(c: &mut Criterion) { | ||
let runtime = RuntimeBuilder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
c.bench_function("serialization_bench", |b| { | ||
let config = Config::builder().build(); | ||
let input = PutItemInput::builder() | ||
.table_name("Movies-5") | ||
.set_item(Some( | ||
attr_obj! { | ||
"year" => attr_n!("2013"), | ||
"title" => attr_s!("Turn It Down, Or Else!"), | ||
"info" => attr_obj! { | ||
"directors" => attr_list![attr_s!("Alice Smith"), attr_s!("Bob Jones")], | ||
"release_date" => attr_s!("2013-01-18T00:00:00Z"), | ||
"rating" => attr_n!("6.2"), | ||
"genres" => attr_list!(attr_s!("Comedy"), attr_s!("Drama")), | ||
"image_url" => attr_s!("http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg"), | ||
"plot" => attr_s!("A rock band plays their music at high volumes, annoying the neighbors."), | ||
"rank" => attr_n!("11"), | ||
"running_time_secs" => attr_n!("5215"), | ||
"actors" => attr_list!(attr_s!("David Matthewman"), attr_s!("Ann Thomas"), attr_s!("Jonathan G. Neff")) | ||
} | ||
}.as_m().unwrap().clone(), | ||
)) | ||
.build() | ||
.expect("valid input"); | ||
b.to_async(&runtime).iter(|| do_bench(&config, &input)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_group); | ||
criterion_main!(benches); |
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.
This function actually doesn't need to be async