bigjocker's den

Cassandra Murmur3Partitioner token calculator

Cassandra recently replaced the default partitioner from the old RandomPartitioner to the much faster Murmur3Partitioner. The RandomPartitioner implementation uses MD5 hashes for the tokens, whereas Murmur3Partitioner uses, you guessed it, Murmur3. I was recently looking for a simple Javascript utility to generate the tokens for a Murmur3 based cluster, but could not find any. So here’s a small one.

There’s quite a lot of token generators for the RandomPartitioner implementation which uses the slowest MD5 hashing algorithm, but I haven’t seen any that covers the Murmur3 range. The process for token generation is simple: Cassandra partitions your data based on a hash value for the primary key of the column family; each node will store a range of hashes, so your data will be randomly distributed across your cluster. The Murmur3 algorithm will generate a hash that will range from -263 to 263-1. Assigning an uniform range to each node guarantees that your data will be evenly distributed and that your cluster will not have hot spots. A faster hashing algorithm means finding the corresponding node for a row faster, and Murmur3 is way faster than MD5.

Here’s a simple token generator for the Murmur3Partitioner:

Number of nodes:

Please note one thing: I’m using the Biginteger.js library to manipulate big integers, and it seems to have some rounding issues. It rounds (floors?) the last 3 digits down to 0 for some reason. This should only be an issue if you are creating a cluster with more than a few trillion nodes.

1 comment for “Cassandra Murmur3Partitioner token calculator

  1. justme
    August 23, 2013 at 12:12 pm

    It doesn’t work, i used -9223372036854775808 and it worked, your node 0 value is too low.

Leave a Reply

Your email address will not be published. Required fields are marked *