Skip to content
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 7 commits into from
Aug 19, 2024

Conversation

jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Aug 14, 2024

Description of changes:

always reset the config on connections yielded from ConfigPool to account for Callbacks that might be swapping the config on connections.

This also adds a doc comment for the ConfigPool confirming that it is a connection pool, and adds a benchmark to get real numbers about the performance savings of connection reuse.

This change degrades ConfigPool performance by about 4%
(772 ns -> 804 ns).

Connection Creation/connection reuse
                        time:   [803.89 ns 804.03 ns 804.17 ns]

Connection Creation/connection allocation
                        time:   [2.6046 µs 2.6057 µs 2.6068 µs]

Testing:

Added a unit test to prevent regression on this behavior.

And added a benchmark to understand the performance of the ConfigPool.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Aug 14, 2024
@jmayclin jmayclin changed the title docs(bindings): add ConfigPool doc comment fix(bindings): ConfigPool should always yield associated connections Aug 14, 2024
@@ -0,0 +1,44 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Connection Creation/connection reuse
                        time:   [751.49 ns 751.64 ns 751.78 ns]
                        change: [-3.3691% -3.3445% -3.3186%] (p = 0.00 < 0.05)
                        Performance has improved.

Connection Creation/connection allocation
                        time:   [2.2163 µs 2.2170 µs 2.2178 µs]
                        change: [-23.654% -23.616% -23.581%] (p = 0.00 < 0.05)
                        Performance has improved.

Essentially jemalloc improved the connection allocation/free performance by ~23%.

I agree that ~2 microseconds is a relatively small improvement.

maybe we have plans that suggest we can get more out of pooling than we do today in this benchmark?

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?

Copy link
Contributor

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 ;)

@jmayclin jmayclin marked this pull request as ready for review August 14, 2024 19:35
bindings/rust/s2n-tls/src/pool.rs Outdated Show resolved Hide resolved
bindings/rust/s2n-tls/src/pool.rs Outdated Show resolved Hide resolved
- change comment wording to call out benchmark as simple
- note that this is intended for environments where allocation are
  unusually expensive.
@jmayclin jmayclin requested a review from lrstewart August 15, 2024 16:44
- move documentation to module
- remove concrete numbers
@jmayclin jmayclin enabled auto-merge (squash) August 19, 2024 22:07
@jmayclin jmayclin merged commit fcc3184 into aws:main Aug 19, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants