jcarreira / cirrus-kv

High-performance key-value store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement CacheManager eviction policy

jcarreira opened this issue · comments

Ideally, we would like to provide the ability for the developer to provide its own eviction policy.

This might not be the way to go (at least for now) because:

  1. hard to abstract away internals of the cache from the eviction policy
  2. eviction policy if not tightly implemented with the cache becomes inefficient

References:
Redis eviction policies: https://redis.io/topics/lru-cache

One possible approach is to create a base class cirrus::EvictionPolicy that can be derived by specific eviction policies.

This cirrus::EvictionPolicy declares a method

std::vector<ObjID> evictObjects(uint64_t nObjects)

that can be called by the store whenever a put occurs that exceeds the available capacity to compute a list of objects to be evicted.

The class also declares all the other public methods of the store. Whenever a store method is called (e.g., get, put, remove), the corresponding eviction policy method is also called (Hollywood principle).

Pros:

  1. Design allows custom application policies on top of some out of the box policies we can provide (e.g., LRU)
  2. The eviction policy has enough information about the contents of the cache. Whenever a store method is called the eviction policy is informed.

Cons:

  1. We incur at least an extra function call for every store call. Perhaps not as efficient as a tightly integrated policy in the cache
  2. Eviction policy execution can be arbitrarily slow and slow down the store execution because it is on the critical path of the store methods. The developer needs to be careful with policy implementation.
  3. There is possibly an extra cost in space due to the fact that most eviction policies could just piggyback on the cache hashtable to store their metadata.