mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Review comments @S7evinK
This commit is contained in:
parent
1437ac42e3
commit
0c63a8e0d3
|
|
@ -50,7 +50,7 @@ global:
|
||||||
# 'kb' suffix is specified. Note that this is not a hard limit, nor is it a
|
# '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
|
# memory limit for the entire process. A cache that is too small may ultimately
|
||||||
# provide little or no benefit.
|
# 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
|
# 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
|
# it will be evicted and/or refreshed from the database. Lower values result in
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ global:
|
||||||
# 'kb' suffix is specified. Note that this is not a hard limit, nor is it a
|
# '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
|
# memory limit for the entire process. A cache that is too small may ultimately
|
||||||
# provide little or no benefit.
|
# 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
|
# 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
|
# it will be evicted and/or refreshed from the database. Lower values result in
|
||||||
|
|
|
||||||
|
|
@ -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
|
package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -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
|
package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -15,7 +29,7 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"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{
|
cache, err := ristretto.NewCache(&ristretto.Config{
|
||||||
NumCounters: 1e5,
|
NumCounters: 1e5,
|
||||||
MaxCost: int64(maxCost),
|
MaxCost: int64(maxCost),
|
||||||
|
|
@ -60,7 +74,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) (*Caches, error) {
|
func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) (*Caches, error) {
|
||||||
cache := MustCreateCache(maxCost, enablePrometheus)
|
cache := mustCreateCache(maxCost, enablePrometheus)
|
||||||
return &Caches{
|
return &Caches{
|
||||||
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to create cache")
|
logrus.WithError(err).Fatalf("Failed to create cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsCache *gomatrixserverlib.DNSCache
|
var dnsCache *gomatrixserverlib.DNSCache
|
||||||
|
|
|
||||||
|
|
@ -176,17 +176,17 @@ func (c *ServerNotices) Defaults(generate bool) {
|
||||||
func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {}
|
func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {}
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
EstMaxSize DataUnit `yaml:"max_size_est"`
|
EstimatedMaxSize DataUnit `yaml:"max_size_estimated"`
|
||||||
MaxAge time.Duration `yaml:"max_age"`
|
MaxAge time.Duration `yaml:"max_age"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) Defaults(generate bool) {
|
func (c *Cache) Defaults(generate bool) {
|
||||||
c.EstMaxSize = 1024 * 1024 * 1024 // 1GB
|
c.EstimatedMaxSize = 1024 * 1024 * 1024 // 1GB
|
||||||
c.MaxAge = time.Hour
|
c.MaxAge = time.Hour
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) {
|
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.
|
// ReportStats configures opt-in anonymous stats reporting.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue