Permalink
Browse files

SRMember: Start dual-writing to a dedicated cache pool.

This is one of the most heavily hit rels currently and the hope is that
pulling it out to its own pool will make the main cache more effective
for everything else.  It may make sense to move SRMember to a different
model such as a C* DenormalizedRelation in the future.
  • Loading branch information...
1 parent 264f872 commit 347fb8bc5f4c40a645f6a200963c593462102c40 @spladug spladug committed Feb 1, 2014
Showing with 27 additions and 1 deletion.
  1. +2 −0 r2/example.ini
  2. +19 −0 r2/r2/lib/app_globals.py
  3. +6 −1 r2/r2/models/subreddit.py
View
@@ -289,6 +289,8 @@ rendercaches = 127.0.0.1:11211
pagecaches = 127.0.0.1:11211
# hosts that cache permacache cassandra data
permacache_memcaches = 127.0.0.1:11211
+# hosts that cache srmember rels (subset of Thing data)
+srmembercaches = 127.0.0.1:11211
# a local cache that's not globally consistent and can have stale data (optional)
stalecaches =
View
@@ -198,6 +198,7 @@ class Globals(object):
'rendercaches',
'pagecaches',
'memoizecaches',
+ 'srmembercaches',
'cassandra_seeds',
'admins',
'sponsors',
@@ -489,6 +490,13 @@ def setup(self):
num_clients=num_mc_clients,
)
+ # a pool just for srmember rels
+ srmembercaches = CMemcache(
+ self.srmembercaches,
+ min_compress_len=50 * 1024,
+ num_clients=num_mc_clients,
+ )
+
# a smaller pool of caches used only for distributed locks.
# TODO: move this to ZooKeeper
self.lock_cache = CMemcache(self.lockcaches,
@@ -596,6 +604,17 @@ def setup(self):
(localcache_cls(), memoizecaches))
cache_chains.update(memoizecache=self.memoizecache)
+ if stalecaches:
+ self.srmembercache = StaleCacheChain(
+ localcache_cls(),
+ stalecaches,
+ srmembercaches,
+ )
+ else:
+ self.srmembercache = MemcacheChain(
+ (localcache_cls(), srmembercaches))
+ cache_chains.update(srmembercache=self.srmembercache)
+
self.rendercache = MemcacheChain((
localcache_cls(),
rendercaches,
@@ -42,7 +42,7 @@
from r2.lib.permissions import ModeratorPermissionSet
from r2.lib.utils import tup, last_modified_multi, fuzz_activity
from r2.lib.utils import timeago, summarize_markdown
-from r2.lib.cache import sgm
+from r2.lib.cache import sgm, TransitionalCache
from r2.lib.strings import strings, Score
from r2.lib.filters import _force_unicode
from r2.lib.db import tdb_cassandra
@@ -1635,6 +1635,11 @@ def get_links(self, sort, time):
class SRMember(Relation(Subreddit, Account)):
_defaults = dict(encoded_permissions=None)
_permission_class = None
+ _cache = TransitionalCache(
+ original_cache=g.cache,
+ replacement_cache=g.srmembercache,
+ read_original=True,
+ )
def has_permission(self, perm):
"""Returns whether this member has explicitly been granted a permission.

0 comments on commit 347fb8b

Please sign in to comment.