|
LFU is a much trickier concept than LRU for
caching. Of course, any LFU implementation must really be a hybrid LRU/LFU
algorithm. Otherwise once the cache fills up, nothing else can ever get
inserted!
It seems what is really needed here is an algorithm
that utilizes two metrics, last access, and total accesses,
in determining when to invalidate (remove) an element.
I have a few of recommendations:
- maintain two usage counts, one for the previous
period (hour, day, whatever) and one for the current period. Use the
sum of these to give you a moving hit count
that won't overflow an int.
- maintain a Map on top of your linked list to
provide quick access to cache elements: O(logN) vs O(N) if I remember my
Analysis of Algorithms class correctly.
- maintain your linked list in LRU order, but apply
an additional criteria when invalidating elements. E.g., whenever the
cache fills up remove the 1st 10% of elements whose usage count is below a
threshold. If you don't find enough, raise the threshold and try
again.
- use Doug Lea's data structures to reduce the
locking and lock-contention penalties.
- for testing use a non-uniform random number
generator (like java.util.Random.nextGaussian()) to generate your
keys. This will better similate a typical cache situation where certain
elements are much more likely to get requested.
I may take a crack at this ... it's been a while
since my last attempt at a cache utility.
Keats --- You are currently subscribed to jdjlist as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] http://www.sys-con.com/fusetalk To unsubscribe from all mailing lists, click: http://sys-con.com/[EMAIL PROTECTED] **************************************************************************** This e-mail, and any attachment, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re-transmission, copying, dissemination or other use of this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. The contents of this message may contain personal views which are not the views of Discovery Communications, Inc. (DCI). **************************************************************************** |
Title: RE: [jdjlist] Re: LFUCache problem
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation Greg Nudelman
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation James Stauffer
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation Greg Nudelman
- [EMAIL PROTECTED]
