tweak pool args

This commit is contained in:
Andre Medeiros 2021-07-15 13:47:22 -04:00
parent 56d72d5dea
commit e46082949a
4 changed files with 12 additions and 7 deletions

View file

@ -32,7 +32,7 @@ func APICmd(ctx context.Context) *cobra.Command {
} }
defer statsd.Close() defer statsd.Close()
db, err := cmdutil.NewDatabasePool(ctx) db, err := cmdutil.NewDatabasePool(ctx, 32)
if err != nil { if err != nil {
return err return err
} }

View file

@ -38,7 +38,7 @@ func SchedulerCmd(ctx context.Context) *cobra.Command {
} }
defer statsd.Close() defer statsd.Close()
db, err := cmdutil.NewDatabasePool(ctx) db, err := cmdutil.NewDatabasePool(ctx, 32)
if err != nil { if err != nil {
return err return err
} }

View file

@ -38,7 +38,9 @@ func WorkerCmd(ctx context.Context) *cobra.Command {
} }
defer statsd.Close() defer statsd.Close()
db, err := cmdutil.NewDatabasePool(ctx) consumers := runtime.NumCPU() * multiplier
db, err := cmdutil.NewDatabasePool(ctx, multiplier)
if err != nil { if err != nil {
return err return err
} }
@ -60,8 +62,6 @@ func WorkerCmd(ctx context.Context) *cobra.Command {
return fmt.Errorf("invalid queue: %s", queueID) return fmt.Errorf("invalid queue: %s", queueID)
} }
consumers := runtime.NumCPU() * multiplier
worker := workerFn(logger, statsd, db, redis, queue, consumers) worker := workerFn(logger, statsd, db, redis, queue, consumers)
worker.Start() worker.Start()

View file

@ -50,8 +50,13 @@ func NewRedisClient(ctx context.Context) (*redis.Client, error) {
return client, nil return client, nil
} }
func NewDatabasePool(ctx context.Context) (*pgxpool.Pool, error) { func NewDatabasePool(ctx context.Context, maxConns int) (*pgxpool.Pool, error) {
url := fmt.Sprintf("%s?sslmode=require&pool_max_conns=32", os.Getenv("DATABASE_CONNECTION_POOL_URL")) url := fmt.Sprintf(
"%s?sslmode=require&pool_max_conns=%d&pool_min_conns=%d",
os.Getenv("DATABASE_CONNECTION_POOL_URL"),
maxConns,
maxConns/8,
)
config, err := pgxpool.ParseConfig(url) config, err := pgxpool.ParseConfig(url)
if err != nil { if err != nil {
return nil, err return nil, err