Add Redis::Distributed#mget #673
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
When a distributed Redis receives
mget, find the nodes the keys should bestored on and issue
mgetcommands to each sub-node with only their matching keys.Then combine the results and return them in an order that matches the key
list.
Why
My team is sharding the cache in a Rails application that uses Redis as cache storage.
The setup relies on:
It works quite well.
However, we also use
record-cache. That works too because it only uses the high level interface of the generic ActiveSupport cache. Unfortunately, it seems to be optimized to read records in batches, here:https://github.com/orslumen/record-cache/blob/9bf4285c0a086f831b4b6e1d3fc292fbe44a14d6/lib/record_cache/multi_read.rb#L35-L43
The
redis-activesupportcache adapter implementation ofread_multirelies onmget, which currently raises an exception inRedis::Distributed.This causes the cache queries to degenerate from a high number of
mgetto a very large number of singlegetcommands.The result is that we've observed a significant increase of both commands per second and CPU usage, which is what we actually wanted to reduce.