-
Notifications
You must be signed in to change notification settings - Fork 200
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 Len and Capacity methods for ring buffer #321
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: xigang <wangxigang2014@gmail.com>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: xigang The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @xigang! |
@xigang: GitHub didn't allow me to request PR reviews from the following users: PTAL. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@@ -70,3 +70,13 @@ func (r *RingGrowing) WriteOne(data interface{}) { | |||
r.data[(r.readable+r.beg)%r.n] = data | |||
r.readable++ | |||
} | |||
|
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.
does anything ever shrink this buffer?
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.
@liggitt No, this ring buffer implementation (RingGrowing) only grows and never shrinks. Looking at the code:
- The buffer starts with an initialSize specified in
NewRingGrowing
. - When the buffer becomes full (r.readable == r.n), the
WriteOne
method doubles the size (newN := r.n * 2). - There are no methods that reduce the size of the buffer.
If shrinking capability is needed, a method can be added to shrink the buffer when it becomes too empty (for example, when readability falls below a certain threshold, such as 25% of the capacity).
Thank you, liggitt, for reviewing the code.:)
ping @deads2k Please take a look. |
@liggitt Can this PR be approved? |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Add
Len
andCapacity
methods for Informer metrics to calculatenumberOfPendingNotifications
andsizeOfRingGrowing
.PR: kubernetes/kubernetes#129160
KEP: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/4346-informer-metrics
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Release note: