`

cassandra的连接池配置

 
阅读更多

cassandra的连接池配置(转)

首先 client 端驱动https://github.com/datastax/java-driver

cassandra的datastax驱动使用的是异步nio实现的,发出去的请求,不会阻塞线程,当有响应的时候会通知你。所以cassandra客户端和服务器之间不需要太多的连接,因为发送一个请求是很快的,只要一个线程不断监听响应就可以了。

cassandra的配置方式如下:

1
2
3
4
5
6
7
8
9
10
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 32);
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 2);
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 10);
 
Cluster cluster = Cluster.builder()
.addContactPoints("192.168.1.89")
.withPoolingOptions(poolingOptions);

Session sessionInstance = cluster.connect(); //全局使用都可以

这就完成了一个对连接池的配置。
setCoreConnectionsPerHost(HostDistance.LOCAL, 2);
表示和集群里的机器至少有2个连接

setMaxConnectionsPerHost(HostDistance.LOCAL, 10);
最多有10个连接
setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 32);
每个连接允许32请求并发

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics