C library for consistent hashing, and langauge bindings
C library for consistent hashing, and langauge bindings
LOOKING FOR NEW MAINTAINER
I'm not running this anywhere at the moment, and don't have time to work on it. I understand libketama and various ports/clients are in production in various places. If anyone is working on this and feels like maintaining, I will give you push/commit access. find me: [email protected] or twitter.com/metabrew or RJ2 on freenode
We wrote ketama to replace how our memcached clients mapped keys to servers. Previously, clients mapped keys->servers like this:
server = serverlist[hash(key)%serverlist.length];This meant that whenever we added or removed servers from the pool, everything hashed to different servers, which effectively wiped the entire cache.
Ketama solves this problem in the following way:
If you then add or remove a server from the list, only a small proportion of keys end up mapping to different servers.
The server file looks like this: 1.2.3.4:11211 900 5.6.7.8:11211 300 9.8.7.6:11211 1500
ip:port and weighting, \t separated, \n line endings. Just use the number of megs allocated to the server as the weight. The weightings are realised by adding more or less points to the continuum.
Included in this tarball: * libketama * php_ketama * java_ketama * python_ketama
libketama is a general purpose C library that maps keys to a list of servers. The server list is read from a file, and the continuum is created and stored in shared memory for future access. If the file modification time changes, the continuum is regenerated and shared memory is updated.
php_ketama is a PHP extenstion that wraps libketama. We use this in our PHP memcached client library.
java_ketama implements the same logic in pure Java, and has been fitted into our Java memcached client library.
python_ketama is a python module (with libketama dependencies) contributed by [email protected].
$ cd libketama $ make $ make test $ su -c "make install"
This will compile libketama and install it to the default prefix /usr/local. You can change the prefix by editing the PREFIX variable in 'Makefile'.
$ cd php-4.4.x/ext $ ln -s /your/ketama/php_ketama ketama $ cd .. $ rm -Rf autom4te.cache $ ./buildconf --force $ ./configure --all_your_configure_options --with-ketama[=/your/ketama/prefix] $ make $ su -c "make install"
$ cd python_ketama $ python setup.py build $ sudo python setup.py install $ python tests.py
Use the NIF written at rd.io: https://github.com/abs/ketama/tree/rdio/erlang
Don't forget you might have to restart your httpd!
No open issues yet, or sync has not completed.