I am new to the world of Memcached clusters

If I have a php web application that is using memcache - how does it does its hash and decide what node to check for a particular value to avoid having to check them all.

Bonus: How can I easily add a node in a way that avoids having to rebuild all the hashes.

| improve this question | | | | |

Memcache clients know which node to check by hashing the key value. By default it uses the crc32 value of the key. In the old style, you would do something like

serverId = crc32(key) % servers.size

This meant that when you added a new server node, most things would remap to a different node.

For your bonus, use the new style where each node covers a linear rage of crc values determined by a randomly selected server number rather than every Nth value. This is called consistent hashing.

| improve this answer | | | | |
  • How can I tell if I am using the "old" version? Is there a process to switch to the "new" version without much disruption? – ckliborn Mar 13 '12 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.