首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Astyanax ConnectionPool setMaxConnsPerHost

Astyanax ConnectionPool setMaxConnsPerHost
EN

Stack Overflow用户
提问于 2013-01-30 03:35:49
回答 1查看 685关注 0票数 2

我对配置Astyanax连接池的方式感到困惑。我使用以下命令来配置我的池。

代码语言:javascript
复制
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服务器中有一个配置,允许我们设置最大连接数和每个主机的最大连接数。

服务器配置和此配置是否相关?否则,这个设置到底是什么意思呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-09 00:28:41

在java文档中:

分配给单个主机池的最大连接数

ConnectionPoolConfigurationImpl(conecPoolName)setMaxConnsPerHost配置每台主机可以有多少台主机。

代码语言:javascript
复制
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

池中的最大连接数,并非所有连接池实现都使用

代码语言:javascript
复制
public ConnectionPoolConfigurationImpl setMaxConns(int maxConns) {
    this.maxConns = maxConns;
    return this;
}

应该使用哪一个取决于您的connection pool implementation type

但遗憾的是,setMaxConnsPerHostsetMaxConns似乎都缺乏文档。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14590800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档