I have to insert thousands of rows into cassandra db table with spring data. What is the best way to make it fast. Any suggestion?
0
votes
1 Answers
1
votes
The fastest way to do is to use AsyncCqlTemplate to perform asynchronous operations instead of "standard" synchronous ones (here is full example).
AsyncCassandraTemplate asyncTemplate = new AsyncCassandraTemplate(session);
ListenableFuture<Klass> future = asyncTemplate.insert(klass_instance);
But you need to make sure that you don't overload connections - you need to have some kind of counting semaphore that will issue not more than X queries at the time. You may also need to tune connection pooling parameters - for example, bump number of in-flight requests to higher number than standard 1024...
P.S. Don't try to use batches! Until you have in the batch only data for same partition, you'll make the inserts slower, not faster.