Should I read from a Redis Cluster slave?

mayank vats picture mayank vats · May 28, 2016 · Viewed 9.2k times · Source

We have a cluster configuration for Redis used as cache. Now due to the normal pattern of write to master and read from slave (with other databases), we are trying to do the same thing with Redis cluster.
After some investigation we found that none of the Redis clients (in java) like redisson, jedis and Spring Data Redis support this. We seem to have found some workaround for it but it seems ugly and now I am thinking if it is worth it?

Here is my use case

  • Approx highest QPS: 1000
  • Payload size: huge 1 MB max (after compression)
  • Cluster size 3 master each with 2 slaves(pretty high spec machines)
  • Cringe part: the actual network bandwidth to this cluster is Max 1GB (1 GB separately for intra-cluster talk)

With that in mind I have following questions:

  • Will it (reading from slave) help me in any way?
  • Are there any pit holes I should avoid (any special server side config)?
  • Is the narrow path going to be a problem?
  • Is there a standard way (library/client) for doing this correctly

Any help (blogs, case study, suggestions) is greatly appreciated.

Answer

mp911de picture mp911de · May 29, 2016

What is your expectation from slave reads?

It's possible and a usual pattern to read from slaves but it comes with a set of effects.

  1. Slave reads introduce stale data reads
  2. Reading from more than one source allows controlling the read source. This is useful when dealing with availability issues (e.g. the master is down so you can go for slave reads maintaining your availability) or latency issues (e.g. using the node with the lowest latency for reads)
  3. You can use slave reads to distribute the server load. While this is possible, Redis requires an excessive load to see some effect

Quoting from http://redis.io/topics/cluster-spec#scaling-reads-using-slave-nodes:

Normally slave nodes will redirect clients to the authoritative master for the hash slot involved in a given command, however, clients can use slaves in order to scale reads using the READONLY command.

READONLY tells a Redis Cluster slave node that the client is ok reading possibly stale data and is not interested in running write queries.

Jedis has no built-in support to read from other nodes than the master node. Redisson and lettuce provide built-in support for Master and Slave reads. Redisson uses internally a balancer (random, round-robin, weighted) to distribute operations, lettuce provides a preference-driven (Master only, Master preferred, slave, nearest) approach.

Spring Data Redis is built on top of Jedis and lettuce but does not provide a generic feature to read from slaves.

A good rule of thumb is using slaves for availability, not for performance.