Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage memcached cluster across fluctuating aws ec2 instances of django servers

In Django, to cluster memcached nodes, a very simple method is used. Simply list all node address in the settings.py file of all your django servers like so:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': [
            'xxx.xxx.xxx.240:11211',
            'xxx.xxx.xxx.242:11211',
            ...,
        ]
    }
}

Obviously editing the setting.py file of each instance whenever an instance drops out or a new one is added would be painful, how would you go about automagically managing the addition of new nodes to the cluster?

  • All instances are behind a load balancer.

Possible non-answers:

  • I could also just dedicate one django instance to run a memcached single node since I am only using memcached to store tiny tokens. But the goal is to have all ec2 instances be identical.
  • I could also use elasticache but it is expensive (35 bucks/month! :) ) for the smallest version

Note: I use memcached to prevent celeryd workers from accessing the same resources, but its ok if occasionally a resource is double accessed. And my tokens have a short lifespan (less than 15 seconds). So loosing memcached nodes is not a big deal as long as it doesn't happen too frequently.

like image 274
michael Avatar asked Feb 01 '26 06:02

michael


1 Answers

If your cache data really is very small, maybe you'd be interested in a non-amazon hosted cache service like redistogo.com. They have a free version if your data is small enough and the pricing scales very very reasonably.

This doesn't answer your question at all, but since you mentioned elasticache but balked at the price, maybe it will fit your needs.

like image 72
5 revs, 4 users 78% Avatar answered Feb 03 '26 21:02

5 revs, 4 users 78%