DataStax Help Center

What does "prepared statements discarded in the last minute because cache limit reached" mean?

Summary

The application is adding more Statements to the cache than can be stored.

Symptoms

The logs contain many warnings similar to:

INFO [ScheduledTasks:1] 2017-01-26 12:30:32,554 QueryProcessor.java:139 - 1532 prepared statements discarded in the last minute because cache limit reached (28648824 bytes)

Cause

Cassandra has a cache that stores a parsed version of the cql statement that have been prepared.  Using this cached version allows future uses of the statement to skip the parsing stage and thus speeds up the application performance.  

This process is described in more detail here:

http://docs.datastax.com/en/developer/java-driver/3.1/manual/statements/prepared/

The message is logged because either there are too many prepared statements, or the statements being cached are too large.

Solution

Review the application logic to see how queries are prepared.  By default Cassandra should be able to cache many thousands of statements - it is very rare that an application would actually need that many individual statements.

A common scenario is where the application mistakenly adds a text string to the cache - rather than using place holders and then binding the specific variables that are needed.

So for example if the following statements are prepared:

select * from table where col1 = "1" and col2 = "1" and col3 = "1" ;
select * from table where col1 = "2" and col2 = "2" and col3 = "2" ;
select * from table where col1 = "3" and col2 = "3" and col3 = "3" ;

Cassandra will store 3 separate statements. Whereas:

select * from table where col1 = ? and col2 = ? and col3 = ? ;

With bound values for each of the 3 queries in turn would create only one entry in the cache.

It can be useful to add debugging code to the application similar too:

PreparedStatement statement = getPreparedStatement(queryString);
...
logdebug("readAsync() : Execute : query string {}, bindParams:{}", queryString, params.toString());

Bear in mind that this is likely to generate a large number of entries.

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk