Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra load balancing with an ordered partitioner?

Tags:

cassandra

So I see here that Cassandra does not have automatic load balancing, which comes into view when using the ordered partitioner (a certain common range of values of a group of rows would be stored on a relatively few machines which would then serve most of the queries).
What's The Best Practice In Designing A Cassandra Data Model?

I'm still new to Cassandra and how it works. how would one go about avoiding this issue, so that range queries are still possible? I didn't really get the above answers (linked url) idea about appending a hash to keys.

like image 562
deepblue Avatar asked Nov 20 '09 01:11

deepblue


People also ask

What is the role of partitioner in Cassandra?

A partitioner determines how data is distributed across the nodes in the cluster (including replicas). Basically, a partitioner is a function for deriving a token representing a row from its partition key, typically by hashing. Each row of data is then distributed across the cluster by the value of the token.

What is the salient feature of the murmur3 hashing algorithm used by the Cassandra partitioner subsystem?

The Murmur3Partitioner uses the MurmurHash function. This hashing function creates a 64-bit hash value of the partition key. The possible range of hash values is from -2 63 to +2 63-1. When using the Murmur3Partitioner , you can page through all rows using the token function in a CQL query.

What is the default partitioner in the Apache Cassandra cluster?

The Murmur3Partitioner is the default partitioning strategy for new Cassandra clusters and the right choice for new clusters in almost all cases.

How is data partitioned in Cassandra?

As we learned earlier, Cassandra uses a consistent hashing technique to generate the hash value of the partition key (app_name) and assign the row data to a partition range inside a node.


2 Answers

As mentioned on the other post, Cassandra 0.5 supports semiautomatic load balancing, where all you have to do is tell a node to loadbalance and it will move to a busier place on the token ring automatically.

This is covered in http://wiki.apache.org/cassandra/Operations

like image 194
jbellis Avatar answered Sep 19 '22 12:09

jbellis


I think this issue is best taken up on the cassandra-user mailing list; that is where people are.

Cassandra does not have automatic load balancing yet but it may do so in the not-too-distant future. The 0.5 branch may be capable of this now.

Essentially when you bootstrap a node on an already-running system, it should find a spot in the ring which will load balance best and put itself there. Provided you add nodes one at a time (i.e. wait for one node to finish bootstrapping before adding another), that should work pretty well, provided your key distribution doesn't change too much over time.

However, your keys may change over time (especially if they are time-based) so you might want a workaround.

It depends on what you want to range-scan. If you only need to range scan PART of the key, you could hash the bit that you don't want to range scan, and use that as the first part of the key.

I'll use the term "partition" here to refer to the part of the key you don't want to range scan

function makeWholeKey(partition, key) {
   return concat(make_hash(partition), partition, key);
}

Now if you want to range scan the keys within a given partition, you can range scan between makeWholeKey(p,start) and makeWholeKey(p,end)

But if you want to scan the partitions, you're out of luck.

But you can make your nodes have tokens which are evenly distributed around the range of make_hash() output, and you'll get evenly distributed data (assuming you have ENOUGH partitions that it doesn't all clump up on one or two hash values)

like image 37
MarkR Avatar answered Sep 22 '22 12:09

MarkR