eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.4k stars 193 forks source link

should I turn on metric switch within high concurrency application? #238

Open lypro09539 opened 6 months ago

lypro09539 commented 6 months ago

I import this outstanding lib into my app to use its /store/ristretto/v4, and there will be about 80000 QPS concurrency in our production, so should I use cache.NewMetric to enable metric?

Because I find each Get() will generator a observe operation, on the other hand the codec channel buffer length which is 10000 maybe also cause goroutines suspend, is that right? I finaly plan to lower metric sampling rate through code below, I wonder there is better way to reach it or not?

thank you

        ristrettoStoreShelfTidy = ristretto_store.NewRistretto(ristrettoCache)
    promMetrics := metrics.NewPrometheus("shelf_tidy_cache", metrics.WithNamespace("local"))

    ristrettoStoreShelfTidyWithMetric = cache.NewMetric[any](
        promMetrics,
        cache.New[any](ristrettoStoreShelfTidy),
    )

    // ***** some lines skipped

    if rand.Intn(100) < 1 { // only one out of a hundred it will use metric instance to lower sampling rate
        ristrettoStoreShelfTidyWithMetric.Get(ctx, key)
    } else {
        ristrettoStoreShelfTidy.Get(ctx, key)
    }

image