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

人盡茶涼 提交于 2020-01-04 01:58:51

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10676737/how-to-manage-memcached-cluster-across-fluctuating-aws-ec2-instances-of-django-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!