Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



rajib76 avatar image
rajib76 asked Erick Ramirez edited

Why is there a difference in elapsed time when I run a query from CQL vs Java Driver?

Java driver gives me a value of 423 millisecond whereas in CQL it takes 3.2millisecond for the same insert query. Why is CQL faster that running through Java

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

I'm assuming you meant "cqlsh" instead of "CQL". If so, it is not an apples-for-apples comparison.

When you run cqlsh on a node, you are directly connected to the cluster and there is no network hop between the client (cqlsh) and the database. When you run queries using your app, you have to account for the fact that there is at least one network hop (possibly more) required to send the query to the cluster.

In addition to the network hop, using cqlsh locally uses the node as the coordinator for the request and by default uses a consistency of ONE unless you override it. When your app sends a request through the driver, the driver must first generate a query plan (a list of nodes to contact and use as a coordinator), connect to a contact point, then send the request.

And if you look under the hood, it gets a bit more complicate because there are things like address resolution required, synchronous vs asynchronous requests, etc. In any case, it's not a fair comparison since running queries locally directly on a node in the cluster will always be faster. Cheers!

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.