From c3820556e8552144227811c45c1b2b5b5806df15 Mon Sep 17 00:00:00 2001 From: Brennan Lamey Date: Wed, 9 Oct 2024 12:02:42 -0500 Subject: [PATCH] added max db conns --- cmd/kwild/config/config.go | 2 ++ cmd/kwild/config/flags.go | 1 + cmd/kwild/server/build.go | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/kwild/config/config.go b/cmd/kwild/config/config.go index b69bbe5e7..bab9e3197 100644 --- a/cmd/kwild/config/config.go +++ b/cmd/kwild/config/config.go @@ -79,6 +79,7 @@ type AppConfig struct { RPCTimeout Duration `mapstructure:"rpc_timeout"` RPCMaxReqSize int `mapstructure:"rpc_req_limit"` ReadTxTimeout Duration `mapstructure:"db_read_timeout"` + MaxDBConnections uint32 `mapstructure:"db_max_connections"` ExtensionEndpoints []string `mapstructure:"extension_endpoints"` AdminRPCPass string `mapstructure:"admin_pass"` NoTLS bool `mapstructure:"admin_notls"` @@ -566,6 +567,7 @@ func DefaultConfig() *KwildConfig { RPCTimeout: Duration(45 * time.Second), RPCMaxReqSize: 4_200_000, ReadTxTimeout: Duration(5 * time.Second), + MaxDBConnections: 24, Extensions: make(map[string]map[string]string), Snapshots: SnapshotConfig{ Enabled: false, diff --git a/cmd/kwild/config/flags.go b/cmd/kwild/config/flags.go index e3352ad93..c9020a004 100644 --- a/cmd/kwild/config/flags.go +++ b/cmd/kwild/config/flags.go @@ -38,6 +38,7 @@ func AddConfigFlags(flagSet *pflag.FlagSet, cfg *KwildConfig) { flagSet.Var(&cfg.AppCfg.RPCTimeout, "app.rpc-timeout", "timeout for RPC requests (through reading the request, handling the request, and sending the response)") flagSet.IntVar(&cfg.AppCfg.RPCMaxReqSize, "app.rpc-req-limit", cfg.AppCfg.RPCMaxReqSize, "RPC request size limit") flagSet.Var(&cfg.AppCfg.ReadTxTimeout, "app.db-read-timeout", "timeout for database reads initiated by RPC requests") + flagSet.Uint32Var(&cfg.AppCfg.MaxDBConnections, "app.db-max-connections", cfg.AppCfg.MaxDBConnections, "maximum number of database connections") // Extension endpoints flags flagSet.StringSliceVar(&cfg.AppCfg.ExtensionEndpoints, "app.extension-endpoints", cfg.AppCfg.ExtensionEndpoints, "kwild extension endpoints") diff --git a/cmd/kwild/server/build.go b/cmd/kwild/server/build.go index 9fda5cd1a..836e495c0 100644 --- a/cmd/kwild/server/build.go +++ b/cmd/kwild/server/build.go @@ -426,7 +426,7 @@ func buildDB(d *coreDependencies, closer *closeFuncs) *pg.DB { // If yes, restore the database from the snapshot restoreDB(d) - db, err := d.dbOpener(d.ctx, d.cfg.AppCfg.DBName, 24) + db, err := d.dbOpener(d.ctx, d.cfg.AppCfg.DBName, uint32(d.cfg.AppCfg.MaxDBConnections)) if err != nil { failBuild(err, "kwild database open failed") }