1

What can be the maximum preferable size guava cache can use?My system has 8 gb RAM so without degrading the performance of system and other applications how much MB's can i use ? Does Guava cache also use hardDisk storage when RAM storage is not available ?

Louis Wasserman
  • 172,699
  • 23
  • 307
  • 375
agrawal1084
  • 99
  • 2
  • 10

1 Answers1

6

You can only limit the number of entries in the cache. In Guava there is no way to specify the size limit in megabytes. EHCache supports specifying the size limit in megabytes, however, determining the size of a cached entry, is a difficult task and involves some magic, guessing, and, a performance overhead.

Does Guava cache also use hardDisk storage when RAM storage is not available?

No, it is Java heap only. See CachesExplained ยท google/guava Wiki for details.

In practice you start with a reasonable but low cache size, and increase it, while keeping and eye on your heap memory consumption.

Actually the question "How to size a cache?" is not easy to answer, usually there is experience combined with gut feeling involved. To broaden the answer a little and give you more directions:

Prerequisites

  • Make sure you understand the general concepts of the Java heap and garbage collection
  • Know/check the maximum heap size setting of your JVM. See: How is the default java heap size determined?
  • Learn how to monitor and interpret the heap consumption and GC activity, e.g. with VisualVM, see: http://visualvm.java.net/monitor_tab.html
  • Know how to retrieve and interpret statistics from the cache, especially the hit rate
  • Know your data, the estimated size in byte of one entry and the size count of your active data set

Rules of thumb

  • Aim for a hit rate of 90% and more. If it is less, increase the cache size, or, have an idea why the cache is not very effective. Possible causes: Cache misses because of a low expiry time, lots of sequential scans. Sometimes you can improve your application or fiddle with other parameters then the cache size to optimize your hit rate.
  • For a first "best bet" configure your cache size (in entry counts) at least of 10% of your active data set size
Community
  • 1
  • 1
cruftex
  • 5,107
  • 2
  • 15
  • 32
  • I dont have data to analyse just in your pov If my current ram usage is around 50% then can I use 100 mb data in cache ? โ€“ agrawal1084 Dec 29 '15 at 05:46
  • Of course, 100 MB shouldn't be a problem. However, double check the maximum heap size of your JVM. I'll update my answer. โ€“ cruftex Dec 29 '15 at 08:51