【发布时间】:2020-09-09 18:25:58
【问题描述】:
对于我的论文,我需要将数据从文件上传到 Cassandra 集群。 session.execute() 太慢了。所以我决定使用 session.executeAsyn()。但它会导致 BusyConnectionException。
这是我的 Java 代码:
final PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, 32768)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 32768);
final Cluster cluster = Cluster.builder()
.withPoolingOptions(poolingOptions)
.addContactPoint("x.x.x.x")
.withPort(9042)
.build();
final Session session = cluster.connect();
System.out.println("session object---" + session.getState());
final String path = "&PathToFile%";
final File dir = new File(path);
session.execute("use products;");
for (final File file : dir.listFiles()) {
final BufferedReader br = new BufferedReader(new FileReader(file));
String str;
final String insert = br.readLine();
while ((str = br.readLine()) != null) {
final String query = insert + str.substring(0, str.length() - 1) + "IF NOT EXISTS ;";
session.executeAsync(query);
}
}
session.close();
cluster.close();
}
以下是我在执行代码时遇到的异常:
查询 /x.x.x.1:9042 时出错:com.datastax.driver.core.exceptions.BusyPoolException: [/x.x.x.1] 池忙(没有可用连接,队列已达到最大大小 256) 查询 /x.x.x.2:9042 时出错:com.datastax.driver.core.exceptions.BusyPoolException: [/x.x.x.2] 池忙(没有可用连接,队列已达到最大大小 256) 查询 /x.x.x.3:9042 时出错:com.datastax.driver.core.exceptions.BusyPoolException: [/x.x.x.3] 池忙(没有可用连接,队列已达到其最大大小 256) 查询 /x.x.x.4:9042 时出错:com.datastax.driver.core.exceptions.BusyPoolException: [/x.x.x.4] 池忙(没有可用的连接,队列已达到其最大大小 256) 查询 /x.x.x.5:9042 时出错:com.datastax.driver.core.exceptions.BusyPoolException: [/x.x.x.5] 池忙(没有可用的连接,队列已达到其最大大小 256)
【问题讨论】:
-
本系统 CLI 上的
ulimit -a返回什么?还要检查this
标签: java cassandra connection-pooling datastax-java-driver