java - Cassandra java驱动程序协议(protocol)版本和连接限制不匹配

标签 java cassandra cql cassandra-2.0 cassandra-2.1

我使用的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

我是协议(protocol)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/

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

最佳答案

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

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

关于java - Cassandra java驱动程序协议(protocol)版本和连接限制不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47024198/

相关文章:

java - 每次都将数据新鲜写入文件

database - 选择 * 与选择 Cassandra 中的特定列

java - InvalidTypeException : Invalid type for value 1 of CQL type text, 需要类 java.lang.String 但类 [Ljava.lang.Object;假如

idisposable - NDepend CQL 查询缺少 IDisposable 实现

database-performance - 了解 nodetool cfstats 中的 "Number of keys"

cassandra - Cassandra CQL 中的 Where 和 Order By 条款

java - 多对多额外列 eclipselink 不起作用

java - 如何在ant中复用依赖的项目?

scala - Spark cassandra 连接器在独立 Spark 集群中不起作用

java - 如何应对以下代码中的 java.lang.NumberFormatException?