Skip to content

Commit fb8b73e

Browse files
committed
Chill the defaults, we don't need that many connections
1 parent 408208f commit fb8b73e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Config struct {
2020
// Timeout for each Redis command after which we fall back to a local
2121
// in-memory counter. If Redis does not respond within this duration,
2222
// 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
2424

2525
// Client if supplied will be used and the below fields will be ignored.
2626
//
@@ -31,6 +31,6 @@ type Config struct {
3131
Port uint16 `toml:"port"`
3232
Password string `toml:"password"` // optional
3333
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
3636
}

httprateredis.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ func NewRedisLimitCounter(cfg *Config) (*redisCounter, error) {
3838
cfg.PrefixKey = "httprate"
3939
}
4040
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+
}
4348
}
4449

4550
rc := &redisCounter{
@@ -52,10 +57,10 @@ func NewRedisLimitCounter(cfg *Config) (*redisCounter, error) {
5257
if cfg.Client == nil {
5358
maxIdle, maxActive := cfg.MaxIdle, cfg.MaxActive
5459
if maxIdle < 1 {
55-
maxIdle = 20
60+
maxIdle = 5
5661
}
5762
if maxActive < 1 {
58-
maxActive = 50
63+
maxActive = 10
5964
}
6065

6166
rc.client = redis.NewClient(&redis.Options{

0 commit comments

Comments
 (0)