正确处理大量异步查询

时间:2018-04-06 04:38:52

标签: java cassandra

我必须更新Cassandra表中的数千条记录并使用executeAsync(BoundStatement)方法,但我收到错误Pool is busy (no available connection and the queue has reached its max size 256),请参阅下面的详细信息。$

正确处理此类执行的最佳方法是什么?如何增加Cassandra查询队列大小和队列中的等待时间?

Exception in thread "Thread-6" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: cassandra2/172.18.0.17:9042 (com.datastax.driver.core.exceptions.BusyPoolException: [cassandra2/172.18.0.17] Pool is busy (no available connection and the queue has reached its max size 256)), cassandra4/172.18.0.18:9042 (com.datastax.driver.core.exceptions.BusyPoolException: [cassandra4/172.18.0.18] Pool is busy (no available connection and the queue has reached its max size 256)), cassandra1/172.18.0.11:9042 (com.datastax.driver.core.exceptions.BusyPoolException: [cassandra1/172.18.0.11] Pool is busy (no available connection and the queue has reached its max size 256)))
at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:75)
at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:28)
at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:28)
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:236)

我使用具有3个节点的群集,QUORUM一致性和复制因子3。

2 个答案:

答案 0 :(得分:2)

有两种选择:

  1. 调整connection pool以实现群集的最高性能
  2. 限制异步查询的数量以避免NoHostAvailableException。例如。如described here

答案 1 :(得分:2)

你可以增加你的队列,但这真的只是解决问题。您可能只想重试任何此类请求,但使用信号量可能符合您的最佳利益,并且一次只允许一定数量的请求进入,而不是一次排队所有插入。

如果排序很重要,你也可以使用这样的机制

Spark Cassandra Connector slidingIteartor用于控制许多人的执行 异步请求