levdimov avatar image
levdimov asked levdimov commented

How exactly prepared statements increase performance?

As far as I concerned, prepared statements eliminate the need of constantly parsing and preparing statements on the cassandra's side thus speeding up queries by a few hundred microseconds and decreasing the overall latency. But "A few hundred microseconds" doesn't seem as a thing I would go for to increase cluster performance. Do prepared statements also affect CPU/Memory usage, duration of GC calls or something else and if so then how exactly? Are there any artifacts of load tests that compare prepared and regular statements?

We have a cluster of 6 nodes running Cassandra 3.11.3 executing 30-40K CQL requests per minute at average

Thank you.

cassandraperformanceprepared statement
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 levdimov commented

@levdimov You're correct. The advantage is not having to parse the statements again since it gets cached server-side. Only the binding parameters and the query ID (of the cached statement) gets sent across the wire so the savings can add up substantially over time.

But you will only realise the benefits if the app is repeatedly querying with the same prepared statement over and over. If the statement does not get reused then it ends up being more expensive since there is now the added overhead of caching it without being used again.

As for comparisons, prepared statements can be 10% faster (maybe more) but YMMV based on your use case, data model, access patterns, etc. You will need to perform your own testing to figure out whether it's beneficial for your case. Cheers!

1 comment Share
10 |1000

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

levdimov avatar image levdimov commented ·

Thank you for your answer!

Yes, the app will repeatedly querying the same fixed set of statements so it seems that it will definetely do good.

I was really looking for any possible outcome before my own testing, but it seems that I'm out of luck here :)

1 Like 1 ·