mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
fill_memcached_caches: Also fill the caches of User/UserProfile objects.
Since we flush memcached when we do a server restart, the flurry of get_updates requests that fly in afterwards are all cache misses for getting the User/UserProfile objects, so Tornado ends up spending around 70ms per get_updates request rather than the usual 1-2ms. So this should substantially improve our Tornado performance around server restarts. (imported from commit 07b8126bdfd4ff14e4c3362f9eda1fe5fd571c5b)
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
# This file needs to be different from cache.py because cache.py
|
# This file needs to be different from cache.py because cache.py
|
||||||
# cannot import anything from zephyr.models or we'd have an import
|
# cannot import anything from zephyr.models or we'd have an import
|
||||||
# loop
|
# loop
|
||||||
from zephyr.models import Message
|
from zephyr.models import Message, UserProfile
|
||||||
from zephyr.lib.cache import cache_with_key, djcache, message_cache_key
|
from zephyr.lib.cache import cache_with_key, djcache, message_cache_key, \
|
||||||
|
userprofile_by_email_cache_key, userprofile_by_user_cache_key, \
|
||||||
|
user_by_id_cache_key
|
||||||
|
|
||||||
MESSAGE_CACHE_SIZE = 25000
|
MESSAGE_CACHE_SIZE = 25000
|
||||||
|
|
||||||
@@ -21,3 +23,17 @@ def populate_message_cache():
|
|||||||
items_for_memcached[message_cache_key(m.id)] = (m,)
|
items_for_memcached[message_cache_key(m.id)] = (m,)
|
||||||
|
|
||||||
djcache.set_many(items_for_memcached, timeout=3600*24)
|
djcache.set_many(items_for_memcached, timeout=3600*24)
|
||||||
|
|
||||||
|
# Fill our various caches of User/UserProfile objects used by Tornado
|
||||||
|
def populate_user_cache():
|
||||||
|
items_for_memcached = {}
|
||||||
|
for user_profile in UserProfile.objects.select_related().all():
|
||||||
|
items_for_memcached[userprofile_by_email_cache_key(user_profile.user.email)] = (user_profile,)
|
||||||
|
items_for_memcached[userprofile_by_user_cache_key(user_profile.user.id)] = (user_profile,)
|
||||||
|
items_for_memcached[user_by_id_cache_key(user_profile.user.id)] = (user_profile.user,)
|
||||||
|
|
||||||
|
djcache.set_many(items_for_memcached, timeout=3600*24*7)
|
||||||
|
|
||||||
|
def fill_memcached_caches():
|
||||||
|
populate_user_cache()
|
||||||
|
populate_message_cache()
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from zephyr.lib.cache_helpers import populate_message_cache
|
from zephyr.lib.cache_helpers import fill_memcached_caches
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
option_list = BaseCommand.option_list
|
option_list = BaseCommand.option_list
|
||||||
help = "Populate the memcached cache of messages."
|
help = "Populate the memcached cache of messages."
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
populate_message_cache()
|
fill_memcached_caches()
|
||||||
|
|||||||
Reference in New Issue
Block a user