From 12b99eda89c75491f56039c4ae7d6e0f8b08bc4d Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Thu, 9 Dec 2021 14:47:35 +0100 Subject: [PATCH] Make sure Redis connection pool is large enough The default Redis PoolSize is 10 * CPU, which isn't enough to run Icinga DB on machines with only 1 CPU. Most of our open connections come from blocking XREADs. (e.g. Heartbeat, Runtime, Overdue, History) --- pkg/config/redis.go | 2 ++ pkg/utils/utils.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/pkg/config/redis.go b/pkg/config/redis.go index 259d87f8..bd3c7c05 100644 --- a/pkg/config/redis.go +++ b/pkg/config/redis.go @@ -8,6 +8,7 @@ import ( "github.com/icinga/icingadb/pkg/icingaredis" "github.com/icinga/icingadb/pkg/logging" "github.com/icinga/icingadb/pkg/retry" + "github.com/icinga/icingadb/pkg/utils" "github.com/pkg/errors" "go.uber.org/zap" "net" @@ -54,6 +55,7 @@ func (r *Redis) NewClient(logger *logging.Logger) (*icingaredis.Client, error) { opts := c.Options() opts.MaxRetries = opts.PoolSize + 1 // https://github.com/go-redis/redis/issues/1737 + opts.PoolSize = utils.MaxInt(32, opts.PoolSize) c = redis.NewClient(opts) return icingaredis.NewClient(c, logger, &r.Options), nil diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 6c8b4fff..91ed99a5 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -191,3 +191,12 @@ func AppName() string { return filepath.Base(exe) } + +// MaxInt returns the larger of the given integers. +func MaxInt(x, y int) int { + if x > y { + return x + } + + return y +}