【问题标题】:Astyanax ConnectionPool setMaxConnsPerHostAstyanax ConnectionPool setMaxConnsPerHost
【发布时间】:2016-05-11 03:04:00
【问题描述】:

我对配置 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 服务器中有一个配置允许我们设置最大连接数和最大值每个主机的连接数。

服务器配置和这个配置有关系吗?否则,这个设置究竟是什么意思?

【问题讨论】:

    标签: cassandra astyanax


    【解决方案1】:

    来自 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

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

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 1970-01-01
      • 2012-06-22
      • 2013-02-08
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 2013-11-28
      • 2019-11-30
      相关资源
      最近更新 更多