diff options
author | 2023-01-26 15:12:48 +0100 | |
---|---|---|
committer | 2023-01-26 15:12:48 +0100 | |
commit | 782169da765baf1d651c1b71e5f974f762c92d8e (patch) | |
tree | 073d78698a911af2ac37a2a64bf5ae57406fc38c /internal/config | |
parent | [feature] Public list of suspended domains (#1362) (diff) | |
download | gotosocial-782169da765baf1d651c1b71e5f974f762c92d8e.tar.xz |
[chore] set max open / idle conns + conn max lifetime for both postgres and sqlite (#1369)
* [chore] set max open / idle conns + conn max lifetime for both postgres and sqlite
* reduce cache size default to 8MiB, reduce connections to 2 * cpu
* introduce max open conns multiplier, tune sqlite and pg separately
* go fmt
Diffstat (limited to 'internal/config')
-rw-r--r-- | internal/config/config.go | 25 | ||||
-rw-r--r-- | internal/config/defaults.go | 25 | ||||
-rw-r--r-- | internal/config/flags.go | 1 | ||||
-rw-r--r-- | internal/config/helpers.gen.go | 25 |
4 files changed, 52 insertions, 24 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 472e7b93d..7025ab63a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -58,18 +58,19 @@ type Configuration struct { TrustedProxies []string `name:"trusted-proxies" usage:"Proxies to trust when parsing x-forwarded headers into real IPs."` SoftwareVersion string `name:"software-version" usage:""` - DbType string `name:"db-type" usage:"Database type: eg., postgres"` - DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"` - DbPort int `name:"db-port" usage:"Database port"` - DbUser string `name:"db-user" usage:"Database username"` - DbPassword string `name:"db-password" usage:"Database password"` - DbDatabase string `name:"db-database" usage:"Database name"` - DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"` - DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"` - DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"` - DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"` - DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"` - DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"` + DbType string `name:"db-type" usage:"Database type: eg., postgres"` + DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"` + DbPort int `name:"db-port" usage:"Database port"` + DbUser string `name:"db-user" usage:"Database username"` + DbPassword string `name:"db-password" usage:"Database password"` + DbDatabase string `name:"db-database" usage:"Database name"` + DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"` + DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"` + DbMaxOpenConnsMultiplier int `name:"db-max-open-conns-multiplier" usage:"Multiplier to use per cpu for max open database connections. 0 or less is normalized to 1."` + DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"` + DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"` + DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"` + DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"` WebTemplateBaseDir string `name:"web-template-base-dir" usage:"Basedir for html templating files for rendering pages and composing emails."` WebAssetBaseDir string `name:"web-asset-base-dir" usage:"Directory to serve static assets from, accessible at example.org/assets/"` diff --git a/internal/config/defaults.go b/internal/config/defaults.go index ecd32be2f..6b4c5db17 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -40,18 +40,19 @@ var Defaults = Configuration{ Port: 8080, TrustedProxies: []string{"127.0.0.1/32", "::1"}, // localhost - DbType: "postgres", - DbAddress: "", - DbPort: 5432, - DbUser: "", - DbPassword: "", - DbDatabase: "gotosocial", - DbTLSMode: "disable", - DbTLSCACert: "", - DbSqliteJournalMode: "WAL", - DbSqliteSynchronous: "NORMAL", - DbSqliteCacheSize: 64 * bytesize.MiB, - DbSqliteBusyTimeout: time.Minute * 5, + DbType: "postgres", + DbAddress: "", + DbPort: 5432, + DbUser: "", + DbPassword: "", + DbDatabase: "gotosocial", + DbTLSMode: "disable", + DbTLSCACert: "", + DbMaxOpenConnsMultiplier: 8, + DbSqliteJournalMode: "WAL", + DbSqliteSynchronous: "NORMAL", + DbSqliteCacheSize: 8 * bytesize.MiB, + DbSqliteBusyTimeout: time.Minute * 5, WebTemplateBaseDir: "./web/template/", WebAssetBaseDir: "./web/assets/", diff --git a/internal/config/flags.go b/internal/config/flags.go index a21f17f53..e594615d1 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -51,6 +51,7 @@ func (s *ConfigState) AddGlobalFlags(cmd *cobra.Command) { cmd.PersistentFlags().String(DbDatabaseFlag(), cfg.DbDatabase, fieldtag("DbDatabase", "usage")) cmd.PersistentFlags().String(DbTLSModeFlag(), cfg.DbTLSMode, fieldtag("DbTLSMode", "usage")) cmd.PersistentFlags().String(DbTLSCACertFlag(), cfg.DbTLSCACert, fieldtag("DbTLSCACert", "usage")) + cmd.PersistentFlags().Int(DbMaxOpenConnsMultiplierFlag(), cfg.DbMaxOpenConnsMultiplier, fieldtag("DbMaxOpenConnsMultiplier", "usage")) cmd.PersistentFlags().String(DbSqliteJournalModeFlag(), cfg.DbSqliteJournalMode, fieldtag("DbSqliteJournalMode", "usage")) cmd.PersistentFlags().String(DbSqliteSynchronousFlag(), cfg.DbSqliteSynchronous, fieldtag("DbSqliteSynchronous", "usage")) cmd.PersistentFlags().Uint64(DbSqliteCacheSizeFlag(), uint64(cfg.DbSqliteCacheSize), fieldtag("DbSqliteCacheSize", "usage")) diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 3560c566a..3bf62efc6 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -524,6 +524,31 @@ func GetDbTLSCACert() string { return global.GetDbTLSCACert() } // SetDbTLSCACert safely sets the value for global configuration 'DbTLSCACert' field func SetDbTLSCACert(v string) { global.SetDbTLSCACert(v) } +// GetDbMaxOpenConnsMultiplier safely fetches the Configuration value for state's 'DbMaxOpenConnsMultiplier' field +func (st *ConfigState) GetDbMaxOpenConnsMultiplier() (v int) { + st.mutex.Lock() + v = st.config.DbMaxOpenConnsMultiplier + st.mutex.Unlock() + return +} + +// SetDbMaxOpenConnsMultiplier safely sets the Configuration value for state's 'DbMaxOpenConnsMultiplier' field +func (st *ConfigState) SetDbMaxOpenConnsMultiplier(v int) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.DbMaxOpenConnsMultiplier = v + st.reloadToViper() +} + +// DbMaxOpenConnsMultiplierFlag returns the flag name for the 'DbMaxOpenConnsMultiplier' field +func DbMaxOpenConnsMultiplierFlag() string { return "db-max-open-conns-multiplier" } + +// GetDbMaxOpenConnsMultiplier safely fetches the value for global configuration 'DbMaxOpenConnsMultiplier' field +func GetDbMaxOpenConnsMultiplier() int { return global.GetDbMaxOpenConnsMultiplier() } + +// SetDbMaxOpenConnsMultiplier safely sets the value for global configuration 'DbMaxOpenConnsMultiplier' field +func SetDbMaxOpenConnsMultiplier(v int) { global.SetDbMaxOpenConnsMultiplier(v) } + // GetDbSqliteJournalMode safely fetches the Configuration value for state's 'DbSqliteJournalMode' field func (st *ConfigState) GetDbSqliteJournalMode() (v string) { st.mutex.Lock() |