![](/img/trans.png)
[英]setMaxConns and setMaxConnsPerHost in Astyanax client
[英]Astyanax ConnectionPool setMaxConnsPerHost
我對配置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服務器中有一個配置,允許我們設置最大連接數和最大連接數。每個主機的連接數。
服務器配置與此配置相關嗎? 否則,此設置的確切含義是什么?
從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;
}
應該使用哪一種取決於您的連接池實現類型 。
但是可惜的是setMaxConnsPerHost和setMaxConns似乎都缺少文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.