diff --git a/dendrite-sample.monolith.yaml b/dendrite-sample.monolith.yaml index c0134c542..d426b410a 100644 --- a/dendrite-sample.monolith.yaml +++ b/dendrite-sample.monolith.yaml @@ -41,6 +41,14 @@ global: max_idle_conns: 5 conn_max_lifetime: -1 + # Configuration for in-process caches, to help speed up processing transactions + # and reducing load on the database. + cache: + # The estimated maximum size for the global cache in bytes. Note that this is + # not a hard limit, nor is it a memory limit for the entire process. A cache that + # is too small may end up yielding little benefit. + max_bytes_est: 1073741824 + # The server name to delegate server-server communications to, with optional port # e.g. localhost:443 well_known_server_name: "" diff --git a/dendrite-sample.polylith.yaml b/dendrite-sample.polylith.yaml index b9e3e5e56..9c4a348dd 100644 --- a/dendrite-sample.polylith.yaml +++ b/dendrite-sample.polylith.yaml @@ -31,6 +31,14 @@ global: # considered valid by other homeservers. key_validity_period: 168h0m0s + # Configuration for in-process caches, to help speed up processing transactions + # and reducing load on the database. + cache: + # The estimated maximum size for the global cache in bytes. Note that this is + # not a hard limit, nor is it a memory limit for the entire process. A cache that + # is too small may end up yielding little benefit. + max_bytes_est: 1073741824 + # The server name to delegate server-server communications to, with optional port # e.g. localhost:443 well_known_server_name: "" diff --git a/setup/base/base.go b/setup/base/base.go index a02ea3d7f..85698cedc 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -161,7 +161,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base } } - cache, err := caching.NewRistrettoCache(cfg.Global.Caches.EstMaxSize, enableMetrics) + cache, err := caching.NewRistrettoCache(cfg.Global.Cache.EstMaxSize, enableMetrics) if err != nil { logrus.WithError(err).Warnf("Failed to create cache") } diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 1b2c04611..1182b6953 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -75,7 +75,7 @@ type Global struct { ReportStats ReportStats `yaml:"report_stats"` // Configuration for the caches. - Caches Caches `yaml:"caches"` + Cache Cache `yaml:"cache"` } func (c *Global) Defaults(generate bool) { @@ -93,7 +93,7 @@ func (c *Global) Defaults(generate bool) { c.Sentry.Defaults() c.ServerNotices.Defaults(generate) c.ReportStats.Defaults() - c.Caches.Defaults(generate) + c.Cache.Defaults(generate) } func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { @@ -106,7 +106,7 @@ func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { c.DNSCache.Verify(configErrs, isMonolith) c.ServerNotices.Verify(configErrs, isMonolith) c.ReportStats.Verify(configErrs, isMonolith) - c.Caches.Verify(configErrs, isMonolith) + c.Cache.Verify(configErrs, isMonolith) } type OldVerifyKeys struct { @@ -173,17 +173,15 @@ func (c *ServerNotices) Defaults(generate bool) { func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {} -type Caches struct { - Enabled bool `yaml:"enabled"` +type Cache struct { EstMaxSize int64 `yaml:"max_bytes_est"` } -func (c *Caches) Defaults(generate bool) { - c.Enabled = true +func (c *Cache) Defaults(generate bool) { c.EstMaxSize = 1024 * 1024 * 1024 // 1GB } -func (c *Caches) Verify(errors *ConfigErrors, isMonolith bool) { +func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) { checkPositive(errors, "max_bytes_est", int64(c.EstMaxSize)) }