fix: getCurrentRps

This commit is contained in:
debugtalk
2021-12-24 11:59:13 +08:00
parent f2afb8f9de
commit ab12a93bbc
3 changed files with 22 additions and 31 deletions
+3 -3
View File
@@ -164,7 +164,7 @@ func (limiter *RampUpRateLimiter) Start() {
case <-quitChannel:
return
default:
atomic.StoreInt64(&limiter.currentThreshold, limiter.nextThreshold)
atomic.StoreInt64(&limiter.currentThreshold, atomic.LoadInt64(&limiter.nextThreshold))
time.Sleep(limiter.refillPeriod)
close(limiter.broadcastChannel)
limiter.broadcastChannel = make(chan bool)
@@ -178,7 +178,7 @@ func (limiter *RampUpRateLimiter) Start() {
case <-quitChannel:
return
default:
nextValue := limiter.nextThreshold + limiter.rampUpStep
nextValue := atomic.LoadInt64(&limiter.nextThreshold) + limiter.rampUpStep
if nextValue < 0 {
// int64 overflow
nextValue = int64(math.MaxInt64)
@@ -208,6 +208,6 @@ func (limiter *RampUpRateLimiter) Acquire() (blocked bool) {
// Stop the rate limiter.
func (limiter *RampUpRateLimiter) Stop() {
limiter.nextThreshold = 0
atomic.StoreInt64(&limiter.nextThreshold, 0)
close(limiter.quitChannel)
}