Caching: Memcached vs locmem

1,098 views
Skip to first unread message

Brian

unread,
May 16, 2008, 3:20:19 PM5/16/08
to Django users
Can someone run down the differences between using Memcached vs
locmem?

The docs indicate Memcached is "the best" solution, but seems
considerably harder to setup. Just curious what the trade-offs are.

Thanks.

the.re...@gmail.com

unread,
May 17, 2008, 8:37:52 PM5/17/08
to Django users
I managed to get memcached up and running in about 5 minutes, so
whilst it does involve more setup than locmem I wouldn't say it's
difficult to the point of not being worth doing.

Memcached is basically more efficient in general and supports
clustering which makes it much better for scalability

Brian

unread,
May 17, 2008, 9:12:27 PM5/17/08
to Django users
On May 17, 7:37 pm, "a...@andrewingram.net" <the.real.a...@gmail.com>
wrote:
> I managed to get memcached up and running in about 5 minutes, so
> whilst it does involve more setup than locmem I wouldn't say it's
> difficult to the point of not being worth doing.

Thanks for that. I'll likely give it a try.

> Memcached is basically more efficient in general and supports
> clustering which makes it much better for scalability

But if you aren't clustering, say you have only a single server, is
there an advantage?

I turned on locmem today, but I don't think it is working. How can I
tell? I looked at my site with two browsers, one logged into admin,
and the other as anonymous. I made changes to the site as admin, and
the anonymous guy picked them up immediately.

Here are my settings:

CACHE_BACKEND = 'locmem:///?timeout=3600'
CACHE_MIDDLEWARE_SECONDS = 3600
CACHE_MIDDLEWARE_KEY_PREFIX = ''
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = False

MIDDLEWARE_CLASSES = (
'django.middleware.cache.CacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)

Brett Hoerner

unread,
May 18, 2008, 1:55:50 PM5/18/08
to django...@googlegroups.com
On Sat, May 17, 2008 at 8:12 PM, Brian <bgn...@gmail.com> wrote:
> But if you aren't clustering, say you have only a single server, is
> there an advantage?

Yes, locmem is memory local to a single Python process. If you're
running Django in some sort of multi-process server (as most people
do) e.g. Apache with the prefork MPM, each Python process will have to
cache for itself. If you use memcached then all of your Python
processes will speak to another process (memcached) and thus have the
same cache state at any given time.

> I turned on locmem today, but I don't think it is working. How can I
> tell? I looked at my site with two browsers, one logged into admin,
> and the other as anonymous. I made changes to the site as admin, and
> the anonymous guy picked them up immediately.

Is this using Django runserver, or under a 'production' setup such as
Apache? If you're using Apache this could be an example of the above,
your other user's request went to a different process which hadn't
cached the page yet in its own local memory.

Brett

Brian

unread,
May 18, 2008, 2:31:49 PM5/18/08
to Django users
On May 18, 12:55 pm, "Brett Hoerner" <bretthoer...@gmail.com> wrote:
> On Sat, May 17, 2008 at 8:12 PM, Brian <bgn...@gmail.com> wrote:
> > But if you aren't clustering, say you have only a single server, is
> > there an advantage?
>
> Yes, locmem is memory local to a single Python process. If you're
> running Django in some sort of multi-process server (as most people
> do) e.g. Apache with the prefork MPM, each Python process will have to
> cache for itself. If you use memcached then all of your Python
> processes will speak to another process (memcached) and thus have the
> same cache state at any given time.

Thanks, this makes sense. So each process has its own locmem cache.
But if you use memcached all processes would share memcached. Gotcha.

>
> > I turned on locmem today, but I don't think it is working. How can I
> > tell? I looked at my site with two browsers, one logged into admin,
> > and the other as anonymous. I made changes to the site as admin, and
> > the anonymous guy picked them up immediately.
>
> Is this using Django runserver, or under a 'production' setup such as
> Apache? If you're using Apache this could be an example of the above,
> your other user's request went to a different process which hadn't
> cached the page yet in its own local memory.

Yes this is under a production Apache server. Thanks.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages