GithubHelp home page GithubHelp logo

Comments (4)

karlmcguire avatar karlmcguire commented on April 27, 2024

It sounded to me that if the value calculated by new entries is higher than the lowest entry in a random sample, the new entry gets admitted. Otherwise not.

Correct.

won't the number of discarded items go up over time? Imagine if there are only reads for a minute or 10minutes, the frequency of most items increase and they gain a higher value than any new incoming entries.

TinyLFU prevents this with two "freshness" mechanisms:

  • Counter Resets: every N increments all counters are halved. Because a counter increment occurs for every Read, in your example of only reads for an extended period of time this mechanism would work as fast as possible (compared to a mixed workload).
  • 4-bit Counters: not only are these great for memory usage but due to the small range of values these actually perform better in hit ratio benchmarks due to the opportunities it provides for new items to be admitted (@ben-manes has ran these).

I'm not confident in how the value is calculated, so I apologies if this is way off. Also curious if you have metrics for discarded (new items that was never added) metrics?

No problem, this is a common question, and the freshness mechanisms are a small but important aspect of Ristretto.

We do have metrics for new items that are rejected here.

from ristretto.

karlmcguire avatar karlmcguire commented on April 27, 2024

Here's an example of checking the rejectSets metric:

// create cache with Metrics on
cache, err := NewCache(&Config{
    NumCounters: 1e7,  // 10M
    MaxCost:     1 << 30,  // 1GB
    BufferItems: 64,
    Metrics:     true,
})
if err != nil {
    panic(err)
}

// do your testing
//
//

// get the number of rejected items
rejected := cache.metrics().Get(rejectSets)

Currently we're not publicly exposing the metrics. I don't see a reason not to, so we'll probably add those to the public API.

from ristretto.

ben-manes avatar ben-manes commented on April 27, 2024

Also an admission window can be used to delay the decision, allowing a new entry the chance to build up its frequency. That avoids consecutive misses in recency traces. The amount of space allocated to the window can be dynamically tuned based on the workload.

from ristretto.

karlmcguire avatar karlmcguire commented on April 27, 2024

The concise answer to this question is: freshness mechanisms (addressed above) and windowing (addressed in #46). I'll close this for now.

from ristretto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.