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

Add LIFO option for getting pool resources #162

Merged
merged 5 commits into from
May 26, 2023

Conversation

zainkabani
Copy link
Contributor

@zainkabani zainkabani commented May 24, 2023

The current strategy that bb8 uses for pulling from the connection queue is FIFO. This means that we are constantly resetting idle timers for connections. This PR adds an option to make the queue a stack so that the pool can reuse the most recently used resources and allow older ones to idle timeout.

@zainkabani zainkabani marked this pull request as ready for review May 24, 2023 16:05
bb8/src/api.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 24, 2023

Codecov Report

Patch coverage: 57.14% and project coverage change: -2.91 ⚠️

Comparison is base (040b7dc) 74.28% compared to head (77516fa) 71.37%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #162      +/-   ##
==========================================
- Coverage   74.28%   71.37%   -2.91%     
==========================================
  Files           6        6              
  Lines         556      587      +31     
==========================================
+ Hits          413      419       +6     
- Misses        143      168      +25     
Impacted Files Coverage Δ
bb8/src/api.rs 61.49% <44.44%> (-0.93%) ⬇️
bb8/src/internals.rs 94.32% <80.00%> (-0.61%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

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

I'm open to merging this, but I have a bunch of stylistic suggestions.

bb8/src/api.rs Outdated
#[derive(Debug)]
pub enum QueueStrategy {
/// Last in first out
LIFO,
Copy link
Owner

Choose a reason for hiding this comment

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

We should spell the variant name Lifo instead of LIFO per the naming guidelines. IMO the comment in its current state isn't that useful, I think it would be helpful to elaborate on the intended effect.

Also, please move the type definition below the Builder impl -- the prevailing style is sort of top-down.

I think it would be useful to derive Default on QueueStrategy, and then initialize Builder::queue_strategy to QueueStrategy::default().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions, I've implemented them in my latest changes but still failing the build tests. Can't reproduce on my machine so let me know if you have any ideas on how to pass them

Copy link
Owner

Choose a reason for hiding this comment

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

That's right -- I said to derive Default but that's not supported yet by the MSRV. Can you just add a custom Default impl that does the same thing instead? I like to avoid bumping the MSRV where possible.

bb8/src/internals.rs Show resolved Hide resolved
@zainkabani zainkabani changed the title Add LIFO option for getting resources in the pool Add LIFO option for getting pool resources May 24, 2023
@zainkabani
Copy link
Contributor Author

@djc Does this seem ready for merge on your end?

@djc djc merged commit c6c8c0d into djc:main May 26, 2023
8 of 10 checks passed
@djc
Copy link
Owner

djc commented May 26, 2023

Yup, thanks!

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.

None yet

3 participants