Search code examples
scalacassandracassandra-2.0datastax-java-driver

Configuration to optimize cassandra java/scala driver for intensive IO operations?


I can't find any configuration for pooling option on cassandra (using Scala, but I can managed with Java examples). Has anyone ever done it before ?

Edit : I'm using the java driver with scala extra. My goal is to optimise an intensive IO application (DB Read queries).


Solution

  • You need to tune as described in the driver's documentation. Cassandra 2.0 uses protocol V2 that has limit on the amount of the in-flight requests, so you have only possibility to increase a number of connections opened from driver to Cassandra. By default, for protocol V2 it has minimum 2 connections and maximum 2 connections. You can increase it to 4 minimum and 10 maximum with following code:

    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions
        .setConnectionsPerHost(HostDistance.LOCAL,  4, 10)
        .setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
    

    and options should be added when you create Cluster/Session objects:

    Cluster cluster = Cluster.builder()
        .withContactPoints("127.0.0.1")
        .withPoolingOptions(poolingOptions)
        .build();