Skip to content

Commit d31df45

Browse files
authored
feat: set poolSize and poolTimeout for manager (#4089)
Signed-off-by: Gaius <[email protected]>
1 parent 93aefb4 commit d31df45

File tree

9 files changed

+36
-12
lines changed

9 files changed

+36
-12
lines changed

internal/job/constants.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const (
4343
// Machinery server configuration.
4444
const (
4545
DefaultResultsExpireIn = 86400
46-
DefaultRedisMaxIdle = 5
47-
DefaultRedisMaxActive = 20
46+
DefaultRedisMaxIdle = 30
47+
DefaultRedisMaxActive = 50
4848
DefaultRedisIdleTimeout = 30
4949
DefaultRedisReadTimeout = 60
5050
DefaultRedisWriteTimeout = 60

manager/config/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858

5959
const (
6060
// DefaultRedisPoolSize is default pool size for redis.
61-
DefaultRedisPoolSize = 20
61+
DefaultRedisPoolSize = 40
6262

6363
// DefaultRedisPoolTimeout is default pool timeout for redis.
6464
DefaultRedisPoolTimeout = 10 * time.Second

manager/database/database.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func New(cfg *config.Config) (*Database, error) {
8888
Password: cfg.Database.Redis.Password,
8989
SentinelUsername: cfg.Database.Redis.SentinelUsername,
9090
SentinelPassword: cfg.Database.Redis.SentinelPassword,
91+
PoolSize: cfg.Database.Redis.PoolSize,
92+
PoolTimeout: cfg.Database.Redis.PoolTimeout,
9193
})
9294
if err != nil {
9395
return nil, err

pkg/redis/redis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ func NewRedis(cfg *redis.UniversalOptions) (redis.UniversalClient, error) {
7474
Password: cfg.Password,
7575
SentinelUsername: cfg.SentinelUsername,
7676
SentinelPassword: cfg.SentinelPassword,
77+
PoolSize: cfg.PoolSize,
78+
PoolTimeout: cfg.PoolTimeout,
7779
})
7880

7981
if err := client.Ping(context.Background()).Err(); err != nil {

scheduler/config/config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ type RedisConfig struct {
283283
// SentinelPassword is sentinel server password.
284284
SentinelPassword string `yaml:"sentinelPassword" mapstructure:"sentinelPassword"`
285285

286+
// PoolSize is the maximum number of idle connections in the pool.
287+
PoolSize int `yaml:"poolSize" mapstructure:"poolSize"`
288+
289+
// PoolTimeout is the maximum amount of time a connection may be idle before being closed.
290+
PoolTimeout time.Duration `yaml:"poolTimeout" mapstructure:"poolTimeout"`
291+
286292
// BrokerDB is broker database name.
287293
BrokerDB int `yaml:"brokerDB" mapstructure:"brokerDB"`
288294

@@ -334,8 +340,10 @@ func New() *Config {
334340
},
335341
Database: DatabaseConfig{
336342
Redis: RedisConfig{
337-
BrokerDB: DefaultRedisBrokerDB,
338-
BackendDB: DefaultRedisBackendDB,
343+
BrokerDB: DefaultRedisBrokerDB,
344+
BackendDB: DefaultRedisBackendDB,
345+
PoolSize: DefaultRedisPoolSize,
346+
PoolTimeout: DefaultRedisPoolTimeout,
339347
},
340348
},
341349
DynConfig: DynConfig{

scheduler/config/config_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ func TestConfig_Load(t *testing.T) {
9595
},
9696
Database: DatabaseConfig{
9797
Redis: RedisConfig{
98-
Host: "127.0.0.1",
99-
Password: "foo",
100-
Addrs: []string{"foo", "bar"},
101-
MasterName: "baz",
102-
Port: 6379,
103-
BrokerDB: DefaultRedisBrokerDB,
104-
BackendDB: DefaultRedisBackendDB,
98+
Host: "127.0.0.1",
99+
Password: "foo",
100+
Addrs: []string{"foo", "bar"},
101+
MasterName: "baz",
102+
Port: 6379,
103+
BrokerDB: DefaultRedisBrokerDB,
104+
BackendDB: DefaultRedisBackendDB,
105+
PoolSize: 10,
106+
PoolTimeout: 1 * time.Second,
105107
},
106108
},
107109
DynConfig: DynConfig{

scheduler/config/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ const (
5151

5252
// DefaultRedisBackendDB is default db for redis backend.
5353
DefaultRedisBackendDB = 2
54+
55+
// DefaultRedisPoolSize is default pool size for redis.
56+
DefaultRedisPoolSize = 20
57+
58+
// DefaultRedisPoolTimeout is default pool timeout for redis.
59+
DefaultRedisPoolTimeout = 10 * time.Second
5460
)
5561

5662
const (

scheduler/config/testdata/scheduler.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ database:
3939
password: foo
4040
brokerDB: 1
4141
backendDB: 2
42+
poolSize: 10
43+
poolTimeout: 1s
4244

4345
dynConfig:
4446
refreshInterval: 10s

scheduler/scheduler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func New(ctx context.Context, cfg *config.Config, d dfpath.Dfpath) (*Server, err
122122
Password: cfg.Database.Redis.Password,
123123
SentinelUsername: cfg.Database.Redis.SentinelUsername,
124124
SentinelPassword: cfg.Database.Redis.SentinelPassword,
125+
PoolSize: cfg.Database.Redis.PoolSize,
126+
PoolTimeout: cfg.Database.Redis.PoolTimeout,
125127
})
126128
if err != nil {
127129
return nil, err

0 commit comments

Comments
 (0)