#cache #pingora #policy #algorithm #eviction #high #tiny-lfu

TinyUFO

In-memory cache implementation with TinyLFU as the admission policy and S3-FIFO as the eviction policy

5 releases (3 breaking)

new 0.4.0 Nov 1, 2024
0.3.0 Jul 12, 2024
0.2.0 May 10, 2024
0.1.1 Apr 18, 2024
0.1.0 Feb 27, 2024

#66 in Caching

Download history 170/week @ 2024-07-17 184/week @ 2024-07-24 175/week @ 2024-07-31 181/week @ 2024-08-07 197/week @ 2024-08-14 126/week @ 2024-08-21 154/week @ 2024-08-28 137/week @ 2024-09-04 168/week @ 2024-09-11 170/week @ 2024-09-18 179/week @ 2024-09-25 51/week @ 2024-10-02 109/week @ 2024-10-09 143/week @ 2024-10-16 91/week @ 2024-10-23 192/week @ 2024-10-30

977 downloads per month
Used in 4 crates

Apache-2.0

45KB
865 lines

TinyUFO

TinyUFO is a fast and efficient in-memory cache. It adopts the state-of-the-art S3-FIFO as well as TinyLFU algorithms to achieve high throughput and high hit ratio as the same time.

Usage

See docs

Performance Comparison

We compare TinyUFO with lru, the most commonly used cache algorithm and moka, another great cache library that implements TinyLFU.

Hit Ratio

The table below show the cache hit ratio of the compared algorithm under different size of cache, zipf=1.

cache size / total assets TinyUFO TinyUFO - LRU TinyUFO - moka (TinyLFU)
0.5% 45.26% +14.21pp -0.33pp
1% 52.35% +13.19pp +1.69pp
5% 68.89% +10.14pp +1.91pp
10% 75.98% +8.39pp +1.59pp
25% 85.34% +5.39pp +0.95pp

Both TinyUFO and moka greatly improves hit ratio from lru. TinyUFO is the one better in this workload. This paper contains more thorough cache performance evaluations S3-FIFO, which TinyUFO varies from, against many caching algorithms under a variety of workloads.

Speed

The table below shows the number of operations performed per second for each cache library. The tests are performed using 8 threads on a x64 Linux desktop.

Setup TinyUFO LRU moka
Pure read 148.7 million ops 7.0 million ops 14.1 million ops
Mixed read/write 80.9 million ops 6.8 million ops 16.6 million ops

Because of TinyUFO's lock-free design, it greatly outperforms the others.

Memory overhead

TinyUFO provides a compact mode to trade raw read speed for more memory efficiency. Whether the saving worthy the trade off depends on the actual size and the work load. For small in-memory assets, the saved memory means more things can be cached.

The table below show the memory allocation (in bytes) of the compared cache library under certain workloads to store zero-sized assets.

cache size TinyUFO TinyUFO compact LRU moka
100 39,409 19,000 9,408 354,376
1000 236,053 86,352 128,512 535,888
10000 2,290,635 766,024 1,075,648 2,489,088

Dependencies

~2–7MB
~41K SLoC