mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-22 14:21:55 -06:00
Make federationsender_cache_size configurable
This commit is contained in:
parent
88264974ee
commit
4631f53241
|
@ -42,7 +42,7 @@ func main() {
|
|||
|
||||
fmt.Println("Fetching", len(snapshotNIDs), "snapshot NIDs")
|
||||
|
||||
cache, err := caching.NewInMemoryLRUCache(true)
|
||||
cache, err := caching.NewInMemoryLRUCache(&cfg.Global)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
|
|||
panic(err)
|
||||
}
|
||||
|
||||
cache, err := caching.NewInMemoryLRUCache(false)
|
||||
cache, err := caching.NewInMemoryLRUCache(&cfg.Global)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -103,6 +103,11 @@ global:
|
|||
username: metrics
|
||||
password: metrics
|
||||
|
||||
# Advanced options for tuning in-memory caches. Do not change these unless
|
||||
# you know what you are doing.
|
||||
# caches:
|
||||
# federationsender_cache_size: 128
|
||||
|
||||
# Configuration for the Appservice API.
|
||||
app_service_api:
|
||||
internal_api:
|
||||
|
|
|
@ -7,9 +7,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
FederationEventCacheName = "federation_event"
|
||||
FederationEventCacheMaxEntries = 256
|
||||
FederationEventCacheMutable = true // to allow use of Unset only
|
||||
FederationSenderCacheName = "federation_event"
|
||||
FederationSenderCacheMutable = true // to allow use of Unset only
|
||||
)
|
||||
|
||||
// FederationSenderCache contains the subset of functions needed for
|
||||
|
|
|
@ -4,16 +4,17 @@ import (
|
|||
"fmt"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
|
||||
func NewInMemoryLRUCache(cfg *config.Global) (*Caches, error) {
|
||||
roomVersions, err := NewInMemoryLRUCachePartition(
|
||||
RoomVersionCacheName,
|
||||
RoomVersionCacheMutable,
|
||||
RoomVersionCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -22,7 +23,7 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
|
|||
ServerKeyCacheName,
|
||||
ServerKeyCacheMutable,
|
||||
ServerKeyCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -31,7 +32,7 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
|
|||
RoomServerStateKeyNIDsCacheName,
|
||||
RoomServerStateKeyNIDsCacheMutable,
|
||||
RoomServerStateKeyNIDsCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -40,7 +41,7 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
|
|||
RoomServerEventTypeNIDsCacheName,
|
||||
RoomServerEventTypeNIDsCacheMutable,
|
||||
RoomServerEventTypeNIDsCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -49,7 +50,7 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
|
|||
RoomServerRoomNIDsCacheName,
|
||||
RoomServerRoomNIDsCacheMutable,
|
||||
RoomServerRoomNIDsCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -58,16 +59,16 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
|
|||
RoomServerRoomIDsCacheName,
|
||||
RoomServerRoomIDsCacheMutable,
|
||||
RoomServerRoomIDsCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
federationEvents, err := NewInMemoryLRUCachePartition(
|
||||
FederationEventCacheName,
|
||||
FederationEventCacheMutable,
|
||||
FederationEventCacheMaxEntries,
|
||||
enablePrometheus,
|
||||
FederationSenderCacheName,
|
||||
FederationSenderCacheMutable,
|
||||
cfg.Caches.FederationSenderEventCacheSize,
|
||||
cfg.Metrics.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -106,7 +106,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo
|
|||
logrus.WithError(err).Panicf("failed to start opentracing")
|
||||
}
|
||||
|
||||
cache, err := caching.NewInMemoryLRUCache(true)
|
||||
cache, err := caching.NewInMemoryLRUCache(&cfg.Global)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warnf("Failed to create cache")
|
||||
}
|
||||
|
|
|
@ -48,6 +48,9 @@ type Global struct {
|
|||
|
||||
// Metrics configuration
|
||||
Metrics Metrics `yaml:"metrics"`
|
||||
|
||||
// Cache configuration
|
||||
Caches Caches `yaml:"caches"`
|
||||
}
|
||||
|
||||
func (c *Global) Defaults() {
|
||||
|
@ -140,3 +143,14 @@ func (c DatabaseOptions) MaxOpenConns() int {
|
|||
func (c DatabaseOptions) ConnMaxLifetime() time.Duration {
|
||||
return time.Duration(c.ConnMaxLifetimeSeconds) * time.Second
|
||||
}
|
||||
|
||||
type Caches struct {
|
||||
FederationSenderEventCacheSize int `yaml:"federationsender_cache_size"`
|
||||
}
|
||||
|
||||
func (c *Caches) Defaults() {
|
||||
c.FederationSenderEventCacheSize = 128
|
||||
}
|
||||
|
||||
func (c *Caches) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue