Reputation: 101
I have set up a cassandra cluster with only two nodes on two servers with identical hardware configuration in the same internal network recently. It works well with cqlsh, everything seems perfect. Then I followed the code example in datastax's website to write java code to work with the cluster and problems comes. The program works, it connects to the cluster and successfully writes to and reads data from it. However, the connection is way too slow! I deployed the code in the same machine where one of the cluster node resides and it takes over 5 seconds to connect. More precisely, it's the line session = cluster.connect() takes most of the time.
I tried to setup another cassandra cluster with only one node in the same network, with similar hardware configuration. It takes around 1 second to connect. So i think it's likely i missed some configurations when writing the code. I spend quite some time searching for answer but could not get any. Given the 5 seconds connection time, it very hard for me to consider to use it as a replacement for my current database.
In addition, the ping time among these machines are within 1ms, so i don't think it's the network's problem. using cqlsh to connect to cluster is very fast too.
The cassandra version is 2.1.4 and the maven dependency for datastax is
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.4</version>
</dependency>
So i wonder if anyone could enlighten me on why it's takes so long to connect to the cluster with only two nodes. Thank you very much.
Here is the code to connect to cassandra cluster , basically it's the same as shown in its website.
long start = System.currentTimeMillis();
cluster = Cluster.builder().addContactPoint(node1).addContactPoint(node2).build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n",metadata.getClusterName());
System.out.println(metadata.getPartitioner());
session = cluster.connect();
long time = System.currentTimeMillis() - start;
System.out.println("time to connect : " + time);
Upvotes: 3
Views: 2182
Reputation: 101
I believe i found the reason why it's so slow. It's simply because i set rpc_address
to 0.0.0.0
in [cassandra]/conf/cassandra.yaml
. Once i set it to the actually IP address, the connection time dropped from 5 seconds to 0.2 second.
is it because rpc address affects node discovery time significantly ?
Upvotes: 2