我的应用程序与cassandra的连接不断增加,MaxConnectionsPerHost无法正常工作。我想知道为什么?
这是我的移民。
Builder builder = Cluster.builder();
builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
// JMX 配置
builder.withoutJMXReporting().withoutMetrics();
//DCAwareRoundRobinPolicy dCAwareRoundRobinPolicy = new DCAwareRoundRobinPolicy("DC1", 2);
builder.withLoadBalancingPolicy(new RoundRobinPolicy());
// 添加节点
for (String host : this.agentHosts) {
builder.addContactPoints(host);
}
builder.withPort(this.port);
cluster = builder.build();
PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions();
// 连接池配置
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 20).setCoreConnectionsPerHost(HostDistance.LOCAL, 2).setMaxConnectionsPerHost(HostDistance.REMOTE, 20).setCoreConnectionsPerHost(HostDistance.REMOTE, 2);
// socket 链接配置
SocketOptions socketOptions = cluster.getConfiguration().getSocketOptions();
socketOptions.setKeepAlive(true).setReceiveBufferSize(1024 * 1024).setSendBufferSize(1024 * 1024).setConnectTimeoutMillis(5 * 1000).setReadTimeoutMillis(1000);
//builder.withSocketOptions(socketOptions);
// Query 配置
QueryOptions queryOptions = cluster.getConfiguration().getQueryOptions();
queryOptions.setConsistencyLevel(ConsistencyLevel.ONE);
//builder.withQueryOptions(queryOptions);
logger.info("Connected to cluster: {}\n", cluster.getMetadata().getClusterName());
cassandraSession = cluster.connect(KEY_SPACE);
正如您所看到的,我将MaxConnectionsPerHost设置为20,但与cassandra主机的连接通常超过20。 详细信息是我的应用程序部署在192.168.1.23上,而cassandra主机是192.168.1.12~192.168.1.19,主机192.168.1.12~192.168.1.16是数据中心,192.168.1.17~192.168.1.19是另一个数据中心。 192.168.1.23和cassandra主机之间的连接通常超过20,如100。
答案 0 :(得分:0)
我将我的java驱动程序从cassandra-driver-core-2.0.1.jar更新为cassandra-driver-core-2.1.4.jar,问题解决了。