Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Configuration

elandau edited this page · 10 revisions
Clone this wiki locally

Coming soon…

Connection Pool

Token Aware

The following example shows how to set up the token aware connection pool. The first example sets up a basic token aware pool which will round robin all hosts within a token range.

AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster("ClusterName")
    .forKeyspace("KeyspaceName")
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
        .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    )
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(3)
        .setSeeds("127.0.0.1:9160")
     )
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

context.start();
Keyspace keyspace = context.getEntity();

This example shows how to set up token aware with latency aware using a simple moving average to sort and score hosts within a partition. (Note, SmaLatencyScoreStrategyImpl will be redone soon to not depend on the config object) You will likely want to experiment with these values for your specific use case. Depending on the type of operations you perform there may be huge variance in the latency so you may want to increase the latency aware window size to smooth out the averages.

ConnectionPoolConfigurationImpl poolConfig = new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(1)
        .setSeeds("127.0.0.1:9160")
        .setLatencyAwareUpdateInterval(10000)  // Will resort hosts per token partition every 10 seconds
        .setLatencyAwareResetInterval(10000) // Will clear the latency every 10 seconds
        .setLatencyAwareBadnessThreshold(0.50) // Will sort hosts if a host is more than 100% slower than the best and always assign connections to the fastest host, otherwise will use round robin
        .setLatencyAwareWindowSize(100) // Uses last 100 latency samples
;
poolConfig.setLatencyScoreStrategy(new SmaLatencyScoreStrategyImpl(poolConfig)); // Enabled SMA.  Omit this to use round robin with a token range

AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster("ClusterName")
    .forKeyspace("KeyspaceName")
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
        .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    )
    .withConnectionPoolConfiguration(poolConfig)
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

context.start();
Keyspace keyspace = context.getEntity();
Something went wrong with that request. Please try again.