user3123372
user3123372

Reputation: 744

Redis cluster/ load balancing

Redis doesnt support master master replication.

In the redis tutorial I can see that there is a configuration , with 6 nodes, 3 master, 3 slaves,

Can any one tell me what is the aim of this configuration(slaves are for fail-over , what is the purpose of 3 master ?)

My requirement is to reduce number of connection made from the app server to Redis . so I was looking for a way where I can point to multiple redis nodes , so if I create a key from redis node 1, I can delete that key from Redis node 2.

Is it possible?

Upvotes: 0

Views: 3291

Answers (1)

e7lT2P
e7lT2P

Reputation: 1921

First of all you can change the default configuration if you do little work in

redis-trib.rb

in function def check_create_parameters. You can set one master and one slave replica.

The purpose for this configuration is for fault tolerance. The slaves also can be used for read (READONLY). In the three masters, the hashslots equally distributed and with a load balancing algorithm you can re-distribute and the actual keys. The steps of a possible algorithm that distirbutes the keys among the nodes are (tested by me and it works as expected):

  1. Find the crowd of masters
  2. Obtain the total number of keys they hold
  3. For each master node store the hostname, port and number of keys
  4. Calculate the keys that each master must hold so that the distribution of keys to be balanced (total keys of cluster / number of masters)
  5. Find which master nodes must take or give keys and the total amount of keys that they must give/take
  6. Characterize masters as source or target nodes depending on whether they are receiving or giving away keys respectively
  7. Start migrating from source node to target nodes, first the hashslots and then the relevant keys and iterate until all the masters have the same amount of keys

This algorithm will help to minimize the response time. What i mean:

With three masters the response time can be minimized. If you have a configuration with one master and this master holds for example 30000 #keys, the response time to get 1000keys at once is > from a configuration with 2 masters that holds 15000 each.

If you create a key in master1, then if you try to reach(read) that key from master2 you will get a MOVED error. So, the solution is to create a smart client that maps the hashslots to the corresponding node. Thus, you can delete the key from master2 only in the case that master2 redirects your request to the correct master.

Hope that helps.

Upvotes: 1

Related Questions