Cassandra Astyanax连接池setMaxConnsPerHost
我对配置Astyanax连接池的方式感到困惑。 我使用以下配置我的池Cassandra Astyanax连接池setMaxConnsPerHost,cassandra,astyanax,Cassandra,Astyanax,我对配置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 Keysp
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();
}
public final int CONNECTION\u POOL\u SIZE\u PER\u HOST=1;
私有字符串conecPoolName=“xxxx”;
私有字符串ipSeeds=“xxxxx”;
私有字符串clusterName=“xxxxx”;
私有字符串keyspaceName=“xxxxx”;
私有密钥空间密钥空间;
专用连接池配置MPL conPool;
公共DMPastyanExconFPool()抛出DMPEException{
conPool=新连接池配置mpl(conecPoolName).setMaxConnsPerHost(
连接池大小(每个主机)。设置种子(IP种子);
AstyanaxContext context=new AstyanaxContext.Builder().forCluster(clusterName)
.forKeyspace(键空间名称)
.WithAstyAnxConfiguration(新建AstyAnxConfiguration().setDiscoveryType(NodeDiscoveryType.NONE))
.withConnectionPoolConfiguration(conPool)
.withConnectionPoolMonitor(新计数ConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace=context.getEntity();
}
大多数属性都很容易理解,但我不确定setMaxConnsPerHost究竟设置了什么。在我的机器中,我使用一个多线程应用程序来创建几个cassandra连接,即使setMaxConnsPerHost设置为1,它也可以正常工作。另外,我知道cassandra服务器中有一个配置,允许我们设置每个主机的最大连接数和最大连接数
服务器配置与此配置相关吗?否则,此设置的确切含义是什么?来自java文档:
要为单个主机池分配的最大连接数
连接池配置mpl(conecPoolName)
。配置每个主机可以拥有的主机数
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;
}
还有一种方法用于设置池中允许的最大连接数:
池中的最大连接数,并非所有连接池实现都使用
应该使用哪一种取决于您的个人喜好
但遗憾的是,这两个项目似乎都缺乏文档
public ConnectionPoolConfigurationImpl setMaxConns(int maxConns) {
this.maxConns = maxConns;
return this;
}