开发者

Memcache failover and consistent hashing

开发者 https://www.devze.com 2022-12-31 21:21 出处:网络
I am trying to work out a good way to handle offline/down memcached servers in my current web application that are built with PHP.

I am trying to work out a good way to handle offline/down memcached servers in my current web application that are built with PHP.

I just found this link that shows an approach on how to do what I want, I think: http://web.archive.org/web/20090421075021/http://cmunezero.com/2008/08/11/consistent-memcache-hashing-and-failover-with-php/

Anyhow, it gets me confused when I start working with it and reading the PHP documention about failover with memcache. Why is offline memcache servers added to the $realInstance server pool together with the online servers?

Reading the mem开发者_StackOverflow中文版cache documentation confuses me even more: http://www.php.net/manual/en/memcache.addserver.php

status

Controls if the server should be flagged as online. Setting this parameter to FALSE and retry_interval to -1 allows a failed server to be kept in the pool so as not to affect the key distribution algorithm. Requests for this server will then failover or fail immediately depending on the memcache.allow_failover setting. Default to TRUE, meaning the server should be considered online.

Thanks,


Basically, the way memcache distributed storage works, is that you tell it about all its servers. Then when you ask for a key (either to be stored or fetched), it creates a hash of that key. That hash then goes through an algorithm to determine which server in the pool it should go to (this is all done at the client). If you remove offline servers from the pool, that hash calculation will be different, and your entire store may be compromised (the data will still be there, but you might not be able to access it).

The status flag lets you handle a server fail (one that didn't just happen) in a sizable application. So, what you can do is have a configuration file for your application that lists all the servers and its status. Then, if you need to take one of the servers offline for a few minutes (or few hours), you can set that server's status flag to false. That way, php won't try to look for it (and hit a timeout), but the hash mapping will stay the same (So everything else will still be accessible).

Make sense?

0

精彩评论

暂无评论...
验证码 换一张
取 消