NonBlockingHashMap unbounded growth
Status: Beta
Brought to you by:
cliffclick
NonBlockingHashMap seems to have unbounded growth when using unique keys, even if the actual set of entries is small.
This gist illustrates the problem: https://gist.github.com/3568485
It simply inserts and removes a monotonically increasing integer. I.e., the working set is at most one object, but the map still grows to use all available heap, at which point it will eventually die with a OutOfMemoryError.
This problem has been observed in the wild in Cassandra, where NonBlockingHashMap is used liberally.
This is another manifestation of the behavior I observed in http://sourceforge.net/tracker/?func=detail&aid=2828100&group_id=194172&atid=948362 and http://sourceforge.net/tracker/?func=detail&aid=2835696&group_id=194172&atid=948362: remove replaces the value with a tombstone, but the (key, tombstone) entry will not be cleared until the map resizes. So if you keep inserting unique keys you will indeed grow the map until it OOMs before the next resize.