Hashing uses port number?

Mikael Johansson mikael at synd.info
Fri Sep 1 16:52:47 UTC 2006

Each call to Memcache::addServer() adds $weight (default = 1) number of
buckets to the list of possible servers to select for a given key. When
selecting a server to serve a given key, the key is hashed using (more
or less) crc32(key)%total_number_of_buckets.

The short answer is that yes, the port is considered in the hashing
algorithm. If your all your data is stored on the first server it's
because all the keys you are using map to that specific servers buckets.
Using memcache_connect() or only addServer() shouldn't make a
difference, though the hignest performance can be found using the
extension as

 $mmc = new Memcache()
 $mmc->addServer('node01.example.com', 11211);
 $mmc->addServer('node02.example.com', 11211);
 $mmc->addServer('node03.example.com', 11211);

 $mmc->set('foo', 'bar');

Since addServer() will not connect to the server until actually needed
(such as when the server is selected for a set/get operation)


Chris Newland wrote:
> Hi,
> I'm trying to simulate my production environment by running multiple
> memcached servers on my dev machine (on different ports).
> I can add the servers to the pool, and getExtendedStats for all of them
> ok but when I try to write data, it only goes to the memcached that I
> have connected to. (Using getExtendedStats curr_items to determine this).
> Can someone let me know if the port is considered in the hashing algorithm?
> I hope not as that would be an easy explanation.
> I'm using Debian Sarge, memcached 2.0.4, PHP PECL memcache client.
> Many thanks,
> Chris

More information about the memcached mailing list