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

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

问题描述

Redis 不支持 master 复制.

Redis doesnt support master master replication.

在redis教程中可以看到有一个配置,有6个节点,3个master,3个slave,

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

谁能告诉我这个配置的目的是什么(slave是为了fail-over,3master的目的是什么?)

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.

此配置的目的是为了容错.从站也可用于读取(只读).在三个 master 中,hashslots 平均分配,并且通过负载平衡算法,您可以重新分配实际的密钥.在节点之间分配密钥的可能算法的步骤是(由我测试并且按预期工作):

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. 计算每个 master 必须持有的密钥,以便要平衡的键的分布(簇的键总数/数量大师)
  5. 找出哪些主节点必须接受或提供密钥以及总数他们必须给予/拿走的钥匙
  6. 将主节点表征为源节点或目标节点,具体取决于他们分别接收或赠送钥匙
  7. 开始从源节点迁移到目标节点,首先是hashslots 然后是相关的键并迭代直到所有主人拥有相同数量的密钥

此算法将有助于最大限度地缩短响应时间.我的意思是:

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

使用三个主站可以最大限度地缩短响应时间.如果您的配置有一个主控,并且该主控持有例如 30000 个#keys,则一次获得 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 将您的请求重定向到正确的 master 的情况下,您才能从 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天全站免登陆