Reputation: 490
Say I have a Cassandra cluster with 3 datacenters, 1 in Beijiing, 1 in Changsha, and 1 in Shenzhen, now I want my client application running in Changsha only talk to C* nodes in Changsha, How do I do? Currently with the following code my client app is talking to all nodes in all datacenters in 3 cities, consequently the overall performance is drawn down by the latency between cities.
import com.datastax.driver.core.{Session, Cluster}
val cluster: Cluster = Cluster.builder().addContactPoints("10.10.11.71")
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
.withReconnectionPolicy(new ConstantReconnectionPolicy(100L))
.withLoadBalancingPolicy(new RoundRobinPolicy)
.build()
val session: Session = cluster.connect()
Upvotes: 0
Views: 302
Reputation: 4061
The problem is in the Load balancing Policy. Round Robin has the behaviour you have described in your question. You should use the DC Aware Round Robin Policy. That will use the nearest data center but all the nodes. It is also possible to use a whitelist of nodes.
Upvotes: 3