我对配置Astyanax连接池的方式感到困惑。我使用以下命令来配置我的池。
public final int CONNECTION_POOL_SIZE_PER_HOST = 1;
private String conecPoolName = "xxxx";
private String ipSeeds = "xxxxx";
private String clusterName = "xxxxx";
private String keyspaceName = "xxxxx";
private Keyspace keyspace;
private ConnectionPoolConfigurationImpl conPool;
public DMPAstyanaxConfPool() throws DMPException {
conPool = new ConnectionPoolConfigurationImpl(conecPoolName).setMaxConnsPerHost(
CONNECTION_POOL_SIZE_PER_HOST).setSeeds(ipSeeds);
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder().forCluster(clusterName)
.forKeyspace(keyspaceName)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE))
.withConnectionPoolConfiguration(conPool)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getEntity();
}大多数属性都很容易理解,但我不确定setMaxConnsPerHost到底设置了什么。在我的机器中,我使用了一个多线程应用程序,它创建了几个cassandra连接,即使setMaxConnsPerHost设置为1,它也工作得很好。此外,我知道cassandra服务器中有一个配置,允许我们设置最大连接数和每个主机的最大连接数。
服务器配置和此配置是否相关?否则,这个设置到底是什么意思呢?
发布于 2013-03-09 00:28:41
在java文档中:
分配给单个主机池的最大连接数
ConnectionPoolConfigurationImpl(conecPoolName)。setMaxConnsPerHost配置每台主机可以有多少台主机。
public ConnectionPoolConfigurationImpl setMaxConnsPerHost(int maxConns) {
Preconditions.checkArgument(maxConns > 0, "maxConnsPerHost must be >0");
//this relates to connections per each node.
this.maxConnsPerPartition = maxConns;
return this;
}还有一个用于设置池中允许的最大连接数的setMaxConns:
池中的最大连接数,并非所有连接池实现都使用
public ConnectionPoolConfigurationImpl setMaxConns(int maxConns) {
this.maxConns = maxConns;
return this;
}应该使用哪一个取决于您的connection pool implementation type。
但遗憾的是,setMaxConnsPerHost和setMaxConns似乎都缺乏文档。
https://stackoverflow.com/questions/14590800
复制相似问题