-
Notifications
You must be signed in to change notification settings - Fork 352
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
feature: limit concurrency #2675
Conversation
Signed-off-by: Sandor Szücs <[email protected]>
if sbf, ok := ctx.StateBag()[filters.LimitConcurrency]; ok { | ||
if f, ok := sbf.(func()); ok { | ||
defer f() | ||
} | ||
} |
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.
Why do we need to defer it here instead of just decrementing on Response (or in HandleErrorResponse)?
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.
Because if the backend is fully asynchronous we need to decrement after copystream (after the full body was sent to client )
type ( | ||
limitConcurrencySpec struct{} | ||
limitConcurrencyFilter struct { | ||
concurrentRequests *atomic.Int64 |
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.
There is no need to use pointer here
if err != nil { | ||
return nil, err | ||
} | ||
if cc < 1 { |
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 think we can allow zero for completeness here.
// | ||
// - 503 if full | ||
func (f *limitConcurrencyFilter) Request(ctx filters.FilterContext) { | ||
if f.maxConcurrency > f.concurrentRequests.Load() { |
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.
This condition looks wrong
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 think this https://pkg.go.dev/golang.org/x/sync/semaphore#Weighted.TryAcquire might be more suitable here.
close this in favor of #2685 |
No description provided.