• Stars
    star
    825
  • Rank 55,281 (Top 2 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created over 15 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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


About Ketama
============

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:

 * Take your list of servers (eg: 1.2.3.4:11211, 5.6.7.8:11211, 9.8.7.6:11211)
 * Hash each server string to several (100-200) unsigned ints
 * Conceptually, these numbers are placed on a circle called the continuum.
   (imagine a clock face that goes from 0 to 2^32)
 * Each number links to the server it was hashed from, so servers appear
   at several points on the continuum, by each of the numbers they hashed to.
 * To map a key->server, hash your key to a single unsigned int, and find the
   next biggest number on the continuum. The server linked to that number is
   the correct server for that key.
 * If you hash your key to a value near 2^32 and there are no points on the
   continuum greater than your hash, return the first server in the continuum.

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.


Implementation
==============

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].

Installation
============

* libketama (the general purpose C library)

$ 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'.

* php_ketama (PHP extension that wraps libketama and therefore depends on it)

$ 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"

* python_ketama (python module that depends on libketama)

$ cd python_ketama
$ python setup.py build
$ sudo python setup.py install
$ python tests.py

* erlang

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!

More Repositories

1

irccat

IRC bot that simplifies posting to IRC from shell scripts
Java
276
star
2

playdar-core

Playdar - a content resolver for music
PHP
192
star
3

erlang-spdy

Library implementing the SPDY protocol
Erlang
104
star
4

relflow

Version-incrementing, appup-generating, relx-coaxing, workflow-assistant for Erlang projects using rebar3.
Erlang
92
star
5

estatsd

Erlang stats aggregation app that periodically flushes data to graphite
Erlang
88
star
6

playdar

Abandoned C++ codebase, see playdar-core repo!
C
49
star
7

heatmiser-neohub.py

Python library to talk the direct-lan-api to control a Heatmiser Neohub / Neostats - and home-assistant component
Python
31
star
8

erlang_rebar_example_project

Basic project using rebar, to demonstrate upgrades and packaging etc
Erlang
24
star
9

erlang-reup

Watches for .erl & .hrl changes, recompiles and reloads. You know, for development.
Erlang
24
star
10

erlang-cassandra-cql

cassandra driver in erlang that speaks native cassandra protocol
Erlang
22
star
11

mochiweb-websockets

***OBSOLETE, using my mochiweb repo now ***
Erlang
20
star
12

libf2f

Library for building p2p networks, C++ boost/asio
C++
16
star
13

libportfwd

Set up port fwds and find external IP: C++/CMake wrapper for miniupnpc and nat-pmp libs
C
14
star
14

greynet

A darknet/mesh network plugin for legacy C++ playdar codebase
C++
11
star
15

doorbird-mdns-vlan-subnet-bridge

Allow ios/android apps to discover and direct connect to doorbirds in a different subnet
Python
8
star
16

gocat

IRCCat in Go
Go
7
star
17

musickit

Qt+Webkit container app that exposes phonon/etc APIs to js
JavaScript
6
star
18

logtail

tail -f logfiles in a browser using websockets (erlang)
Erlang
6
star
19

sonos-shipping-forecast

Play the Shipping Forecast from BBC Radio 4, then return Sonos to original state.
Python
6
star
20

libmemcached

temporary repo for patching libmemcached
Shell
6
star
21

dotvim

my .vim
Vim Script
5
star
22

www.playdar.org

Playdar website
JavaScript
5
star
23

bevy_timewarp

A rollback library that buffers component state. Useful for netcode.
Rust
5
star
24

captainhook

Batch set github service hooks for all repos in an org
Python
4
star
25

vagrant-chef-basebox

Basic vagrant+chef setup
Ruby
4
star
26

estr-erlang-elixir-binary-string

Adaptor for using Elixir's UTF8 binary string module in Erlang
Erlang
3
star
27

bevy_naia_laminar

bevy plugin for laminar atop naia-socket
Rust
2
star
28

appupper

deprecated, see relflow:
Erlang
2
star
29

relsandbox

Release sandbox app (various changes, with appups)
Erlang
2
star
30

irccat-cookbook

chef cookbook for irccat
HTML
2
star
31

dot-janus

My .janus dir, containing vim config and plugins in addition to janus vim distro
Vim Script
2
star
32

erlang-countess

rebar3 release playground for blog post
Erlang
1
star
33

qdaapd

An embeddable C++/Qt DAAP server library
C
1
star
34

conjist

music network thing
C
1
star
35

radioblink

WIP - Circuit which takes the audio output of a PMR radio and blinks LEDs when it receives a signal
C
1
star
36

sharesight-custom-investment-price-updater

updates vg small cap price to sharesight
Rust
1
star