简体   繁体   English

Spring数据/ Cassandra批量插入

[英]Spring data/cassandra batch insertion

I have to insert thousands of rows into cassandra db table with spring data. 我必须将数以千计的行插入带有弹簧数据的cassandra db表中。 What is the best way to make it fast. 最快的最好方法是什么。 Any suggestion? 有什么建议吗?

The fastest way to do is to use AsyncCqlTemplate to perform asynchronous operations instead of "standard" synchronous ones (here is full example ). 最快的方法是使用AsyncCqlTemplate来执行异步操作,而不是“标准”同步操作(此处是完整的示例 )。

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. 但是,您需要确保您不会使连接超载-您需要某种计数信号量,该信号量在当时只会发出X个查询。 You may also need to tune connection pooling parameters - for example, bump number of in-flight requests to higher number than standard 1024... 您可能还需要调整连接池参数 -例如,将进行中的请求的突发数量提高到比标准1024更高的数量...

PS Don't try to use batches! PS不要尝试使用批处理! Until you have in the batch only data for same partition, you'll make the inserts slower, not faster. 在批处理中只有相同分区的数据之前,您将使插入速度变慢,而不是更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM