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

[QUESTION]: Is it possible to get experinece similar to redis MGET #315

Open
dakait opened this issue Nov 10, 2022 · 0 comments
Open

[QUESTION]: Is it possible to get experinece similar to redis MGET #315

dakait opened this issue Nov 10, 2022 · 0 comments
Labels
kind/question Something requiring a response.

Comments

@dakait
Copy link

dakait commented Nov 10, 2022

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:

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?

@dakait dakait added the kind/question Something requiring a response. label Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Something requiring a response.
Projects
None yet
Development

No branches or pull requests

1 participant