We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 915e5fe commit 87e6317Copy full SHA for 87e6317
ratelimiter/memory.go
@@ -5,7 +5,10 @@ import (
5
"time"
6
)
7
8
-const GC_SIZE int = 100
+const (
9
+ GC_SIZE int = 100
10
+ GC_PERIOD time.Duration = 60 * time.Second
11
+)
12
13
type Memory struct {
14
store map[string]LeakyBucket
@@ -44,11 +47,10 @@ func (m *Memory) GarbageCollect() {
44
47
now := time.Now()
45
48
46
49
// rate limit GC to once per minute
- if now.Add(60*time.Second).Unix() > m.lastGCCollected.Unix() {
-
50
+ if now.Unix() >= m.lastGCCollected.Add(GC_PERIOD).Unix() {
51
for key, bucket := range m.store {
52
// if the bucket is drained, then GC
- if bucket.DrainedAt().Unix() > now.Unix() {
53
+ if bucket.DrainedAt().Unix() < now.Unix() {
54
delete(m.store, key)
55
}
56
0 commit comments