Skip to content

Fix idle pruning with sampling based implementation - #2631

Merged
YohDeadfall merged 2 commits into
npgsql:devfrom
NinoFloris:idle-pruning
Sep 23, 2019
Merged

YohDeadfall merged 2 commits into
npgsql:devfrom
NinoFloris:idle-pruning

Conversation

@NinoFloris

@NinoFloris NinoFloris commented Sep 22, 2019 •

Copy link
Copy Markdown
Member

Fixes idle pruning with sampling based implementation.
This type of manual reset/reactivation timer has a smaller lock range and no need for array copies compared to one where you'd have to worry about overlapping callbacks.

There's one possible case where enable/disable is called right when the median is calculated that might take a bit longer than we want but that entirely depends on the sample size to sort.
Ideally I'd rip this Enable/Disable from any allocate/release flows and replace it with some timer logic that uses a back-off period instead, what do you think @roji?

Also I haven't removed ReleaseTimestamp from Connector yet, now that it's not used anymore should I do that?

Fixes #2224.

Has minimal hot path locking but could be reduced by removing timer enable/disable entirely

@YohDeadfall YohDeadfall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, thank you for your work! Let's address some nits before merging.

Comment thread src/Npgsql/ConnectorPool.cs Resolved
Comment thread src/Npgsql/ConnectorPool.cs Resolved

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great, thanks! See some comments but nothing major, it's great that pruning is (almost) totally external to our critical paths now. Much better than before.

Ideally I'd rip this Enable/Disable from any allocate/release flows and replace it with some timer logic that uses a back-off period instead, what do you think @roji?

Yeah, that would remove pruning completely from the critical flows. But the way you currently do it, there's only one simple comparison of openCount to _min to allocate/release, which should really be negligible. I'd rather merge as-is now for 4.1 and revisit (if at all) later...

Also I haven't removed ReleaseTimestamp from Connector yet, now that it's not used anymore should I do that?

Kill it 😈

Comment thread src/Npgsql/ConnectorPool.cs Resolved
Comment thread src/Npgsql/ConnectorPool.cs Resolved
Comment thread src/Npgsql/ConnectorPool.cs Resolved
Comment thread src/Npgsql/ConnectorPool.cs Resolved
@roji

roji commented Sep 23, 2019

Copy link
Copy Markdown
Member

@NinoFloris once you're happy with it let me know and I'll merge for you.

@NinoFloris

Copy link
Copy Markdown
Member Author

Happy to see it merged. :shipit:

@YohDeadfall
YohDeadfall merged commit b889a12 into npgsql:dev Sep 23, 2019
@roji

roji commented Sep 23, 2019

Copy link
Copy Markdown
Member

Awesome, thanks @NinoFloris!

@waelemara

Copy link
Copy Markdown

Hi, @NinoFloris Is this fix released, and if so what is the version?

@roji

roji commented Oct 30, 2019

Copy link
Copy Markdown
Member

@waelemara as you can see on the issue for this PR (#2224), this was released as part of 4.1.0.

@waelemara

Copy link
Copy Markdown

@roji yup thanks for that, it wasn’t clear at the beginning, appreciate your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection Pool does not free idle connections in version 4.0

4 participants