File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ type Config struct {
20
20
// Timeout for each Redis command after which we fall back to a local
21
21
// in-memory counter. If Redis does not respond within this duration,
22
22
// the system will use the local counter unless it is explicitly disabled.
23
- FallbackTimeout time.Duration `toml:"fallback_timeout"` // default: 50ms
23
+ FallbackTimeout time.Duration `toml:"fallback_timeout"` // default: 100ms
24
24
25
25
// Client if supplied will be used and the below fields will be ignored.
26
26
//
@@ -31,6 +31,6 @@ type Config struct {
31
31
Port uint16 `toml:"port"`
32
32
Password string `toml:"password"` // optional
33
33
DBIndex int `toml:"db_index"` // default: 0
34
- MaxIdle int `toml:"max_idle"` // default: 4
35
- MaxActive int `toml:"max_active"` // default: 8
34
+ MaxIdle int `toml:"max_idle"` // default: 5
35
+ MaxActive int `toml:"max_active"` // default: 10
36
36
}
Original file line number Diff line number Diff line change @@ -38,8 +38,13 @@ func NewRedisLimitCounter(cfg *Config) (*redisCounter, error) {
38
38
cfg .PrefixKey = "httprate"
39
39
}
40
40
if cfg .FallbackTimeout == 0 {
41
- // Activate local in-memory fallback fairly quickly, as this would slow down all requests.
42
- cfg .FallbackTimeout = 100 * time .Millisecond
41
+ if cfg .FallbackDisabled {
42
+ cfg .FallbackTimeout = time .Second
43
+ } else {
44
+ // Activate local in-memory fallback fairly quickly,
45
+ // so we don't slow down incoming requests too much.
46
+ cfg .FallbackTimeout = 100 * time .Millisecond
47
+ }
43
48
}
44
49
45
50
rc := & redisCounter {
@@ -52,10 +57,10 @@ func NewRedisLimitCounter(cfg *Config) (*redisCounter, error) {
52
57
if cfg .Client == nil {
53
58
maxIdle , maxActive := cfg .MaxIdle , cfg .MaxActive
54
59
if maxIdle < 1 {
55
- maxIdle = 20
60
+ maxIdle = 5
56
61
}
57
62
if maxActive < 1 {
58
- maxActive = 50
63
+ maxActive = 10
59
64
}
60
65
61
66
rc .client = redis .NewClient (& redis.Options {
You can’t perform that action at this time.
0 commit comments