Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I read from a Redis Cluster slave?

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.

like image 638
mayank vats Avatar asked May 28 '16 11:05

mayank vats


Video Answer


2 Answers

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.

like image 69
mp911de Avatar answered Oct 17 '22 12:10

mp911de


none of the Redis clients (in java) like redisson support this

Redisson provides readMode setting available for cluster mode configuration. Available values are:

SLAVE - Read from slave nodes,
MASTER - Read from master node,
MASTER_SLAVE - Read from master and slave nodes

You need to use SLAVE value.

Config example:

Config config = new Config();
config.useClusterServers()
      .setReadMode(ReadMode.SLAVE)
      .addNodeAddress(...);

Redisson redisson = Redisson.create(config);
like image 4
Nikita Koksharov Avatar answered Oct 17 '22 14:10

Nikita Koksharov