Skip to content

Commit

Permalink
common: improve aimd limiter (#542)
Browse files Browse the repository at this point in the history
Signed-off-by: huanghaoyuanhhy <[email protected]>
  • Loading branch information
huanghaoyuanhhy authored Feb 17, 2025
1 parent d1da847 commit d42df3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func isRateLimitError(err error) bool {

func newRateLimiters() map[string]*common.AIMDLimiter {
return map[string]*common.AIMDLimiter{
"flush": common.NewAIMDLimiter(1, 50, 5),
"flush": common.NewAIMDLimiter(0.01, 50, 5),
"createColl": common.NewAIMDLimiter(1, 100, 5),
}
}
Expand Down
10 changes: 7 additions & 3 deletions internal/common/aimd_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ func (a *AIMDLimiter) Wait(ctx context.Context) error {
}

func (a *AIMDLimiter) Success() {
if a.curRPS.Load() >= a.maxRPS {
curRPS := a.curRPS.Load()
if curRPS >= a.maxRPS {
return
}

a.curRPS.Add(1)
if curRPS < 1 {
a.curRPS.Add(0.1)
} else {
a.curRPS.Add(1)
}
}

func (a *AIMDLimiter) Failure() {
Expand Down

0 comments on commit d42df3f

Please sign in to comment.