cleanup so it can refer to late-config

anoa/temp_working_cache_config
Amber H. Brown 2020-01-17 01:48:27 +11:00
parent 0a02b2a1c5
commit a21702fe76
10 changed files with 21 additions and 19 deletions

View File

@ -484,7 +484,7 @@ def phone_stats_home(hs, stats, stats_process=_stats_process):
daily_sent_messages = yield hs.get_datastore().count_daily_sent_messages() daily_sent_messages = yield hs.get_datastore().count_daily_sent_messages()
stats["daily_sent_messages"] = daily_sent_messages stats["daily_sent_messages"] = daily_sent_messages
stats["cache_factor"] = hs.config.caches.global_factor stats["cache_factor"] = hs.config.caches.global_factor
stats["event_cache_size"] = hs.config.event_cache_size stats["event_cache_size"] = hs.config.caches.event_cache_size
# #
# Performance statistics # Performance statistics

View File

@ -53,6 +53,8 @@ class CacheConfig(Config):
section = "caches" section = "caches"
def read_config(self, config, **kwargs): def read_config(self, config, **kwargs):
self.event_cache_size = self.parse_size(config.get("event_cache_size", "10K"))
global DEFAULT_CACHE_SIZE_FACTOR global DEFAULT_CACHE_SIZE_FACTOR
cache_config = config.get("caches", {}) cache_config = config.get("caches", {})

View File

@ -57,8 +57,6 @@ class DatabaseConfig(Config):
section = "database" section = "database"
def read_config(self, config, **kwargs): def read_config(self, config, **kwargs):
self.event_cache_size = self.parse_size(config.get("event_cache_size", "10K"))
# We *experimentally* support specifying multiple databases via the # We *experimentally* support specifying multiple databases via the
# `databases` key. This is a map from a label to database config in the # `databases` key. This is a map from a label to database config in the
# same format as the `database` config option, plus an extra # same format as the `database` config option, plus an extra

View File

@ -72,7 +72,7 @@ class EventsWorkerStore(SQLBaseStore):
super(EventsWorkerStore, self).__init__(database, db_conn, hs) super(EventsWorkerStore, self).__init__(database, db_conn, hs)
self._get_event_cache = Cache( self._get_event_cache = Cache(
"*getEvent*", keylen=3, max_entries=hs.config.event_cache_size "*getEvent*", keylen=3, max_entries=hs.config.caches.event_cache_size
) )
self._event_fetch_lock = threading.Condition() self._event_fetch_lock = threading.Condition()

View File

@ -31,7 +31,7 @@ logger = logging.getLogger(__name__)
class RelationsWorkerStore(SQLBaseStore): class RelationsWorkerStore(SQLBaseStore):
@cached(tree=True) @cached(tree=True, max_entries="event_cache_size")
def get_relations_for_event( def get_relations_for_event(
self, self,
event_id, event_id,
@ -133,7 +133,7 @@ class RelationsWorkerStore(SQLBaseStore):
"get_recent_references_for_event", _get_recent_references_for_event_txn "get_recent_references_for_event", _get_recent_references_for_event_txn
) )
@cached(tree=True) @cached(tree=True, max_entries="event_cache_size")
def get_aggregation_groups_for_event( def get_aggregation_groups_for_event(
self, self,
event_id, event_id,

View File

@ -28,7 +28,6 @@ from synapse.storage.data_stores.state.bg_updates import StateBackgroundUpdateSt
from synapse.storage.database import Database from synapse.storage.database import Database
from synapse.storage.state import StateFilter from synapse.storage.state import StateFilter
from synapse.types import StateMap from synapse.types import StateMap
from synapse.util.caches import get_cache_factor_for
from synapse.util.caches.descriptors import cached from synapse.util.caches.descriptors import cached
from synapse.util.caches.dictionary_cache import DictionaryCache from synapse.util.caches.dictionary_cache import DictionaryCache
@ -90,11 +89,10 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
self._state_group_cache = DictionaryCache( self._state_group_cache = DictionaryCache(
"*stateGroupCache*", "*stateGroupCache*",
# TODO: this hasn't been tuned yet # TODO: this hasn't been tuned yet
50000 * get_cache_factor_for("stateGroupCache"), 50000,
) )
self._state_group_members_cache = DictionaryCache( self._state_group_members_cache = DictionaryCache(
"*stateGroupMembersCache*", "*stateGroupMembersCache*", 500000,
500000 * get_cache_factor_for("stateGroupMembersCache"),
) )
@cached(max_entries=10000, iterable=True) @cached(max_entries=10000, iterable=True)

View File

@ -377,7 +377,10 @@ class CacheDescriptor(_CacheDescriptorBase):
self.tree = tree self.tree = tree
self.iterable = iterable self.iterable = iterable
def __get__(self, obj, objtype=None): def __get__(self, obj, owner):
if isinstance(self.max_entries, str):
self.max_entries = getattr(obj.hs.config.caches, self.max_entries)
cache = Cache( cache = Cache(
name=self.orig.__name__, name=self.orig.__name__,
max_entries=self.max_entries, max_entries=self.max_entries,

View File

@ -43,7 +43,7 @@ class ApplicationServiceStoreTestCase(unittest.TestCase):
) )
hs.config.app_service_config_files = self.as_yaml_files hs.config.app_service_config_files = self.as_yaml_files
hs.config.event_cache_size = 1 hs.config.caches.event_cache_size = 1
hs.config.password_providers = [] hs.config.password_providers = []
self.as_token = "token1" self.as_token = "token1"
@ -110,7 +110,7 @@ class ApplicationServiceTransactionStoreTestCase(unittest.TestCase):
) )
hs.config.app_service_config_files = self.as_yaml_files hs.config.app_service_config_files = self.as_yaml_files
hs.config.event_cache_size = 1 hs.config.caches.event_cache_size = 1
hs.config.password_providers = [] hs.config.password_providers = []
self.as_list = [ self.as_list = [
@ -422,7 +422,7 @@ class ApplicationServiceStoreConfigTestCase(unittest.TestCase):
) )
hs.config.app_service_config_files = [f1, f2] hs.config.app_service_config_files = [f1, f2]
hs.config.event_cache_size = 1 hs.config.caches.event_cache_size = 1
hs.config.password_providers = [] hs.config.password_providers = []
database = hs.get_datastores().databases[0] database = hs.get_datastores().databases[0]
@ -440,7 +440,7 @@ class ApplicationServiceStoreConfigTestCase(unittest.TestCase):
) )
hs.config.app_service_config_files = [f1, f2] hs.config.app_service_config_files = [f1, f2]
hs.config.event_cache_size = 1 hs.config.caches.event_cache_size = 1
hs.config.password_providers = [] hs.config.password_providers = []
with self.assertRaises(ConfigError) as cm: with self.assertRaises(ConfigError) as cm:
@ -464,7 +464,7 @@ class ApplicationServiceStoreConfigTestCase(unittest.TestCase):
) )
hs.config.app_service_config_files = [f1, f2] hs.config.app_service_config_files = [f1, f2]
hs.config.event_cache_size = 1 hs.config.caches.event_cache_size = 1
hs.config.password_providers = [] hs.config.password_providers = []
with self.assertRaises(ConfigError) as cm: with self.assertRaises(ConfigError) as cm:

View File

@ -51,7 +51,8 @@ class SQLBaseStoreTestCase(unittest.TestCase):
config = Mock() config = Mock()
config._disable_native_upserts = True config._disable_native_upserts = True
config.event_cache_size = 1 config.caches = Mock()
config.caches.event_cache_size = 1
hs = TestHomeServer("test", config=config) hs = TestHomeServer("test", config=config)
sqlite_config = {"name": "sqlite3"} sqlite_config = {"name": "sqlite3"}

View File

@ -84,7 +84,7 @@ class LruCacheTestCase(unittest.HomeserverTestCase):
self.assertEquals(len(cache), 0) self.assertEquals(len(cache), 0)
class LruCacheCallbacksTestCase(unittest.TestCase): class LruCacheCallbacksTestCase(unittest.HomeserverTestCase):
def test_get(self): def test_get(self):
m = Mock() m = Mock()
cache = LruCache(1) cache = LruCache(1)
@ -233,7 +233,7 @@ class LruCacheCallbacksTestCase(unittest.TestCase):
self.assertEquals(m3.call_count, 1) self.assertEquals(m3.call_count, 1)
class LruCacheSizedTestCase(unittest.TestCase): class LruCacheSizedTestCase(unittest.HomeserverTestCase):
def test_evict(self): def test_evict(self):
cache = LruCache(5, size_callback=len) cache = LruCache(5, size_callback=len)
cache["key1"] = [0] cache["key1"] = [0]