Skip to content

Commit 719e015

Browse files
author
Aaron Meihm
authored
Merge pull request #12 from mozilla-services/redispool
redis connection pool configuration, increase timeouts
2 parents 15bf19a + 193ddee commit 719e015

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4717
-2101
lines changed

iprepd.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type serverCfg struct {
2525
ReadTimeout int
2626
WriteTimeout int
2727
DialTimeout int
28+
MaxPoolSize int
29+
MinIdleConn int
2830
}
2931
Auth struct {
3032
DisableAuth bool
@@ -48,13 +50,16 @@ func (cfg *serverCfg) validate() error {
4850
cfg.VersionResponse = "./version.json"
4951
}
5052
if cfg.Redis.ReadTimeout == 0 {
51-
cfg.Redis.ReadTimeout = 50
53+
cfg.Redis.ReadTimeout = 100
5254
}
5355
if cfg.Redis.WriteTimeout == 0 {
54-
cfg.Redis.WriteTimeout = 50
56+
cfg.Redis.WriteTimeout = 100
5557
}
5658
if cfg.Redis.DialTimeout == 0 {
57-
cfg.Redis.DialTimeout = 100
59+
cfg.Redis.DialTimeout = 250
60+
}
61+
if cfg.Redis.MinIdleConn == 0 {
62+
cfg.Redis.MinIdleConn = 20
5863
}
5964
return nil
6065
}

iprepd.yaml.sample

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ redis:
1010
#replicas:
1111
# - 127.0.0.1:7000
1212
# Read, write, and dial connection timeouts in ms (defaults shown).
13-
readtimeout: 50
14-
writetimeout: 50
15-
dialtimeout: 100
13+
readtimeout: 100
14+
writetimeout: 100
15+
dialtimeout: 250
16+
# If 0, use go-redis default maximum client pool size (10 * runtime.NumCPU()). Set to non-zero to
17+
# manually specify maximum pool size.
18+
# https://godoc.org/github.com/go-redis/redis#Options
19+
#maxpoolsize: 0
20+
# The minimum number of idle connections to try to keep open with redis. If 0, the value will
21+
# default to 20. If the maximum pool size is less than 20, it will default to the entire pool
22+
# size.
23+
#minidleconn: 0
1624
auth:
1725
# Configure any Hawk credentials here. Each credential should be specified as a key/value
1826
# pair, where the key is the Hawk ID and the value is the secret.

redis.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package iprepd
22

33
import (
44
"math/rand"
5+
"runtime"
56
"time"
67

78
"github.com/go-redis/redis"
@@ -48,12 +49,21 @@ func (r *redisLink) set(k string, v interface{}, e time.Duration) *redis.StatusC
4849
}
4950

5051
func newRedisLink(cfg serverCfg) (ret redisLink, err error) {
52+
minIdleConns := cfg.Redis.MinIdleConn
53+
if cfg.Redis.MaxPoolSize != 0 && cfg.Redis.MaxPoolSize < 20 {
54+
minIdleConns = cfg.Redis.MaxPoolSize
55+
} else if cfg.Redis.MaxPoolSize == 0 && (10*runtime.NumCPU()) < 20 {
56+
minIdleConns = 10 * runtime.NumCPU()
57+
}
58+
5159
ret.master = redis.NewClient(&redis.Options{
5260
Addr: cfg.Redis.Addr,
5361
DB: 0,
5462
ReadTimeout: time.Millisecond * time.Duration(cfg.Redis.ReadTimeout),
5563
WriteTimeout: time.Millisecond * time.Duration(cfg.Redis.WriteTimeout),
5664
DialTimeout: time.Millisecond * time.Duration(cfg.Redis.DialTimeout),
65+
PoolSize: cfg.Redis.MaxPoolSize,
66+
MinIdleConns: minIdleConns,
5767
})
5868
_, err = ret.ping().Result()
5969
if err != nil {
@@ -67,10 +77,12 @@ func newRedisLink(cfg serverCfg) (ret redisLink, err error) {
6777
continue
6878
}
6979
y := redis.NewClient(&redis.Options{
70-
Addr: x,
71-
DB: 0,
72-
ReadTimeout: time.Millisecond * time.Duration(cfg.Redis.ReadTimeout),
73-
DialTimeout: time.Millisecond * time.Duration(cfg.Redis.DialTimeout),
80+
Addr: x,
81+
DB: 0,
82+
ReadTimeout: time.Millisecond * time.Duration(cfg.Redis.ReadTimeout),
83+
DialTimeout: time.Millisecond * time.Duration(cfg.Redis.DialTimeout),
84+
PoolSize: cfg.Redis.MaxPoolSize,
85+
MinIdleConns: minIdleConns,
7486
})
7587
ret.readClients = append(ret.readClients, y)
7688
}

vendor/github.com/go-redis/redis/.travis.yml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-redis/redis/CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-redis/redis/Makefile

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-redis/redis/README.md

Lines changed: 18 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-redis/redis/bench_test.go

Lines changed: 40 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)