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

Fix rate limiting in priority matcher #7406

Open
wants to merge 1 commit into
base: priority
Choose a base branch
from
Open

Conversation

dnr
Copy link
Member

@dnr dnr commented Feb 28, 2025

What changed?

  • Add interface for task-specific absolute ready time (currently not task-specific yet)
  • Use ready time to delay match
  • Add new simple limiter that works with ready times
  • Hook up existing dynamic configs and user-controlled limit

Why?

  • Accurate rate limiting in priority matcher
  • Hooks for future per-priority, per-fairness key, etc. limits

How did you test it?

not tested yet, on feature branch

@dnr dnr requested a review from a team as a code owner February 28, 2025 18:49
Copy link
Contributor

@stephanos stephanos left a comment

Choose a reason for hiding this comment

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

Approved with comments, as discussed.

return delay <= 0
now := time.Now().UnixNano()
d.tasks.consumeTokens(now, task, -1)
d.match() // another task may be ready to match now
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO

Comment on lines +599 to +601
func (s *simpleLimiter) consume(now int64, tokens int64) {
s.ready = max(now, s.ready+s.burst) - s.burst + tokens*s.interval
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, additional comment would be helpful to explain the overall intuition.

ready int64 // unix nanos
}

func (s *simpleLimiter) set(rate float64, burst int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, passing in burst duration seems slightly easier to follow.

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.

2 participants