Add enviroment variable SYNAPSE_CACHE_FACTOR, default it to 0.1

pull/4/merge
Erik Johnston 9 years ago
parent 742ec37ca3
commit 910fc0f28f
  1. 4
      synapse/handlers/presence.py
  2. 2
      synapse/handlers/receipts.py
  3. 6
      synapse/util/caches/descriptors.py

@ -130,6 +130,10 @@ class PresenceHandler(BaseHandler):
for state in active_presence for state in active_presence
} }
metrics.register_callback(
"user_to_current_state_size", lambda: len(self.user_to_current_state)
)
now = self.clock.time_msec() now = self.clock.time_msec()
for state in active_presence: for state in active_presence:
self.wheel_timer.insert( self.wheel_timer.insert(

@ -36,8 +36,6 @@ class ReceiptsHandler(BaseHandler):
) )
self.clock = self.hs.get_clock() self.clock = self.hs.get_clock()
self._receipt_cache = None
@defer.inlineCallbacks @defer.inlineCallbacks
def received_client_receipt(self, room_id, receipt_type, user_id, def received_client_receipt(self, room_id, receipt_type, user_id,
event_id): event_id):

@ -28,6 +28,7 @@ from twisted.internet import defer
from collections import OrderedDict from collections import OrderedDict
import os
import functools import functools
import inspect import inspect
import threading import threading
@ -38,9 +39,14 @@ logger = logging.getLogger(__name__)
_CacheSentinel = object() _CacheSentinel = object()
CACHE_SIZE_FACTOR = float(os.environ.get("SYNAPSE_CACHE_FACTOR", 0.1))
class Cache(object): class Cache(object):
def __init__(self, name, max_entries=1000, keylen=1, lru=True, tree=False): def __init__(self, name, max_entries=1000, keylen=1, lru=True, tree=False):
max_entries = int(max_entries * CACHE_SIZE_FACTOR)
if lru: if lru:
cache_type = TreeCache if tree else dict cache_type = TreeCache if tree else dict
self.cache = LruCache( self.cache = LruCache(

Loading…
Cancel
Save