Tweak max age handling, config key name

This commit is contained in:
Neil Alexander 2022-07-07 14:27:58 +01:00
parent caecdedeed
commit 56b2672f92
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 19 additions and 10 deletions

View file

@ -41,15 +41,16 @@ 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.
# Configuration for in-memory caches. Caches can often improve performance by
# keeping frequently accessed items (like events, identifiers etc.) in memory
# rather than having to read them from the database.
cache:
# The estimated maximum size for the global cache in bytes, or in terabytes,
# gigabytes, megabytes or kilobytes when the appropriate 'tb', 'gb', 'mb' or
# 'kb' suffix is specified. 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 ultimately
# provide little or no benefit.
max_bytes_est: 1gb
max_size_est: 1gb
# The maximum amount of time that a cache entry can live for in memory before
# it will be evicted and/or refreshed from the database. Lower values result in

View file

@ -31,15 +31,16 @@ 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.
# Configuration for in-memory caches. Caches can often improve performance by
# keeping frequently accessed items (like events, identifiers etc.) in memory
# rather than having to read them from the database.
cache:
# The estimated maximum size for the global cache in bytes, or in terabytes,
# gigabytes, megabytes or kilobytes when the appropriate 'tb', 'gb', 'mb' or
# 'kb' suffix is specified. 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 ultimately
# provide little or no benefit.
max_bytes_est: 1gb
max_size_est: 1gb
# The maximum amount of time that a cache entry can live for in memory before
# it will be evicted and/or refreshed from the database. Lower values result in

View file

@ -94,7 +94,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
cache: cache,
Prefix: federationPDUsCache,
Mutable: true,
MaxAge: time.Hour / 2,
MaxAge: lesserOf(time.Hour/2, maxAge),
},
},
FederationEDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.EDU]{
@ -102,7 +102,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
cache: cache,
Prefix: federationEDUsCache,
Mutable: true,
MaxAge: time.Hour / 2,
MaxAge: lesserOf(time.Hour/2, maxAge),
},
},
SpaceSummaryRooms: &RistrettoCachePartition[string, gomatrixserverlib.MSC2946SpacesResponse]{
@ -174,3 +174,10 @@ func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool) {
value, ok = v.(V)
return
}
func lesserOf(a, b time.Duration) time.Duration {
if a < b {
return a
}
return b
}

View file

@ -176,7 +176,7 @@ func (c *ServerNotices) Defaults(generate bool) {
func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {}
type Cache struct {
EstMaxSize DataUnit `yaml:"max_bytes_est"`
EstMaxSize DataUnit `yaml:"max_size_est"`
MaxAge time.Duration `yaml:"max_age"`
}
@ -186,7 +186,7 @@ func (c *Cache) Defaults(generate bool) {
}
func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) {
checkPositive(errors, "max_bytes_est", int64(c.EstMaxSize))
checkPositive(errors, "max_size_est", int64(c.EstMaxSize))
}
// ReportStats configures opt-in anonymous stats reporting.