How does the MemCacheStore really work with multiple servers?

扶醉桌前 提交于 2019-12-12 05:18:17

问题


I can't find documentation on the behavior of ActiveSupport::Cache::MemCacheStore anywhere, and I'm hoping someone here can shed some light. The rdoc says:

"Clustering and load balancing. One can specify multiple memcached servers, and MemCacheStore will load balance between all available servers. If a server goes down, then MemCacheStore will ignore it until it comes back up."

Ok. I want the last feature, so if a memcache server goes down the whole stack doesn't fail. But I need to understand the load balancing feature. I assume it doesn't just round robin requests, as that would result in unnecessary cache misses, it seems. Also, I'm using memcache for sessions, so I wouldn't want someone logged in to suddenly not have a session because memcache client "load balanced" that request to a server that doesn't have that session...

Can someone help me understand how the "load balancing" feature works?


回答1:


As I understand it it uses a hashing mechanism to determine which memcache server to send requests to. The hashing mechanism uses the key if the key value pair being stored thus when the value is requested by key the same hashing method will tell rails the correct memcache server to fetch the data from.

This means that if a memcache server dies you will loose the proportion of data that is cached on it (ie in a 3 server config if 1 server dies you will loose 33% of your cache)

EDIT: See http://www.ruby-forum.com/topic/100104 for a much better explanation of that than I've just given.



来源:https://stackoverflow.com/questions/5733972/how-does-the-memcachestore-really-work-with-multiple-servers

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