Review comments @S7evinK

This commit is contained in:
Neil Alexander 2022-07-08 09:38:22 +01:00
parent 1437ac42e3
commit 0c63a8e0d3
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
6 changed files with 38 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -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 (

View file

@ -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,

View file

@ -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

View file

@ -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.