I use Cassandra java driver
.
I receive 150k requests per second, which I insert to 8 tables having different partition keys.
My question is which is a better way:
I am asking this question because , considering my request size (150k), batch sounds like the better option but because all the tables have different partition keys, batch appears expensive.
In Cassandra BATCH is used to execute multiple modification statements (insert, update, delete) simultaneously. It is very useful when you have to update some column as well as delete some of the existing.
Single partition batches should be used when atomicity and isolation is required. Even if you only need atomicity (and no isolation) you should model your data so that you can use single partition instead of multi partition batches.
In Cassandra, batch allows the client to group related updates into a single statement. If some of the replicas for the batch fail mid-operation, the coordinator will hint those rows automatically.
There is a batch insert operation in Cassandra. You can batch together inserts, even in different column families, to make insertion more efficient. In Hector, you can use HFactory. createMutator then use the add methods on the returned Mutator to add operations to your batch.
Please check my answer from below link:
Cassandra batch query performance on tables having different partition keys
Batches are not for improving performance. They are used for ensuring atomicity and isolation.
Batching can be effective for single partition write operations. But batches are often mistakenly used in an attempt to optimize performance. Depending on the batch operation, the performance may actually worsen.
https://docs.datastax.com/en/cql/3.3/cql/cql_using/useBatch.html
If data consistency is not needed among those tables, then use single insert. Single requests are distributed or propagated properly (depends on load balancing policy) among nodes. If you are concerned about request handling and use batch, batches will burden so many extra works on coordinator nodes which will not be efficient I guess :)
Batches have a HUGE impact on performance instead. The sollution that best suits you as I understand to split into diffirent lists per partition keys and then use batch statements. You will see a huge impact on performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With