Redis集群/负载均衡 [英] Redis cluster/ load balancing

查看:382
本文介绍了Redis集群/负载均衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Redis不支持主-主复制。

Redis doesnt support master master replication.

在redis教程中,我看到有一个配置,具有6个节点,3个主节点,3个从属,

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

任何人都可以告诉我这种配置的目的是什么(从站是为了进行故障转移,3个主设备的目的是什么?)

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

我的要求是减少从应用服务器到Redis的连接数。因此,我一直在寻找一种指向多个Redis节点的方法,因此,如果我从Redis节点1创建密钥,则可以从Redis节点2删除该密钥。

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.

有可能吗?

推荐答案

首先,如果您在


redis-trib.rb

redis-trib.rb

在函数 def check_create_parameters 。您可以设置一个主副本和一个从副本。

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

此配置的目的是为了容错。从站也可以用于读取(READONLY)。在这三个母版中,哈希槽平均分配,并且可以使用负载平衡算法重新分配实际密钥。可以在节点之间分发密钥的一种可能算法的步骤(由我测试,并且按预期工作):

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. 主服务器数量

  2. 获取其持有的密钥总数

  3. 对于每个主节点,存储主机名,端口和密钥数量

  4. 计算每个主控必须拥有的密钥,以使
    的密钥分布保持平衡(群集的总密钥/主控的
    数)

  5. 查找必须拥有或提供密钥的主节点以及它们必须提供/获取的密钥总金额

  6. 根据$ b是否将主节点特征化为源节点或目标节点他们分别接收或提供密钥的$ b

  7. 开始从源节点迁移到目标节点,首先是
    哈希槽,然后是相关密钥,然后迭代直到所有
    个主密钥的数量相同

  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:

有了三个主机,可以将响应时间最小化。如果您有一个拥有一个主服务器的配置,而该主服务器拥有30000个#key,则一次获取1000个密钥的响应时间是>具有2个主服务器(每个拥有15000个)的配置。

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.

如果在master1中创建密钥,那么如果尝试从master2到达(读取)该密钥,则会收到MOVED错误。因此,解决方案是创建一个将哈希槽映射到相应节点的智能客户端。因此,只有在master2将您的请求重定向到正确的主服务器的情况下,您才能从master2删除密钥。

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.

希望有帮助。

这篇关于Redis集群/负载均衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆