I am confused with the way of configuring Astyanax connection pool. I use the following to configure my pool.
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();
}
Most properties are easy to understand, but I am not sure what exactly setMaxConnsPerHost sets. In my machine, I use a multithread application that creates several cassandra connections and it works fine, even if setMaxConnsPerHost is set to 1. Also, I know there is a config in cassandra server that allow us to set the maximum number of connections and maximum number of connections per host.
Are the server config and this config related? Otherwise, what exactly is the meaning of this setting?
From the java docs:
Maximum number of connections to allocate for a single host's pool
ConnectionPoolConfigurationImpl(conecPoolName)
.setMaxConnsPerHost configures how many hosts you can have per host.
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;
}
There is also setMaxConns for setting the maximum allowed connections in the pool:
Maximum number of connections in the pool, not used by all connection pool implementations
public ConnectionPoolConfigurationImpl setMaxConns(int maxConns) {
this.maxConns = maxConns;
return this;
}
Which one should be used depends on your connection pool implementation type.
But sadly both setMaxConnsPerHost and setMaxConns seem to be lacking documentation.