Hi,
I'm use local cache using Ristretto to reduce the latency of data retrieval. I'm retriving around 60000 cache keys per second at peak traffic. I tried searching but not able to find a multi get solution for retriving data so I'm looping over the number of cache keys and doing Get() to retrieve data from local cache.
Sharing some comparison calculation for latency:
Local cache:
Avg latency: 0.00994 ms
Cache keys in a request 1000
Total latency in one request: 9.94 ms
Redis Mget:
Avg latency: 2.18 ms
Cache keys in a request 1000
Reducing cache keys per request can help in reducing this but due to goroutines throttling added in system I can only take this upto 500 cache keys per request.
Code reference:
type RedisPair struct {
Key string
Value interface{}
found bool
}
func (l *localCache) MGet(ctx context.Context, pairs ...*RedisPair) bool {
if len(pairs) == 0 {
return true
}
allFound := true
for _, pair := range pairs {
found := l.Get(ctx, pair.Key, pair.Value)
pair.found = found
allFound = allFound && found
}
return allFound
}
func (l *localCache) Get(ctx context.Context, key string, obj interface{}) bool {
val, found := l.Cache.Get(key)
if found {
err := l.unmarshal(val, obj)
if err != nil {
return false
}
return found
}
return false
}
How can I optimise my code so I don't have to loop for Get() operations?
Question.
Hi, I'm use local cache using Ristretto to reduce the latency of data retrieval. I'm retriving around 60000 cache keys per second at peak traffic. I tried searching but not able to find a multi get solution for retriving data so I'm looping over the number of cache keys and doing Get() to retrieve data from local cache. Sharing some comparison calculation for latency:
Local cache: Avg latency: 0.00994 ms Cache keys in a request 1000 Total latency in one request: 9.94 ms
Redis Mget: Avg latency: 2.18 ms Cache keys in a request 1000
Reducing cache keys per request can help in reducing this but due to goroutines throttling added in system I can only take this upto 500 cache keys per request.
Code reference:
How can I optimise my code so I don't have to loop for Get() operations?