Cassandra Java驱动程序的最佳设置只能写入本地数据中心

我最近开始为我们的Cassandra用例使用Datastax Java驱动程序…我们将使用Datastax Java驱动程序读取/写入Cassandra …

我成功地可以使用Datastax Java驱动程序创建Cassandra连接…但是我想知道,在生产环境中是否还有其他设置可以使用Datastax Java驱动程序在连接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) {

    }
}

我的首要任务是:

>根据本地数据中心过滤掉Cassandra节点.因此,在连接池中,只有本地数据中心Cassandra节点.
>在使用Datastax java驱动程序时,可以获得最佳的性能,并具有一定的设置.

我知道某些设置可能会在不同的环境中有所不同,但是在使用Datastax Java驱动程序进行Cassandra连接时,可能需要遵循一些设置来获得最佳性能.

就像在Astyanax早期使用的一个例子,那就是你需要使用TOKEN_AWARE …

所以应该有一些最好的设置,或者推荐使用Datastax java驱动程序?

解决方法

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

那么你需要使用DCAwareRoundRobinPolicy.

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

对于DataStax Java驱动程序也是如此,它被称为TokenAwarePolicy,可以在上面引用的DCAwareRoundRobinPolicy之上使用.

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..

我不能说“每个人”,但是除了上述负载平衡策略的适当选择之外,其余的将最有可能是环境依赖的.但是,当然如果你关心性能,那么从Configuration和一些现实的工作负载播放各种设置是一个好主意,看看有没有帮助.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...