Class ClockProPlusEviction
- java.lang.Object
-
- org.cache2k.core.eviction.AbstractEviction
-
- org.cache2k.core.eviction.ClockProPlusEviction
-
- All Implemented Interfaces:
NeedsClose,Eviction
public class ClockProPlusEviction extends AbstractEviction
Eviction algorithm inspired from CLOCK Pro with 3 clocks.Uses a static allocation for hot and cold space sizes. No online or dynamic optimization is done yet. However, the hit rate for all measured access traces is better than LRU and resistant to scans.
From cache2k version 1.2 to version 1.4 the implementation was simplified and the demotion of hot entries removed. The result achieves similar or better hit rates. Version 2.4 limits the ghost size to 3000 elements. Version 2.6 stops inserting evicted hot entries into ghosts.
The Clock-Pro algorithm is explained by the authors in CLOCK-Pro: An Effective Improvement of the CLOCK Replacement and Clock-Pro: An Effective Replacement in OS Kernel.
- Author:
- Jens Wilke
-
-
Field Summary
-
Fields inherited from class org.cache2k.core.eviction.AbstractEviction
heapCache, idleNonEvictDrainCount, idleScanRound, lock, MAXIMAL_CHUNK_SIZE, maxSize, maxWeight, MINIMAL_CHUNK_SIZE, MINIMUM_CAPACITY_FOR_CHUNKING
-
-
Constructor Summary
Constructors Constructor Description ClockProPlusEviction(HeapCacheForEviction heapCache, InternalEvictionListener listener, long maxSize, org.cache2k.operation.Weigher weigher, long maxWeight, boolean noChunking)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckIntegrity(IntegrityState integrityState)protected EntryfindEvictionCandidate()Runs cold hand and in turn hot hand to find eviction candidate.protected EntryfindIdleCandidate(int maxScan)Find idle candidate.protected EntryfindIdleInHot(int maxScan)longgetGhostMax()longgetHotMax()protected longgetScanCount()longgetSize()protected voidinsertIntoReplacementList(Entry e)Place the entry as a new entry into the eviction data structures.protected longremoveAllFromReplacementList()Remove entries from the replacement list without locking the entry itself.protected voidremoveFromReplacementList(Entry e)Remove, expire or eviction of an entry happens.voidremoveFromReplacementListOnEvict(Entry e)Track the entry on the ghost list and call the usual remove procedure.StringtoString()protected voidupdateHotMax()Updates hot max based on current size.-
Methods inherited from class org.cache2k.core.eviction.AbstractEviction
changeCapacity, close, evictEventually, evictEventuallyBeforeInsert, evictEventuallyBeforeInsertOnSegment, evictIdleEntries, getMetrics, isWeigherPresent, removeAll, runLocked, startNewIdleScanRound, submitWithoutTriggeringEviction, updateAccumulatedWeightInLock, updateTotalWeightForRemove, updateWeight
-
-
-
-
Constructor Detail
-
ClockProPlusEviction
public ClockProPlusEviction(HeapCacheForEviction heapCache, InternalEvictionListener listener, long maxSize, org.cache2k.operation.Weigher weigher, long maxWeight, boolean noChunking)
-
-
Method Detail
-
getHotMax
public long getHotMax()
-
getGhostMax
public long getGhostMax()
-
updateHotMax
protected void updateHotMax()
Updates hot max based on current size. This is called when eviction kicks in so current size is the maximum size this cache should reach regardless whether we use entry capacity or weigher to limit the size.- Specified by:
updateHotMaxin classAbstractEviction
-
removeAllFromReplacementList
protected long removeAllFromReplacementList()
Description copied from class:AbstractEvictionRemove entries from the replacement list without locking the entry itself.- Specified by:
removeAllFromReplacementListin classAbstractEviction
-
removeFromReplacementListOnEvict
public void removeFromReplacementListOnEvict(Entry e)
Track the entry on the ghost list and call the usual remove procedure.- Specified by:
removeFromReplacementListOnEvictin classAbstractEviction
-
removeFromReplacementList
protected void removeFromReplacementList(Entry e)
Remove, expire or eviction of an entry happens. Remove the entry from the replacement list data structure.Why don't generate ghosts here? If the entry is removed because of a programmatic remove or expiry we should not occupy any resources. Removing and expiry may also take place when no eviction is needed at all, which happens when the cache size did not hit the maximum yet. Producing ghosts would add additional overhead, when it is not needed.
- Specified by:
removeFromReplacementListin classAbstractEviction
-
getSize
public long getSize()
- Specified by:
getSizein classAbstractEviction
-
insertIntoReplacementList
protected void insertIntoReplacementList(Entry e)
Description copied from class:AbstractEvictionPlace the entry as a new entry into the eviction data structures.- Specified by:
insertIntoReplacementListin classAbstractEviction
-
findIdleCandidate
protected Entry findIdleCandidate(int maxScan)
Find idle candidate. Idle scanning does scan on the bigger clock first, which is typically the hot clock, because entries are sitting in the cache for the longest time.- Specified by:
findIdleCandidatein classAbstractEviction
-
findIdleInHot
protected Entry findIdleInHot(int maxScan)
-
findEvictionCandidate
protected Entry findEvictionCandidate()
Runs cold hand and in turn hot hand to find eviction candidate.- Specified by:
findEvictionCandidatein classAbstractEviction
-
getScanCount
protected long getScanCount()
- Specified by:
getScanCountin classAbstractEviction
-
checkIntegrity
public void checkIntegrity(IntegrityState integrityState)
-
toString
public String toString()
- Overrides:
toStringin classAbstractEviction
-
-