我使用的是java驱动程序版本:2.1.4
卡桑德拉版: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个同时连接?
答案 0 :(得分:0)
使用ProtocolVersion#V3或更高版本,每个连接最多有32768个请求,并且池默认为固定大小1.您通常会通过允许每个连接多个同时请求来提高最大容量( setMaxRequestsPerConnection < / strong>(HostDistance,int))