Skip to content

Add throttler rate-limiting support and return 429 when rate-limited#2

Merged
SaschaSchwarze0 merged 1 commit into
ce-release-1.21.2from
rate_limit_1_21_2
Jun 16, 2026
Merged

Add throttler rate-limiting support and return 429 when rate-limited#2
SaschaSchwarze0 merged 1 commit into
ce-release-1.21.2from
rate_limit_1_21_2

Conversation

@norman465

@norman465 norman465 commented Jun 15, 2026

Copy link
Copy Markdown
  • Rate limiting is applied by each activator to be at 4x (1x inflight, 3x buffered) the revision concurrency by default. Guarded by [100,MAX_INT]
  • The revision concurrency implies how many activators are backing a revision with a minimum of 2:
    • revisionConcurrency/num_activators decides how many requests each activator routes and now rate limits
  • This we store at least 200 requests for the smallest possible revision with a concurrency of 1 and maxScale=1
  • Renamed/refactored variable usage for the breaker
  • Test refactoring to be more strict

Comment thread pkg/queue/breaker.go Outdated
if rateLimitingFactor == 0.0 { // no rate limiting
maxAllowedConcurrency = float64(maxQueueDepth)
}
return int64(math.Max(float64(minQueueDepth), math.Min(math.Floor(maxAllowedConcurrency), float64(maxQueueDepth))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Go has min and max built-in. Not sure if you can use them instead.

@norman465 norman465 Jun 15, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Since we actually don't care that much about exact float values here and the fact that all parameters are non-negative I cast to int and simplified all the min/max

Comment thread pkg/queue/breaker.go Outdated
@@ -161,6 +180,9 @@ func (b *Breaker) InFlight() int {

// UpdateConcurrency updates the maximum number of in-flight requests.
func (b *Breaker) UpdateConcurrency(size int) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know is not your code, but size is not a very insight-giving variable name here. Size of what ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's the size of the semaphore that guards inflight requests to the ksvc. Basically the concurrency an activator is allowed to sent. Do you want that altered?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As you prefer for our patch, but if you PR this to upstream, I recommend to take the chance to address this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll leave it as-is. Upstream I would likely address configuration differently and change more things

Comment thread pkg/activator/net/throttler.go Outdated
Comment thread pkg/activator/net/throttler.go Outdated
Comment thread pkg/queue/breaker.go Outdated
@norman465 norman465 force-pushed the rate_limit_1_21_2 branch from e045384 to 3e10f8a Compare June 15, 2026 12:39
@norman465 norman465 marked this pull request as ready for review June 16, 2026 13:10
@norman465 norman465 changed the title [DO NOT MERGE] Add throttler rate-limiting support and return 429 when rate-limited Add throttler rate-limiting support and return 429 when rate-limited Jun 16, 2026
@norman465 norman465 force-pushed the rate_limit_1_21_2 branch from 3e10f8a to ced1066 Compare June 16, 2026 13:17
@SaschaSchwarze0 SaschaSchwarze0 merged commit 36eb50e into ce-release-1.21.2 Jun 16, 2026
1 check passed
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