4

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.

ckliborn
  • 2,750
  • 4
  • 24
  • 36

1 Answers1

2

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.

Jeff Ferland
  • 20,239
  • 2
  • 61
  • 85
  • 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 05:11