Performance comparison between ConcurrentMap and LoadingCache

191 views
Skip to first unread message

Boyuan Zhang

unread,
Feb 17, 2021, 7:26:28 PMFeb 17
to guava-discuss
Hi team,

I recently changed my application from using ConcurrentMap to LoadingCache to perform certain caching functionality and I noticed a runtime performance drop(roughly from 35 mins to 31 mins). I want to understand what exactly causes this performance improvement. So I'm reaching out to the group to see whether there is a performance comparison already between ConcurrentMap and LoadingCache.

Thanks for your help!

Benjamin Manes

unread,
Feb 17, 2021, 8:16:34 PMFeb 17
to Boyuan Zhang, guava-discuss
This depends on what your workload is doing. Guava's cache is built on top of Java 5's ConcurrentHashMap with a default concurrency level of 4. This setting is because that hash table is segmented into multiple smaller tables, so more segments allows for higher concurrency at a cost of a larger memory footprint. A setting of 64 is more appropriate for performance sensitive scenarios.

Java 8 rewrote the hash table implementation for a 2x speedup and no longer relies on coarse segmentation. To leverage this required a complete rewrite of Guava's cache, which was done in Caffeine. Given the ability to start from scratch and build on everything we learned in Guava, there are many other performance improvements that were planned but not realized in Guava's implementation. This rewrite has about 33% of the read throughput of an unbounded ConcurrentHashMap and can obtain a higher hit rate than Guava's LRU.

The last time that I performed an in-depth benchmark was in 2015, but I do not believe any changes have been dramatic enough to invalidate these results.

In short, first try increasing the concurrencyLevel and, if not satisfactory, then switch to Caffeine.

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/de9b6286-506d-447e-92a4-b10747eda5e4n%40googlegroups.com.

Boyuan Zhang

unread,
Feb 17, 2021, 8:43:04 PMFeb 17
to Benjamin Manes, guava-discuss
Thanks! That's really helpful!
Reply all
Reply to author
Forward
0 new messages