所有TCP连接b / w DataStax驱动程序到Cassandra Remain处于Active关闭状态。即TIME_WAIT州。

时间:2014-07-22 12:37:45

标签: cassandra datastax-java-driver

设置:

网络服务器 Apache Tomcat
RestFull网络服务
使用DataStax java驱动程序2.0

数据库 -2节点Cassandra 2.0.7.31簇
-replicas = 1

问题

发送1500次请求后发送三次以上。我在tomcat日志中遇到错误

     com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.181.13.239 ([/10.181.13.239] Unexpected exception triggered))
                at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:64)
                at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:214)
                at com.datastax.driver.core.ResultSetFuture.getUninterruptibly(ResultSetFuture.java:169)
                at com.jpmc.es.rtm.storage.impl.EventExtract.main(EventExtract.java:36)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
    Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.181.13.239 ([/10.181.13.239] Unexpected exception triggered))
                at com.datastax.driver.core.RequestHandler.sendRequest(RequestHandler.java:98)
                at com.datastax.driver.core.RequestHandler$1.run(RequestHandler.java:165)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

观察 经过这种状态的tomcat。所有进一步的要求获得同样的命运。那是驱动程序无法将我的插入请求发送到cassandra。

执行net stat命令后,我发现所有TCP连接黑白Web服务器和Cassandra都处于TIMED_WAIT状态。

可能是什么原因?为什么Datastax驱动程序无法将连接恢复回池?或者为什么Cassandra正在与客户建立联系。

提前致谢

1 个答案:

答案 0 :(得分:0)

连接增加由于调用为每个请求创建多个会话。现在它工作正常。

         builder = new Cluster.Builder().
                addContactPoints("192.168.114.42");

        builder.withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(
                HostDistance.LOCAL, new PoolingOptions().getMaxConnectionsPerHost(HostDistance.LOCAL)));

        cluster = builder
                .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
                .withReconnectionPolicy(new ConstantReconnectionPolicy(100L))
                .build();
        session = cluster.connect("demodb");

现在,无论交易次数如何,Driver都保持17-26的连接数。