Redis cluster/ load balancing

后端 未结 1 1731
庸人自扰
庸人自扰 2021-01-26 13:11

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 tel

1条回答
  •  无人共我
    2021-01-26 14:07

    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.

    0 讨论(0)
提交回复
热议问题