Re-add default_size_factor multipler. Revert _max_size modification
parent
f300c08d98
commit
28f7f59d0f
|
@ -20,6 +20,7 @@ from six import iteritems, itervalues
|
|||
|
||||
from synapse.metrics.background_process_metrics import run_as_background_process
|
||||
from synapse.util.caches import register_cache
|
||||
from synapse.config import cache as cache_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -56,7 +57,7 @@ class ExpiringCache(object):
|
|||
self._cache_name = cache_name
|
||||
|
||||
self._original_max_size = max_len
|
||||
self._max_size = max_len
|
||||
self._max_size = int(max_len * cache_config.CACHE_PROPERTIES["default_size_factor"])
|
||||
|
||||
self._clock = clock
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import threading
|
|||
from functools import wraps
|
||||
|
||||
from synapse.util.caches.treecache import TreeCache
|
||||
from synapse.config import cache as cache_config
|
||||
|
||||
|
||||
def enumerate_leaves(node, depth):
|
||||
|
@ -78,7 +79,7 @@ class LruCache(object):
|
|||
|
||||
# Save the original max size, and apply the default size factor.
|
||||
self._original_max_size = max_size
|
||||
self._max_size = int(max_size)
|
||||
self.max_size = int(max_size * cache_config.CACHE_PROPERTIES["default_size_factor"])
|
||||
|
||||
list_root = _Node(None, None, None, None)
|
||||
list_root.next_node = list_root
|
||||
|
@ -87,7 +88,7 @@ class LruCache(object):
|
|||
lock = threading.Lock()
|
||||
|
||||
def evict():
|
||||
while cache_len() > self._max_size:
|
||||
while cache_len() > self.max_size:
|
||||
todelete = list_root.prev_node
|
||||
evicted_len = delete_node(todelete)
|
||||
cache.pop(todelete.key, None)
|
||||
|
@ -283,8 +284,8 @@ class LruCache(object):
|
|||
bool: Whether the cache changed size or not.
|
||||
"""
|
||||
new_size = int(self._original_max_size * factor)
|
||||
if new_size != self._max_size:
|
||||
self._max_size = new_size
|
||||
if new_size != self.max_size:
|
||||
self.max_size = new_size
|
||||
self._on_resize()
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
from synapse.config._base import Config, RootConfig
|
||||
from synapse.config.cache import CacheConfig, add_resizable_cache, _CACHES, CACHE_PROPERTIES
|
||||
from synapse.config.cache import CacheConfig, add_resizable_cache
|
||||
from synapse.util.caches.lrucache import LruCache
|
||||
|
||||
from tests.unittest import TestCase
|
||||
|
@ -72,13 +72,13 @@ class CacheConfigTests(TestCase):
|
|||
"""
|
||||
cache = LruCache(100)
|
||||
add_resizable_cache("foo", cache.set_cache_factor)
|
||||
self.assertEqual(cache._max_size, 50)
|
||||
self.assertEqual(cache.max_size, 50)
|
||||
|
||||
config = {"caches": {"per_cache_factors": {"foo": 3}}}
|
||||
t = TestConfig()
|
||||
t.read_config(config, config_dir_path="", data_dir_path="")
|
||||
|
||||
self.assertEqual(cache._max_size, 300)
|
||||
self.assertEqual(cache.max_size, 300)
|
||||
|
||||
def test_individual_instantiated_after_config_load(self):
|
||||
"""
|
||||
|
@ -92,7 +92,7 @@ class CacheConfigTests(TestCase):
|
|||
|
||||
cache = LruCache(100)
|
||||
add_resizable_cache("foo", cache.set_cache_factor)
|
||||
self.assertEqual(cache._max_size, 200)
|
||||
self.assertEqual(cache.max_size, 200)
|
||||
|
||||
def test_global_instantiated_before_config_load(self):
|
||||
"""
|
||||
|
@ -102,13 +102,13 @@ class CacheConfigTests(TestCase):
|
|||
"""
|
||||
cache = LruCache(100)
|
||||
add_resizable_cache("foo", cache.set_cache_factor)
|
||||
self.assertEqual(cache._max_size, 50)
|
||||
self.assertEqual(cache.max_size, 50)
|
||||
|
||||
config = {"caches": {"global_factor": 4}}
|
||||
t = TestConfig()
|
||||
t.read_config(config, config_dir_path="", data_dir_path="")
|
||||
|
||||
self.assertEqual(cache._max_size, 400)
|
||||
self.assertEqual(cache.max_size, 400)
|
||||
|
||||
def test_global_instantiated_after_config_load(self):
|
||||
"""
|
||||
|
@ -122,4 +122,4 @@ class CacheConfigTests(TestCase):
|
|||
|
||||
cache = LruCache(100)
|
||||
add_resizable_cache("foo", cache.set_cache_factor)
|
||||
self.assertEqual(cache._max_size, 150)
|
||||
self.assertEqual(cache.max_size, 150)
|
||||
|
|
Loading…
Reference in New Issue