Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimal settings for Cassandra Java driver to write to the local data centre only

I have recently started using Datastax Java driver for our Cassandra use case... We will be using Datastax Java driver for reading/writing into Cassandra...

I am successfully able to create Cassandra connection using Datastax Java driver... But I am wondering, are there any other settings which I should be using in Production environment to get the better performance using Datastax Java driver while making the connection to Cassandra?

/**
 * Creating Cassandra connection using Datastax driver
 *
 */
private DatastaxConnection() {

    try{
        builder = Cluster.builder();
        builder.addContactPoint("some-node");

        // Can anybody explain me what does below piece of code do?

        builder.poolingOptions().setCoreConnectionsPerHost(
                HostDistance.LOCAL,
                builder.poolingOptions().getMaxConnectionsPerHost(HostDistance.LOCAL));

        // And also what does below piece of code is doing?       
        cluster = builder
                .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
                .withReconnectionPolicy(new ConstantReconnectionPolicy(100L))
                .build();

        StringBuilder s = new StringBuilder();
        Set<Host> allHosts = cluster.getMetadata().getAllHosts();
        for (Host h : allHosts) {
            s.append("[");
            s.append(h.getDatacenter());
            s.append("-");
            s.append(h.getRack());
            s.append("-");
            s.append(h.getAddress());
            s.append("]");
        }
        System.out.println("Cassandra Cluster: " + s.toString());

        session = cluster.connect("testdatastaxks");
    } catch (NoHostAvailableException e) {

    } catch (Exception e) {

    }
}

My top priorities are :-

  • Filter out the Cassandra nodes basis on local datacenter.. So in the connection pool it will only have local datacenter Cassandra nodes.
  • And get the best performance while using Datastax java driver with some certain settings.

I know it might be possible that certain settings will differ in different environment but there might be some settings that everybody has to follow to get the optimal performance while making the Cassandra connections using Datastax Java driver..

Like for an example in Astyanax when I was using earlier, it was that you need to use TOKEN_AWARE...

So there should be some best settings as well or recommended while using Datastax java driver?

like image 441
AKIWEB Avatar asked Oct 26 '13 08:10

AKIWEB


1 Answers

Filter out the Cassandra nodes basis on local datacenter.. So in the connection pool it will only have local datacenter Cassandra nodes

Then you need to use the DCAwareRoundRobinPolicy.

Like for an example in Astyanax when I was using earlier, it was that you need to use TOKEN_AWARE...

That is true for the DataStax Java driver too, it's called TokenAwarePolicy and can be use on top of the DCAwareRoundRobinPolicy cited above.

I know it might be possible that certain settings will differ in different environment but there might be some settings that everybody has to follow to get the optimal performance while making the Cassandra connections using Datastax Java driver..

I can't speak for "everybody" but outside of the proper choice of load balancing policies as described above, the rest will be most likely environment dependent. But of course if you care a lot about performance, it's a good idea to play with various settings from Configuration and some realistic workload and see if something helps.

like image 79
pcmanus Avatar answered Sep 21 '22 14:09

pcmanus