配置以优化cassandra java / scala驱动程序以进行大量IO操作?

时间:2018-11-29 18:48:47

标签: scala cassandra cassandra-2.0

我在cassandra上找不到任何用于池化选项的配置(使用Scala,但可以使用Java示例进行管理)。有没有人做过?

编辑:我正在使用j ava driver with scala extra。我的目标是优化密集型IO应用程序(数据库读取查询)。

2 个答案:

答案 0 :(得分:1)

您需要按照driver's documentation中的说明进行调整。 Cassandra 2.0使用协议V2,该协议对进行中的请求数量有限制,因此,您只能增加从驱动程序到Cassandra的打开连接数。默认情况下,for protocol V2 it has最少2个连接,最多2个连接。您可以使用以下代码将其增加到最少4个和最多10个:

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

和创建群集/会话对象时应添加选项:

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

答案 1 :(得分:-1)

由于您处于JVM环境中,因此只能通过Scala加载有效的Java配置。