Question to Cache::Memcached

Brad Fitzpatrick brad@danga.com
Mon, 7 Jun 2004 12:09:18 -0700 (PDT)


> How does the module decide which backend to give it too (if no weight value is
> specified)?

It runs the key through a hashing function, then mods that number with the
number of buckets (number of servers * each's weight) and uses the result
as the bucket number.

So if you have two servers:

10.0.0.1 weight 1   ->  1 bucket  (bucket 0)
10.0.0.2 weight 3   ->  3 buckets (bucket 1, 2, 3)

Total:                  4 buckets

So now we have key "foobar".  HashValue("foobar") = 238423432423434.

Taking the hash value, mod 4 (4 buckets)...

 238423432423434 % 4 = 2 (bucket 2)

So it uses 10.0.0.2

> Is there a restriction on how the keys may look?

No spaces or newlines.

> My keys are similar to this (without quotes):
>
> "010/dating/profilansicht/profilAnsicht.xmlindex=page1userid=2170797"

That looks fine.

So the mystery is:  what hash values is it calculating for your keys?
It'd be way too weird if they were all 0.