mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Various tweaks
This commit is contained in:
parent
6ff90fa0ee
commit
e064a97eb1
|
|
@ -7,6 +7,7 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
|
|
@ -53,7 +54,7 @@ func main() {
|
|||
|
||||
fmt.Println("Fetching", len(snapshotNIDs), "snapshot NIDs")
|
||||
|
||||
cache, err := caching.NewRistrettoCache(128*1024*1024, true)
|
||||
cache, err := caching.NewRistrettoCache(128*1024*1024, time.Hour, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,10 +44,18 @@ global:
|
|||
# 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 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
|
||||
|
||||
# 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
|
||||
# easier admission of new cache entries but may also increase database load in
|
||||
# comparison to higher values, so adjust conservatively.
|
||||
max_age: 1h
|
||||
|
||||
# The server name to delegate server-server communications to, with optional port
|
||||
# e.g. localhost:443
|
||||
|
|
|
|||
|
|
@ -34,10 +34,18 @@ global:
|
|||
# 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 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
|
||||
|
||||
# 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
|
||||
# easier admission of new cache entries but may also increase database load in
|
||||
# comparison to higher values, so adjust conservatively.
|
||||
max_age: 1h
|
||||
|
||||
# The server name to delegate server-server communications to, with optional port
|
||||
# e.g. localhost:443
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
|
||||
// Create a new cache but don't enable prometheus!
|
||||
s.cache, err = caching.NewRistrettoCache(8*1024*1024, false)
|
||||
s.cache, err = caching.NewRistrettoCache(8*1024*1024, time.Hour, false)
|
||||
if err != nil {
|
||||
panic("can't create cache: " + err.Error())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,37 +57,37 @@ const (
|
|||
lazyLoadingCache
|
||||
)
|
||||
|
||||
func NewRistrettoCache(maxCost config.DataUnit, enablePrometheus bool) (*Caches, error) {
|
||||
func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) (*Caches, error) {
|
||||
cache := MustCreateCache(maxCost, enablePrometheus)
|
||||
return &Caches{
|
||||
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
||||
cache: cache,
|
||||
Prefix: roomVersionsCache,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
ServerKeys: &RistrettoCachePartition[string, gomatrixserverlib.PublicKeyLookupResult]{
|
||||
cache: cache,
|
||||
Prefix: serverKeysCache,
|
||||
Mutable: true,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
RoomServerRoomIDs: &RistrettoCachePartition[int64, string]{
|
||||
cache: cache,
|
||||
Prefix: roomIDsCache,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
RoomServerEvents: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.Event]{
|
||||
&RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
||||
cache: cache,
|
||||
Prefix: roomEventsCache,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
},
|
||||
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{
|
||||
cache: cache,
|
||||
Prefix: roomInfosCache,
|
||||
Mutable: true,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
FederationPDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
||||
&RistrettoCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
||||
|
|
@ -109,13 +109,13 @@ func NewRistrettoCache(maxCost config.DataUnit, enablePrometheus bool) (*Caches,
|
|||
cache: cache,
|
||||
Prefix: spaceSummaryRoomsCache,
|
||||
Mutable: true,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
LazyLoading: &RistrettoCachePartition[string, any]{ // TODO: type
|
||||
cache: cache,
|
||||
Prefix: lazyLoadingCache,
|
||||
Mutable: true,
|
||||
MaxAge: time.Hour,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
|||
Kind: api.KindOutlier, // don't panic if we generate an output event
|
||||
Event: event.Headered(gomatrixserverlib.RoomVersionV6),
|
||||
}
|
||||
cache, err := caching.NewRistrettoCache(8*1024*1024, false)
|
||||
cache, err := caching.NewRistrettoCache(8*1024*1024, time.Hour, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
|
|||
}
|
||||
}
|
||||
|
||||
cache, err := caching.NewRistrettoCache(cfg.Global.Cache.EstMaxSize, enableMetrics)
|
||||
cache, err := caching.NewRistrettoCache(cfg.Global.Cache.EstMaxSize, cfg.Global.Cache.MaxAge, enableMetrics)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warnf("Failed to create cache")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,11 +176,13 @@ 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_bytes_est"`
|
||||
MaxAge time.Duration `yaml:"max_age"`
|
||||
}
|
||||
|
||||
func (c *Cache) Defaults(generate bool) {
|
||||
c.EstMaxSize = 1024 * 1024 * 1024 // 1GB
|
||||
c.MaxAge = time.Hour
|
||||
}
|
||||
|
||||
func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue