-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Provide statistics for get operations #198
Conversation
I'm okay with adding some statistics to bb8, but this PR is pretty far from something I'd like to merge. Please concisely describe your use cases -- which information you need and why -- and then be prepared to invest time to very carefully follow any guidance I provide on how to implement this. |
Tried to update the PR with a much better explanation, please leat me know if you believe that needs still some work
That would be awesome 🙇 |
Can you give some (semi-) formal definitions for conceptually what values you want to expose, and explain why these are the minimal (in terms of complexity) measurements you need to solve for your use case? |
@djc PR should be ready for another review I would like to work on extending the statistics for adding too the following ones:
I can do this on top of this PR or in a new one, any objections? any preference? If we keep the |
Regarding my latest comment, just finished the implementation of other statistics so up to you how you want to handle this second batch of changes. Just let me know. |
Any new feedback on this one? 🙇 |
Hi @djc hope that everything is fine, if you have time I would love to have some feedback with regards the outstanding questions for this PR 🙇 |
Yes, will try to follow up soon (was on vacation for two weeks). |
@djc I believe that Ive addressed all of your comments PTAL (thanks for the review, right now the changes seem to be more aligned with the current base code!) |
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.
Much better, getting pretty close!
bb8/src/inner.rs
Outdated
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub struct Statistics { | ||
/// Information about gets. |
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.
Let's remove this line? Doesn't seem worth it.
bb8/src/api.rs
Outdated
@@ -45,6 +46,11 @@ impl<M: ManageConnection> Pool<M> { | |||
Builder::new() | |||
} | |||
|
|||
/// Returns statistics about the historical usage of the pool. | |||
pub fn statistics(&self) -> Statistics { |
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.
Hmm, actually I think we should make statistics
a field in State
. What do you think?
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.
I would expect that for having a full representation of all metrics, the ones coming from the State
would end us gauge metrics, the user will need to gather both objects, so Im ok to make this easier to the user by only requiring to make a single api call for gathering both.
Ill do that.
Hi @djc i did the changes related to moving the verbose logic for recording the gets in this commit bc9fba4 PTAL I did not go for now on adding The third option is just keep the current implementation with two segregate interfaces. Thoughts? |
I think the changes in #200 would enable doing it the way I suggested, do you agree? |
Yeps Ill piggyback on your changes for making mine changes, thanks for taking care of it! |
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.
LGTM! let me know if you need anything else from me for this PR.
Once merged - if you do that ofc - Ill make a further PR for adding more statistics.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #198 +/- ##
==========================================
+ Coverage 74.95% 76.05% +1.10%
==========================================
Files 6 6
Lines 519 543 +24
==========================================
+ Hits 389 413 +24
Misses 130 130 ☔ View full report in Codecov by Sentry. |
Thanks for your patience, happy to see more statistics in your next PR! |
Thanks for the review process, helped me a lot with my journey for learning Rust. |
Exposing three new attributes as part of a new
Statistics
typeWe will be exposing the three new attributes as part of a new
Statistics
type:get
operations performed for retrieving a new connection that did no wait for getting a connection.get
operations that had to wait for having a connection available.get
operations that did time out while waiting for a connection.See following section for understanding how these two values can be used
Why adding these three new attributes ?
Tuning the connection pool, specifically the max size and the min idle, its something that needs to be done by gathering data that helps you to understand how well configure are for example these to configuration parameters, which should lead to an ideal situation where the contention of the pool is affordable.
By having visibility of the gets that managed to retrieve a connection without waiting and having too the visibility of the ones that had to wait, the user would have available enough data for understanding if the pool is having contention.
When contention can happen
There are multiple scenarios where contention at connection pool level can happen, which can be described as the scenario where there are no enough connections free in the pool and the calls for getting a connection need to wait
By adding the
get_direct
,get_waited
andget_timed_out
we provide a way to know deterministically how much contention the connection pool is suffering. By using a simple operation like(get_waited+get_timed_out)/(get_direct + get_waited+get_timed_out)
the user can understand the percentage of operations that suffered from connection pooling contention.A low number - i.e < 1% - might indicate that the two variables are properly configured, while bigger numbers - i.e > 5% - might indicate that there is a none negligible amount of operations that are suffering an extra latency due to some level of contention when getting a connection.
How and when to use it?
There is an expectation that the
State
will be polled every X times, and the user will take the responsibility of calculating the delta from the previous values, something like:Deltas can be then sent to your favourite time series database/service - i.e prometheus, DD, etc.