diff --git a/dendrite-sample.monolith.yaml b/dendrite-sample.monolith.yaml index c8c06d6c5..9f316c462 100644 --- a/dendrite-sample.monolith.yaml +++ b/dendrite-sample.monolith.yaml @@ -50,7 +50,7 @@ global: # '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_size_est: 1gb + max_size_estimated: 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 diff --git a/dendrite-sample.polylith.yaml b/dendrite-sample.polylith.yaml index c87714b51..a1433cf21 100644 --- a/dendrite-sample.polylith.yaml +++ b/dendrite-sample.polylith.yaml @@ -40,7 +40,7 @@ global: # '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_size_est: 1gb + max_size_estimated: 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 diff --git a/internal/caching/caches.go b/internal/caching/caches.go index 5bc851775..3ab1c1592 100644 --- a/internal/caching/caches.go +++ b/internal/caching/caches.go @@ -1,3 +1,17 @@ +// Copyright 2022 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package caching import ( diff --git a/internal/caching/impl_ristretto.go b/internal/caching/impl_ristretto.go index 9710cfa91..9a5224129 100644 --- a/internal/caching/impl_ristretto.go +++ b/internal/caching/impl_ristretto.go @@ -1,3 +1,17 @@ +// Copyright 2022 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package caching import ( @@ -15,7 +29,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" ) -func MustCreateCache(maxCost config.DataUnit, enablePrometheus bool) *ristretto.Cache { +func mustCreateCache(maxCost config.DataUnit, enablePrometheus bool) *ristretto.Cache { cache, err := ristretto.NewCache(&ristretto.Config{ NumCounters: 1e5, MaxCost: int64(maxCost), @@ -60,7 +74,7 @@ const ( ) func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) (*Caches, error) { - cache := MustCreateCache(maxCost, enablePrometheus) + cache := mustCreateCache(maxCost, enablePrometheus) return &Caches{ RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{ cache: cache, diff --git a/setup/base/base.go b/setup/base/base.go index e1a9a4dc0..991d2f25c 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -161,9 +161,9 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base } } - cache, err := caching.NewRistrettoCache(cfg.Global.Cache.EstMaxSize, cfg.Global.Cache.MaxAge, enableMetrics) + cache, err := caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, enableMetrics) if err != nil { - logrus.WithError(err).Warnf("Failed to create cache") + logrus.WithError(err).Fatalf("Failed to create cache") } var dnsCache *gomatrixserverlib.DNSCache diff --git a/setup/config/config_global.go b/setup/config/config_global.go index e1ccad7b6..ac1380a4e 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -176,17 +176,17 @@ func (c *ServerNotices) Defaults(generate bool) { func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {} type Cache struct { - EstMaxSize DataUnit `yaml:"max_size_est"` - MaxAge time.Duration `yaml:"max_age"` + EstimatedMaxSize DataUnit `yaml:"max_size_estimated"` + MaxAge time.Duration `yaml:"max_age"` } func (c *Cache) Defaults(generate bool) { - c.EstMaxSize = 1024 * 1024 * 1024 // 1GB + c.EstimatedMaxSize = 1024 * 1024 * 1024 // 1GB c.MaxAge = time.Hour } func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) { - checkPositive(errors, "max_size_est", int64(c.EstMaxSize)) + checkPositive(errors, "max_size_estimated", int64(c.EstimatedMaxSize)) } // ReportStats configures opt-in anonymous stats reporting.