RJ/ketama logo

RJ/ketama

Free

C library for consistent hashing, and langauge bindings

FreeFree tier
Type
Open Source

About RJ/ketama

Ketama is a consistent hashing library originally developed to improve memcached client key distribution. It solves the problem of cache invalidation when servers are added or removed from a pool by mapping keys to servers using a hash ring (continuum). This ensures only a small proportion of keys remap when the server list changes. The library includes a core C implementation (libketama) with bindings for PHP, Java, and Python. libketama reads server lists from a file, builds the continuum in shared memory, and automatically reloads when the file is modified. Server weighting is supported by adjusting the number of points each server occupies on the continuum.

Key Features

Consistent hashing algorithm to minimize key remapping when servers change
Core C library (libketama) with shared memory continuum storage
Automatic reloading of server list on file modification
Server weighting via variable number of continuum points
Language bindings for PHP, Java, Python, and Lua
Pure Java implementation (java_ketama) included

Pros & Cons

Pros
  • Minimizes cache misses when adding or removing servers
  • Multi-language support (C, PHP, Java, Python, Lua) for integration flexibility
  • Server weighting allows fine-grained control over load distribution
  • Shared memory implementation provides efficient cross-process access
Cons
  • Project is unmaintained and looking for a new maintainer
  • Documentation is minimal and limited to the README
  • No active development or support channels
  • Limited to simple server-list-based configuration

Best For

Distributed caching with memcachedLoad balancing key-value stores across a server poolAny application needing consistent hashing for server selection

FAQ

What problem does Ketama solve?
It solves the problem of cache invalidation in distributed systems: when servers are added or removed, only a small fraction of keys remap to different servers, preserving most cached data.
How does consistent hashing work in Ketama?
Each server is hashed to multiple points (100-200) on a conceptual circle (0 to 2^32). A key is hashed to a point, and the next highest point on the circle determines the server. If no higher point exists, the first server on the circle is used.
What programming languages are supported?
Ketama includes a core C library and bindings for PHP, Java, Python, and Lua.