Connection pool configuration for cassandra

Connection pool configuration for cassandra

The datastax driver of cassandra is implemented using asynchronous nio. The outgoing request will not block the thread and will notify you when there is a response. So you don't need too many connections between cassandra client and server, because sending a request is fast, as long as one thread is constantly listening for the response.

Cassandra is configured like this:

PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 32);
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 2);
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 4);
 
Cluster cluster = Cluster.builder()
.addContactPoints("192.168.1.101")
.withCredentials(username, password)
.withPoolingOptions(poolingOptions);

 This completes a configuration of the connection pool.

setCoreConnectionsPerHost(HostDistance.LOCAL, 2);
indicates that there are at least 2 connections to the machines in the cluster. Note that there are at least 2 connections to each machine in the cluster.
setMaxConnectionsPerHost(HostDistance.LOCAL, 4);
There are up to 4 connections
setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 32);
Each connection allows 32 concurrent requests.

That is to say, your configuration allows up to (32*4*number of machines) concurrent requests. Failure to acquire a connection may occur if there is too much concurrency.

The above is the case where the cluster is deployed in one computer room and there is only one data center DC, if there are multiple data centers. To set the number of REMOTE connections.

PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 32);
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 2);
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 4);
poolingOptions.setCoreConnectionsPerHost(HostDistance.REMOTE, 2);
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 4);

 After the configuration is completed, the session can be obtained and used in a single instance of the whole program.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326844432&siteId=291194637