Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn if writes are stalled due to blocked eviction (fixes #672)
Eviction occcurs under an exclusive lock which is typically held for very short periods to update the policy and possibly remove a victim entry. Writes are applied to the hash table and the policy updated are buffered, allowing the writer threads to schedule their work, tryLock to update the policy, and move on if busy. If the writer buffer then becomes full then to avoid a memory leak the writers must block to assist, creating back pressure if the write rate exceeds the eviction rate. The eviction's removal of the victim from the hash table may cause unexpected blocking. A map computation performs its work under the same lock guarding the entry, which allows for atomicity of that operation and requiring that other writes to the entry wait until it completes. Typically this is quick, as caches are ready-heavy and the victim entry is unlikely to be computed on. However, since the locking in ConcurrentHashMap is based on the hash bin, not the entry, a hash collision can cause writes to different keys to delay each other. A slow, long-running computation then blocks eviction even though the entries differ. When this happens then the writer buffer fills up and other writes are blocked, causing no more write activity until the eviction is allowed to proceed again. That scenario goes against the advice of this library and the JavaDoc in ConcurrentHashMap, which encourages short and fast computations. That is milliseconds to seconds in practice, not minutes or hours. Instead we offer AsyncCache to decouple the computation from the map, which sacrafices linearizability for more efficient processing. Of course few users will be aware of these implementation details to make that decision early enough. Sadly some will find out only when they observe production problems. To assist we now include a log warning in hopes that it helps highlight it earlier, helps debugging, and hints towards the required fix.
- Loading branch information
Showing
11 changed files
with
136 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.