Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Remove global lock in RateLimitStore
Browse files Browse the repository at this point in the history
Signed-off-by: TungHoang <[email protected]>
  • Loading branch information
LaPetiteSouris committed May 16, 2023
1 parent 6061035 commit dfaf183
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions plugins/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type LimiterStore struct {
accessPerUser *sync.Map
requestPerSec int
burstSize int
mutex *sync.Mutex
cleanupInterval time.Duration
}

Expand All @@ -55,8 +54,6 @@ func (l *LimiterStore) Allow(userID string) error {

// clean removes the access records for users who have not accessed the system for a while
func (l *LimiterStore) clean() {
l.mutex.Lock()
defer l.mutex.Unlock()
l.accessPerUser.Range(func(key, value interface{}) bool {
value.(*accessRecords).mutex.Lock()
defer value.(*accessRecords).mutex.Unlock()
Expand All @@ -70,7 +67,6 @@ func (l *LimiterStore) clean() {
func newRateLimitStore(requestPerSec int, burstSize int, cleanupInterval time.Duration) *LimiterStore {
l := &LimiterStore{
accessPerUser: &sync.Map{},
mutex: &sync.Mutex{},
requestPerSec: requestPerSec,
burstSize: burstSize,
cleanupInterval: cleanupInterval,
Expand Down

0 comments on commit dfaf183

Please sign in to comment.