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

feature: limit concurrency #2675

Closed
wants to merge 1 commit into from
Closed

Conversation

szuecs
Copy link
Member

@szuecs szuecs commented Oct 13, 2023

No description provided.

Signed-off-by: Sandor Szücs <[email protected]>
Comment on lines +1487 to +1491
if sbf, ok := ctx.StateBag()[filters.LimitConcurrency]; ok {
if f, ok := sbf.(func()); ok {
defer f()
}
}
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov Oct 13, 2023

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)?

Copy link
Member Author

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
Copy link
Member

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 {
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 we can allow zero for completeness here.

//
// - 503 if full
func (f *limitConcurrencyFilter) Request(ctx filters.FilterContext) {
if f.maxConcurrency > f.concurrentRequests.Load() {
Copy link
Member

Choose a reason for hiding this comment

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

This condition looks wrong

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 this https://pkg.go.dev/golang.org/x/sync/semaphore#Weighted.TryAcquire might be more suitable here.

@szuecs
Copy link
Member Author

szuecs commented Oct 19, 2023

close this in favor of #2685

@szuecs szuecs closed this Oct 19, 2023
@szuecs szuecs deleted the feature/limit-concurrency branch October 19, 2023 12:03
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