Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size Aware Eviction: First-In-First-Out, or evicting largest items first? #424

Open
rpivo opened this issue May 23, 2024 · 2 comments
Open
Assignees
Labels
question Further information is requested

Comments

@rpivo
Copy link

rpivo commented May 23, 2024

This issue is not really a problem with Moka, but more an ask for clarification in the documentation.

Does the size aware eviction evict items on a first-in-first-out basis, or does it evict the largest items in the cache first?

(I am going to try to test this out, and If I can identify the answer, I will make a pull request.

@tatsuya6502
Copy link
Member

Does the size aware eviction evict items on a first-in-first-out basis, or does it evict the largest items in the cache first?

It evicts least recently used (LRU) item. Item sizes do not affect the eviction order.

It uses a slightly modified version of "Aggregated Victims (AV)" algorithm. AV was introduced by this paper:

and here are the details of the modifications in moka:

https://github.com/moka-rs/moka/blob/v0.12.7/src/future/base_cache.rs#L1913-L1929

    /// Performs size-aware admission explained in the paper:
    /// [Lightweight Robust Size Aware Cache Management][size-aware-cache-paper]
    /// by Gil Einziger, Ohad Eytan, Roy Friedman, Ben Manes.
    ///
    /// [size-aware-cache-paper]: https://arxiv.org/abs/2105.08770
    ///
    /// There are some modifications in this implementation:
    /// - To admit to the main space, candidate's frequency must be higher than
    ///   the aggregated frequencies of the potential victims. (In the paper,
    ///   `>=` operator is used rather than `>`)  The `>` operator will do a better
    ///   job to prevent the main space from polluting.
    /// - When a candidate is rejected, the potential victims will stay at the LRU
    ///   position of the probation access-order queue. (In the paper, they will be
    ///   promoted (to the MRU position?) to force the eviction policy to select a
    ///   different set of victims for the next candidate). We may implement the
    ///   paper's behavior later?

(I am going to try to test this out, and If I can identify the answer, I will make a pull request.

That would be great. Thanks!

FYI, currently, the doc only mentions the followings:

https://docs.rs/moka/latest/moka/sync/struct.Cache.html#example-size-based-eviction

Note that weighted sizes are not used when making eviction selections.

@rpivo
Copy link
Author

rpivo commented May 23, 2024

@tatsuya6502 thank you for this amazing answer! I will read the paper you linked to as well and follow up.

@tatsuya6502 tatsuya6502 added the question Further information is requested label May 23, 2024
@tatsuya6502 tatsuya6502 self-assigned this May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants