禅Hugozen思考 · THOUGHTS

Rabbitmq reading note

2016-08-17 技术笔记

背景

之前在 game workshop 的时候,有做这方面的技术调研,了解了下这方面的技术细节。不过阅读的内容都存在 Evernote 里面,趁着翻阅的时候,把资料再掏出来。

blog

集群方案

  • rabbitmq 的集群方案有几个点
  • node 可以选择 disk 或者 ram 模式,disk 模式存储元数据(比如 exchange、queue、channel)等。而 ram 节点不存储任何数据到 disk 上面(如果配置了 queue 数据为永久性的话,则还是会存??)。
  • 元数据是会在节点间不断的同步的,所以文档建议可以采用一个 disk 节点,多个 ram 节点的方式来达到一个比较好的性能。
  • rabbitmq 对 client 的要求是,client 可以选择连接到一个 proxy,proxy 再分发到集群内部的任意一个节点。但是这个工作必须是我们自己动手搞,不过可以借用一些开源的工具实现,比如 HAPROXY、Nginx。
  • queue 内部的数据,分发的模式好像有两种,一种是完全的同步,一种按需同步。完全同步就是所有节点的队列数据都是一样的,按需索取是当连接某个 node 的 queue 被消费的时候,再从 disk 节点处获取数据。官网的推荐做法是按需同步,这样主要是为了横向扩展的时候,可以支持更多的并发连接,以及减少集群内部的网络通讯,降低消息分发的延迟。
  • 当然这里面有一些风险需要注意,比如集群节点的管理,要时刻注意 disk node 必须是最后一个关掉,以保证消息、元数据的完整性(但我觉得不用完全同步的话,不太可能。就算完全同步,也会存在信息丢失,只是这个概率就很低了吧。总感觉可以通过 log 日志,向 mysql 那类学习。顶多就回档,来个两步提交之类的方法??)
  • 镜像队列:如果为一个队列建立多个镜像,前者称为主节点,后者称为从节点。如果主节点有问题,那么 RabbitMQ 会从从节点中选择最早同步的一个作为新的主节点,以保证尽量不丢失消息,然而原主节点中同步之前的消息还是会丢失。
  • 原文有几个比较经典的说法:
  • All data/state required for the operation of a RabbitMQ broker is replicated across all nodes, for reliability and scaling, with full ACID properties. An exception to this are message queues, which by default reside on the node that created them, though they are visible and reachable from all nodes. To replicate queues across nodes in a cluster, see the documentation on high availability (note that you will need a working cluster first).
  • In general, this aspect of managing the connection to nodes within a cluster is beyond the scope of RabbitMQ itself, and we recommend the use of other technologies designed specifically to solve these problems.
  • A node can be a disk node or a RAM node. (Note: disk and disc are used interchangeably. Configuration syntax or status messages normally use disc.) RAM nodes keep their state only in memory (with the exception of queue contents, which can reside on disc if the queue is persistent or too big to fit in memory). Disk nodes keep state in memory and on disk. As RAM nodes don’t have to write to disk as much as disk nodes, they can perform better. However, note that since the queue data is always stored on disc, the performance improvements will affect only resources management (e.g. adding/removing queues, exchanges, or vhosts), but not publishing or consuming speed. Because state is replicated across all nodes in the cluster, it is sufficient (but not recommended) to have just one disk node within a cluster, to store the state of the cluster safely.

坑

  • 关于配置。

setcookie 要配对,rabbitmqctl 也要跟着一样,不然一直报 “node down” 的错误信息,但是这个其实是 cookie 不配对导致的。

问题

  • durable queue 的问题。

关于 client 连接 server 端,建立 durable queue 之后,重连其它 server 导致的信息丢失问题,好像不存在,这个要再考察下。

性能

其他

← Good practice for storing time related objs in mysql with pythonThe reading note of web page design →