mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Various tweaks
This commit is contained in:
parent
6ff90fa0ee
commit
e064a97eb1
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
"github.com/matrix-org/dendrite/roomserver/state"
|
||||||
|
|
@ -53,7 +54,7 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("Fetching", len(snapshotNIDs), "snapshot NIDs")
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,18 @@ global:
|
||||||
# Configuration for in-process caches, to help speed up processing transactions
|
# Configuration for in-process caches, to help speed up processing transactions
|
||||||
# and reducing load on the database.
|
# and reducing load on the database.
|
||||||
cache:
|
cache:
|
||||||
# The estimated maximum size for the global cache in bytes. Note that this is
|
# The estimated maximum size for the global cache in bytes, or in terabytes,
|
||||||
# not a hard limit, nor is it a memory limit for the entire process. A cache that
|
# gigabytes, megabytes or kilobytes when the appropriate 'tb', 'gb', 'mb' or
|
||||||
# is too small may end up yielding little benefit.
|
# 'kb' suffix is specified. Note that this is not a hard limit, nor is it a
|
||||||
max_bytes_est: 1073741824
|
# 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
|
# The server name to delegate server-server communications to, with optional port
|
||||||
# e.g. localhost:443
|
# e.g. localhost:443
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,18 @@ global:
|
||||||
# Configuration for in-process caches, to help speed up processing transactions
|
# Configuration for in-process caches, to help speed up processing transactions
|
||||||
# and reducing load on the database.
|
# and reducing load on the database.
|
||||||
cache:
|
cache:
|
||||||
# The estimated maximum size for the global cache in bytes. Note that this is
|
# The estimated maximum size for the global cache in bytes, or in terabytes,
|
||||||
# not a hard limit, nor is it a memory limit for the entire process. A cache that
|
# gigabytes, megabytes or kilobytes when the appropriate 'tb', 'gb', 'mb' or
|
||||||
# is too small may end up yielding little benefit.
|
# 'kb' suffix is specified. Note that this is not a hard limit, nor is it a
|
||||||
max_bytes_est: 1073741824
|
# 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
|
# The server name to delegate server-server communications to, with optional port
|
||||||
# e.g. localhost:443
|
# e.g. localhost:443
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new cache but don't enable prometheus!
|
// 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 {
|
if err != nil {
|
||||||
panic("can't create cache: " + err.Error())
|
panic("can't create cache: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,37 +57,37 @@ const (
|
||||||
lazyLoadingCache
|
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)
|
cache := MustCreateCache(maxCost, enablePrometheus)
|
||||||
return &Caches{
|
return &Caches{
|
||||||
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
RoomVersions: &RistrettoCachePartition[string, gomatrixserverlib.RoomVersion]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomVersionsCache,
|
Prefix: roomVersionsCache,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
ServerKeys: &RistrettoCachePartition[string, gomatrixserverlib.PublicKeyLookupResult]{
|
ServerKeys: &RistrettoCachePartition[string, gomatrixserverlib.PublicKeyLookupResult]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: serverKeysCache,
|
Prefix: serverKeysCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
RoomServerRoomIDs: &RistrettoCachePartition[int64, string]{
|
RoomServerRoomIDs: &RistrettoCachePartition[int64, string]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomIDsCache,
|
Prefix: roomIDsCache,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
RoomServerEvents: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.Event]{
|
RoomServerEvents: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.Event]{
|
||||||
&RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
&RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomEventsCache,
|
Prefix: roomEventsCache,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{
|
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: roomInfosCache,
|
Prefix: roomInfosCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
FederationPDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
FederationPDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
||||||
&RistrettoCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
&RistrettoCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
||||||
|
|
@ -109,13 +109,13 @@ func NewRistrettoCache(maxCost config.DataUnit, enablePrometheus bool) (*Caches,
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: spaceSummaryRoomsCache,
|
Prefix: spaceSummaryRoomsCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
LazyLoading: &RistrettoCachePartition[string, any]{ // TODO: type
|
LazyLoading: &RistrettoCachePartition[string, any]{ // TODO: type
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: lazyLoadingCache,
|
Prefix: lazyLoadingCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: time.Hour,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
||||||
Kind: api.KindOutlier, // don't panic if we generate an output event
|
Kind: api.KindOutlier, // don't panic if we generate an output event
|
||||||
Event: event.Headered(gomatrixserverlib.RoomVersionV6),
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to create cache")
|
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) {}
|
func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {}
|
||||||
|
|
||||||
type Cache struct {
|
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) {
|
func (c *Cache) Defaults(generate bool) {
|
||||||
c.EstMaxSize = 1024 * 1024 * 1024 // 1GB
|
c.EstMaxSize = 1024 * 1024 * 1024 // 1GB
|
||||||
|
c.MaxAge = time.Hour
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) {
|
func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue