-
Notifications
You must be signed in to change notification settings - Fork 717
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
fix(bindings): ConfigPool should always yield associated connections #4708
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1f5033
docs(bindings): add ConfigPool doc comment
jmayclin a7421d0
fix: reset the config in the connection pool
jmayclin 0ba46f1
address pr feedback
jmayclin 766dab7
address pr feedback
jmayclin a4287b0
explain yielded connection association
jmayclin 993d090
address ci failure
jmayclin 78a4b57
Merge branch 'main' into pool-investigation
jmayclin 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
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,44 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use s2n_tls::{ | ||
config::Config, | ||
connection::Builder, | ||
enums::Mode, | ||
pool::{ConfigPool, ConfigPoolBuilder, PooledConnection}, | ||
}; | ||
use std::sync::Arc; | ||
|
||
fn connection_wipe(connection_pool: &Arc<ConfigPool>) { | ||
// get a connection from the pool | ||
let conn = PooledConnection::new(connection_pool).unwrap(); | ||
// "drop" the connection, wiping it and returning it to the pool | ||
drop(conn); | ||
} | ||
|
||
fn connection_new(config: &Config) { | ||
let conn = config | ||
.build_connection(s2n_tls::enums::Mode::Server) | ||
.unwrap(); | ||
drop(conn); | ||
} | ||
|
||
fn connection_creation(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Connection Creation"); | ||
let config = s2n_tls::config::Builder::new().build().unwrap(); | ||
let connection_pool = ConfigPoolBuilder::new(Mode::Server, config.clone()).build(); | ||
|
||
group.bench_function("connection reuse", |b| { | ||
b.iter(|| connection_wipe(&connection_pool)); | ||
}); | ||
|
||
group.bench_function("connection allocation", |b| { | ||
b.iter(|| connection_new(&config)); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, connection_creation); | ||
criterion_main!(benches); |
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
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
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.
If you didn't already, it's probably a good idea to re-run this with a more recent allocator (e.g., jemalloc) and see how much that changes the results. Still, ~2 microsecond of difference feels to me like there is probably no reason to use a connection pool -- maybe we have plans that suggest we can get more out of pooling than we do today in this benchmark?
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.
Rerunning the benchmarks with jemalloc I got the following results.
Essentially jemalloc improved the connection allocation/free performance by ~23%.
I agree that ~2 microseconds is a relatively small improvement.
I'm not aware of any, although we're certainly open to suggestions! My goal with this benchmark was to have some empirical data to help highlight the benefit or lack thereof.
My understanding is that connection reuse was one of the older features of s2n-tls, so perhaps the performance benefit was more significant with older platforms/allocators?
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.
Connection reuse is specifically intended for situations where allocation is expensive. There would be no reason to reuse connections with a modern allocator like jemalloc. Unfortunately most of our customers don't use jemalloc ;)