【问题标题】:Cassandra java driver protocol version and connection limits don't matchCassandra java驱动协议版本和连接限制不匹配
【发布时间】:2018-04-11 23:03:38
【问题描述】:

我使用的是java驱动版本:2.1.4
Cassandra 版本:dsc-cassandra-2.1.10
cql 的输出如下

cqlsh 5.0.1 | Cassandra 2.1.10 | CQL spec 3.2.1 | Native protocol v3

我是协议 V3。但是当我尝试将其设置为每个连接超过 128 个请求时,它会引发异常。这似乎是 V2 中的一个限制。解释如下:

以下代码块:

PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 8);

Cluster cluster = Cluster.builder()
                         .addContactPoints(x.x.x.x)
                         .withPoolingOptions(poolingOptions)
                         .withProtocolVersion(ProtocolVersion.V3)
                         .build();

System.out.println("Protocol version = "+myCurrentVersion);
System.out.println("LOCAL CORE = "+poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL));
System.out.println("LOCAL MAX = "+poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL));
System.out.println("Max sim requests = "+poolingOptions.getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL));
System.out.println("Max sim requests per host = "+poolingOptions.getMaxSimultaneousRequestsPerHostThreshold(HostDistance.LOCAL));

 poolingOptions
.setMaxSimultaneousRequestsPerHostThreshold(HostDistance.LOCAL, 3000);

 poolingOptions
.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 128);         

System.out.println("LOCAL CORE = "+poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL));
System.out.println("LOCAL MAX = "+poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL));
System.out.println("Max sim requests = "+poolingOptions.getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL));
System.out.println("Max sim requests per host = "+poolingOptions.getMaxSimultaneousRequestsPerHostThreshold(HostDistance.LOCAL));

输出是:

Protocol version = V3
LOCAL CORE = 1
LOCAL MAX = 8
Max sim requests = 100
Max sim requests per host = 1024
Exception in thread "main" java.lang.IllegalArgumentException: Max simultaneous requests per connection for LOCAL hosts must be in the range (0, 128)
    at com.datastax.driver.core.PoolingOptions.checkRequestsPerConnectionRange(PoolingOptions.java:370)
    at com.datastax.driver.core.PoolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(PoolingOptions.java:175)
    at ca.txio.pricehistoryservice.main.ConnectionOptionTest.main(ConnectionOptionTest.java:38)

根据 Cassandra 文档 https://docs.datastax.com/en/developer/java-driver/2.1/manual/native_protocol/http://docs.datastax.com/en/developer/java-driver/2.1/manual/pooling/

我是协议 V3。但是为什么我限制每个连接 128 个请求。这似乎是 V2 中的一个限制。有人可以解释一下如何找到我的实际版本,如果确实是 V3,为什么我不能同时拥有超过 128 个连接?

【问题讨论】:

    标签: java cassandra cql cassandra-2.0 cassandra-2.1


    【解决方案1】:

    使用 ProtocolVersion#V3 或更高版本,每个连接最多有 32768 个请求,并且池默认为固定大小 1。您通常会通过允许每个连接更多同时请求来提高最大容量(setMaxRequestsPerConnection(HostDistance, int))

    参考:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setMaxRequestsPerConnection-com.datastax.driver.core.HostDistance-int-

    【讨论】:

    • 是的,我试过了。当我尝试将其设置为 128 以上时,请查看代码和我得到的异常。Java 驱动程序也只有一个 setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 128)。不是 setMaxRequestsPerConnection
    • 请将您的驱动程序版本升级到 2.1.7。参考:docs.datastax.com/en/developer/java-driver/2.1/upgrade_guide PoolingOptions 中的以下属性已重命名: MaxSimultaneousRequestsPerConnectionThreshold 到 NewConnectionThreshold MaxSimultaneousRequestsPerHostThreshold 到 MaxRequestsPerConnection 旧的 getter/setter 已被弃用,但它们委托给新的 getter/setter。另外,请注意,协议 v3 的连接池现在可以配置为使用多个连接。有关详细信息,请参阅此页面。
    猜你喜欢
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2015-12-08
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多