dgraph-io / ristretto

A high performance memory-bound Go cache
https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/
Apache License 2.0
5.54k stars 364 forks source link

[QUESTION]: Too high missed rate? #346

Closed maxim-ge closed 1 month ago

maxim-ge commented 1 year ago

Question.

I have a test:

func TestRistretto_Get(t *testing.T) {
    require := require.New(t)

    const CacheSize = 10_000

    m, err := ristretto.NewCache(&ristretto.Config{
        NumCounters: CacheSize / 10, // number of keys to track frequency
        MaxCost:     CacheSize,      // maximum cost of cache
        BufferItems: 64,             // number of keys per Get buffer.
    })
    require.NoError(err)

    numFound := 0
    numMissed := 0

    for i := 0; i < CacheSize; i++ {
        k := fmt.Sprint(i)
        for {
            r := m.Set(k, i+1, 1)
            m.Wait()
            if r {
                break
            }
        }
        _, ok := m.Get(k)
        if !ok {
            numMissed++
        } else {
            numFound++
        }
    }
    fmt.Println("numOk:", numFound, "numMissed:", numMissed)
    require.NotNil(t)
}

It prints numOk: 3494 numMissed: 6506. Is it ok that so many keys are missed?

github-actions[bot] commented 2 months ago

This issue has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.