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

Implement ItemBucketRateLimiter #88261

Merged
merged 1 commit into from Feb 18, 2020
Merged

Implement ItemBucketRateLimiter #88261

merged 1 commit into from Feb 18, 2020

Conversation

mborsz
Copy link
Member

@mborsz mborsz commented Feb 18, 2020

What type of PR is this?
/kind feature

What this PR does / why we need it:
This implements a simple workqueue rate limiter that is using rate.Limiter for each key separately.

It is intended to be used in #88161.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 18, 2020
@mborsz
Copy link
Member Author

mborsz commented Feb 18, 2020

/assign @wojtek-t

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 18, 2020
@wojtek-t
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 18, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mborsz, wojtek-t

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 18, 2020
@mborsz
Copy link
Member Author

mborsz commented Feb 18, 2020

/retest

@k8s-ci-robot k8s-ci-robot merged commit 1e12d92 into kubernetes:master Feb 18, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Feb 18, 2020
@fedebongio
Copy link
Contributor

/cc @lavalamp @jktomer

@k8s-ci-robot
Copy link
Contributor

@fedebongio: GitHub didn't allow me to request PR reviews from the following users: jktomer.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @lavalamp @jktomer

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/test-infra repository.


var _ RateLimiter = &ItemBucketRateLimiter{}

// NewItemBucketRateLimiter creates new ItemBucketRateLimiter instance.
Copy link
Member

Choose a reason for hiding this comment

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

What is the rationale for using this kind of rate limit for erroring items?

Copy link
Member Author

Choose a reason for hiding this comment

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

My intent was not to use this for erroring items, rather for success case.

I know that it might be slightly misleading. Do you have idea how to improve this?

I was thinking about:

  • adding a comment
  • maybe removing this from this file (the fact that it implements RateLimiter suggests that this can be used for error case)

Any other idea? WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I think that adding a comment should be enough - just descibe what are the usecases that we expect it to be used at (it's roughly Daniel`s comment from above: https://github.com/kubernetes/kubernetes/pull/88261/files/6846a0a6b62725a5888d66e2789f2af4fb172045#r380980162 )

@@ -62,6 +62,54 @@ func (r *BucketRateLimiter) NumRequeues(item interface{}) int {
func (r *BucketRateLimiter) Forget(item interface{}) {
}

// ItemBucketRateLimiter implements a workqueue ratelimiter API using standard rate.Limiter.
// Each key is using a separate limiter.
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be good to explain under what conditions it makes sense to use this.

burst int

limitersLock sync.Mutex
limiters map[interface{}]*rate.Limiter
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this pretty heavyweight if there's a lot of keys?

Copy link
Member

Choose a reason for hiding this comment

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

hm, I guess this limiter isn't as bad as I thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants