加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 05:27:22 所属栏目:Java 来源:网络整理
导读:我最近开始为我们的Cassandra用例使用Datastax Java驱动程序…我们将使用Datastax Java驱动程序读取/写入Cassandra … 我成功地可以使用Datastax Java驱动程序创建Cassandra连接…但是我想知道,在生产环境中是否还有其他设置可以使用Datastax 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和一些现实的工作负载播放各种设置是一个好主意,看看有没有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读