Skip to content

Delay connection attempts without addresses. #64

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

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

fabianfett
Copy link
Member

Cherry pick:
https://gitlab.com/swift-server-community/RediStack/-/merge_requests/147

Motivation

In some circumstances users may have connection pools configured without any SocketAddresses ready to go. This is particularly likely in service discovery configurations. Right now, the effect of attempting to use such a pool is two fold. First, we'll emit a bunch of error level logs telling users we have no addresses. Second, we'll fall into the exponential backoff phase of connection establishment.

The first property is annoying, but the second one is actively harmful. If your construction is timed incorrectly, we'll have the awkward problem of burning a bunch of CPU trying to create connections we know we cannot, and then a lengthy delay after the addresses are actually configured before we start trying to use them. That's the worst of all worlds.

This patch adds logic to detect the attempt to create connections when we don't have any configured addresses and delays them. This path should improve performance and ergonomics when in this mode.

@fabianfett fabianfett added the 🔨 semver/patch No public API change. label Jun 18, 2023
@fabianfett fabianfett assigned Joannis and unassigned Joannis Jun 18, 2023
@fabianfett fabianfett requested a review from Joannis June 18, 2023 13:07
@fabianfett fabianfett marked this pull request as draft June 18, 2023 13:25
@fabianfett
Copy link
Member Author

Oh we need to change this a tiny bit to not break API.

Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change! My main question, not necessarily for this PR, is if we can/should add an eventLoop. preconditionInEventLoop() inside the newly added mutable stored property.

In some circumstances users may have connection pools configured without
any SocketAddresses ready to go. This is particularly likely in service
discovery configurations. Right now, the effect of attempting to use
such a pool is two fold. First, we'll emit a bunch of error level logs
telling users we have no addresses. Second, we'll fall into the
exponential backoff phase of connection establishment.

The first property is annoying, but the second one is actively harmful.
If your construction is timed incorrectly, we'll have the awkward
problem of burning a bunch of CPU trying to create connections we know
we cannot, and then a lengthy delay after the addresses are actually
configured before we start trying to use them. That's the worst of all
worlds.

This patch adds logic to detect the attempt to create connections when
we don't have any configured addresses and delays them. This path should
improve performance and ergonomics when in this mode.
@fabianfett fabianfett force-pushed the ff-cory-cherry-pick-1 branch from e404c74 to 921b983 Compare June 19, 2023 08:27
@fabianfett fabianfett marked this pull request as ready for review June 19, 2023 08:32
Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks even better

@fabianfett fabianfett merged commit ef5fdf7 into main Jun 19, 2023
@fabianfett fabianfett deleted the ff-cory-cherry-pick-1 branch June 19, 2023 08:37
@fabianfett fabianfett added 🆕 semver/minor Adds new public API. and removed 🔨 semver/patch No public API change. labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants