From fabaf4005014b8213ed5858de7a7278a480230c9 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 6 Dec 2024 19:11:34 +0300 Subject: [PATCH] fix linter --- v1/rate_limit.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v1/rate_limit.go b/v1/rate_limit.go index c530fd8..e3f3f54 100644 --- a/v1/rate_limit.go +++ b/v1/rate_limit.go @@ -8,6 +8,9 @@ import ( "time" ) +// Use double the CPU count for sharding +const shardsPerCoreMultiplier = 2 + var NoopLimiter Limiter = &noopLimiter{} type token struct { @@ -38,7 +41,7 @@ type tokenShard struct { // NewTokensBucket creates a sharded token bucket limiter. func NewTokensBucket(maxRPS uint32, unusedTokenTime, checkTokenTime time.Duration) Limiter { - shardCount := uint32(runtime.NumCPU() * 2) // Use double the CPU count for sharding + shardCount := uint32(runtime.NumCPU() * shardsPerCoreMultiplier) shards := make([]*tokenShard, shardCount) for i := range shards { shards[i] = &tokenShard{tokens: make(map[string]*token)}