[ 
https://issues.apache.org/jira/browse/KAFKA-8020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16790171#comment-16790171
 ] 

Richard Yu commented on KAFKA-8020:
-----------------------------------

Hi [~mjsax]

Well, elements which have been inserted usually have a certain lifetime right? 
So we want to take advantage of that. While elements in a cache are within 
their useful lifespan, they might potentially be queried. Some entries might be 
queried more than others, but once an entry's lifespan expires. It is of no 
use. Lets consider an example, what could potentially happen is that an entry 
is queried right before its lifespan expires. This moves it to the front of the 
LRU Cache, yet its useful lifespan has been exceeded shortly after. This 
basically means that we could have a bunch of dead entries which is of no use 
at the head of the queue. We will have to wait for these dead entries to cycle 
back to the tail before they are evicted. In contrast, time-aware LRU Caches 
are used so that we can eliminate this problem. Entries, no matter their 
location in the queue, will be evicted efficiently should their lifespan expire 
(hence why we need to use hiearchal time wheels, they are the most efficient of 
keeping track of when an element has run out of time). 

In terms of a KIP, I don't think that it requires ones. There shouldn't be any 
changes to public API, and we are offering a performance enhancement, so a 
configuration which chooses between different caching policies shouldn't be 
necessary. 

> Consider changing design of ThreadCache 
> ----------------------------------------
>
>                 Key: KAFKA-8020
>                 URL: https://issues.apache.org/jira/browse/KAFKA-8020
>             Project: Kafka
>          Issue Type: Improvement
>          Components: streams
>            Reporter: Richard Yu
>            Priority: Major
>
> In distributed systems, time-aware LRU Caches offers a superior eviction 
> policy better than traditional LRU models, having more cache hits than 
> misses. In this new policy, if an item is stored beyond its useful lifespan, 
> then it is removed. For example, in {{CachingWindowStore}}, a window usually 
> is of limited size. After it expires, it would no longer be queried for, but 
> it potentially could stay in the ThreadCache for an unnecessary amount of 
> time if it is not evicted (i.e. the number of entries being inserted is few). 
> For better allocation of memory, it would be better if we implement a 
> time-aware LRU Cache which takes into account the lifespan of an entry and 
> removes it once it has expired.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to