All Projects → rabbitmq → Rabbitmq Sharding

rabbitmq / Rabbitmq Sharding

Licence: other
Sharded logical queues for RabbitMQ: a queue type which provides improved parallelism and thoughput at the cost of total ordering

Programming Languages

erlang
1774 projects

Projects that are alternatives of or similar to Rabbitmq Sharding

alpine-rmq
35MB RabbitMQ Docker image running on Alpine Linux
Stars: ✭ 34 (-87.81%)
Mutual labels:  rabbitmq
csharp-ddd-skeleton
🦈✨ C# DDD Skeleton: Bootstrap your new C# projects applying Hexagonal Architecture and Domain-Driven Design patterns
Stars: ✭ 67 (-75.99%)
Mutual labels:  rabbitmq
Watchman
A simple message queue callback center
Stars: ✭ 271 (-2.87%)
Mutual labels:  rabbitmq
vercors
The VerCors verification toolset for verifying parallel and concurrent software
Stars: ✭ 30 (-89.25%)
Mutual labels:  parallelism
turbocookedrabbit
A user friendly RabbitMQ library written in Golang.
Stars: ✭ 93 (-66.67%)
Mutual labels:  rabbitmq
rbmq
Simple API for spawning RabbitMQ Producers and Consumers.
Stars: ✭ 20 (-92.83%)
Mutual labels:  rabbitmq
celery-priority-tasking
This is a prototype to schedule jobs in the backend based on some priority using Rabbitmq and Celery.
Stars: ✭ 28 (-89.96%)
Mutual labels:  rabbitmq
Benthos
Fancy stream processing made operationally mundane
Stars: ✭ 3,705 (+1227.96%)
Mutual labels:  rabbitmq
flask-rabbitmq
A simple Python Flask combined with RabbitMQ pika library
Stars: ✭ 52 (-81.36%)
Mutual labels:  rabbitmq
Springboot Learn
🌹springboot常用框架整合示例,涉及多种网站监控,数据缓存,网络通信,持久层,权限管理,常用工具等
Stars: ✭ 270 (-3.23%)
Mutual labels:  rabbitmq
rmqmonitor
A agent that written by Go(lang) used for monitoring RabbitMQ.
Stars: ✭ 17 (-93.91%)
Mutual labels:  rabbitmq
parallel python
Code for Python Parallel Programming Cookbook by Giancarlo Zaccone
Stars: ✭ 29 (-89.61%)
Mutual labels:  parallelism
Onetbb
oneAPI Threading Building Blocks (oneTBB)
Stars: ✭ 3,284 (+1077.06%)
Mutual labels:  parallelism
terraform-aws-rabbitmq
A terraform module to deploy a rabbitmq cluster with AutoScaling Group and Load Balancer
Stars: ✭ 25 (-91.04%)
Mutual labels:  rabbitmq
Rabbit Hole
RabbitMQ HTTP API client in Go
Stars: ✭ 273 (-2.15%)
Mutual labels:  rabbitmq
centos-script
🎉centos下工具安装脚本,包含基础环境配置,Gitlab、Docker、LDAP、MongoDB、MySQL、RabbitMQ、Supervisor、Node、Python、zsh、rar、zabbix、k8s、prometheus、grafana等🎉
Stars: ✭ 121 (-56.63%)
Mutual labels:  rabbitmq
fiber-boilerplate
This is the go boilerplate on the top of fiber web framework. With simple setup you can use many features out of the box
Stars: ✭ 184 (-34.05%)
Mutual labels:  rabbitmq
Chatire
💬 Real time Chat application built with Vue, Django, RabbitMQ and uWSGI WebSockets.
Stars: ✭ 278 (-0.36%)
Mutual labels:  rabbitmq
Concurrency Glossary
🦑 Informal definitions of terms used in concurrency modeling
Stars: ✭ 276 (-1.08%)
Mutual labels:  parallelism
Aspnet Servicediscovery Patterns
Samples of simple service discovery patterns with ASP .NET Core
Stars: ✭ 265 (-5.02%)
Mutual labels:  rabbitmq

RabbitMQ Sharding Plugin

This was migrated to https://github.com/rabbitmq/rabbitmq-server

This repository has been moved to the main unified RabbitMQ "monorepo", including all open issues. You can find the source under /deps/rabbitmq_sharding. All issues have been transferred.

Overview

This plugin introduces the concept of sharded queues for RabbitMQ. Sharding is performed by exchanges, that is, messages will be partitioned across "shard" queues by one exchange that we should define as sharded. The machinery used behind the scenes implies defining an exchange that will partition, or shard messages across queues. The partitioning will be done automatically for you, i.e: once you define an exchange as sharded, then the supporting queues will be automatically created on every cluster node and messages will be sharded across them.

Project Maturity

This plugin is reasonably mature and known to have production users.

Overview

The following graphic depicts how the plugin works from the standpoint of a publisher and a consumer:

Sharding Overview

On the picture above the producers publishes a series of messages, those messages get partitioned to different queues, and then our consumer get messages from one of those queues. Therefore if there is a partition with 3 queues, it is assumed that there are at least 3 consumers to get all the messages from those queues.

Queues in RabbitMQ are units of concurrency (and, if there are enough cores available, parallelism). This plugin makes it possible to have a single logical queue that is partitioned into multiple regular queues ("shards"). This trades off total ordering on the logical queue for gains in parallelism.

Message distribution between shards (partitioning) is achieved with a custom exchange type that distributes messages by applying a hashing function to the routing key.

Messages Distribution Between Shards (Partitioning)

The exchanges that ship by default with RabbitMQ work in an "all or nothing" fashion, i.e: if a routing key matches a set of queues bound to the exchange, then RabbitMQ will route the message to all the queues in that set. For this plugin to work it is necessary to route messages to an exchange that would partition messages, so they are routed to at most one queue (a subset).

The plugin provides a new exchange type, "x-modulus-hash", that will use a hashing function to partition messages routed to a logical queue across a number of regular queues (shards).

The "x-modulus-hash" exchange will hash the routing key used to publish the message and then it will apply a Hash mod N to pick the queue where to route the message, where N is the number of queues bound to the exchange. This exchange will completely ignore the binding key used to bind the queue to the exchange.

There are other exchanges with similar behaviour: the Consistent Hash Exchange or the Random Exchange. Those were designed with regular queues in mind, not this plugin, so "x-modulus-hash" is highly recommended.

If message partitioning is the only feature necessary and the automatic scaling of the number of shards (covered below) is not needed or desired, consider using Consistent Hash Exchange instead of this plugin.

Auto-scaling

One of the main properties of this plugin is that when a new node is added to the RabbitMQ cluster, then the plugin will automatically create more shards on the new node. Say there is a shard with 4 queues on node a and node b just joined the cluster. The plugin will automatically create 4 queues on node b and "join" them to the shard partition. Already delivered messages will not be rebalanced but newly arriving messages will be partitioned to the new queues.

Consuming From a Sharded [Pseudo-]Queue

While the plugin creates a bunch of "shard" queues behind the scenes, the idea is that those queues act like a big logical queue where you consume messages from it. Total ordering of messages between shards is not defined.

An example should illustrate this better: let's say you declared the exchange images to be a sharded exchange. Then RabbitMQ creates several "shard" queues behind the scenes:

  • shard: - nodename images 1
  • shard: - nodename images 2
  • shard: - nodename images 3
  • shard: - nodename images 4.

To consume from a sharded queue, register a consumer on the "images" pseudo-queue using the basic.consume method. RabbitMQ will attach the consumer to a shard behind the scenes. Note that consumers must not declare a queue with the same name as the sharded pseudo-queue prior to consuming.

TL;DR: if you have a shard called images, then you can directly consume from a queue called images.

How does it work? The plugin will chose the queue from the shard with the least amount of consumers, provided the queue contents are local to the broker you are connected to.

NOTE: there's a small race condition between RabbitMQ updating the queue's internal stats about consumers and when clients issue basic.consume commands. The problem with this is that if your client issue many basic.consume commands without too much time in between, it might happen that the plugin assigns the consumers to queues in an uneven way.

Load Distribution and Consumer Balancing

As of RabbitMQ 3.8.1, the plugin is no longer affected by the queue master locator policy when using mirrored queues. Please read below if you use a previous version.

This plugin can be affected by queue master locator policy used in the cluster as well as client connection load balancing strategy.

"Minimum masters" is a queue master locator that is most in line with the goals of this plugin.

For load balancers, the "least connections" strategy is more likely to produce an even distribution compared to round robin and other strategies.

How Evenly Will Messages Be Distributed?

As with many data distribution approaches based on a hashing function, even distribution between shards depends on the distribution (variability) of inputs, that is, routing keys. In other words the larger the set of routing keys is, the more even will message distribution between shareds be. If all messages had the same routing key, they would all end up on the same shard.

Installing

RabbitMQ 3.6.0 or later

As of RabbitMQ 3.6.0 this plugin is included into the RabbitMQ distribution.

Like any other RabbitMQ plugin it has to be enabled before it can be used:

rabbitmq-plugins enable rabbitmq_sharding

You'd probably want to also enable the Consistent Hash Exchange plugin, too.

With Earlier Versions

Install the corresponding .ez files from our Community Plugins archive.

Then run the following command:

rabbitmq-plugins enable rabbitmq_sharding

You'd probably want to also enable the Consistent Hash Exchange plugin, too.

Usage

Once the plugin is installed you can define an exchange as sharded by setting up a policy that matches the exchange name. For example if we have the exchange called shard.images, we could define the following policy to shard it:

$CTL set_policy images-shard "^shard.images$" '{"shards-per-node": 2, "routing-key": "1234"}'

This will create 2 sharded queues per node in the cluster, and will bind those queues using the "1234" routing key.

About the routing-key policy definition

In the example above we use the routing key 1234 when defining the policy. This means that the underlying exchanges used for sharding will bind the sharded queues to the exchange using the 1234 routing key specified above. This means that for a direct exchange, _only messages that are published with the routing key 1234 will be routed to the sharded queues. If you decide to use a fanout exchange for sharding, then the 1234 routing key, while used during binding, will be ignored by the exchange. If you use the "x-modulus-hash" exchange, then the routing key will be ignored as well. So depending on the exchange you use, will be the effect the routing-key policy definition has while routing messages.

The routing-key policy definition is optional.

Building from Source

Get the RabbitMQ Public Umbrella ready as explained in the RabbitMQ Plugin Development Guide.

Move to the umbrella folder an then run the following commands, to fetch dependencies:

make up
cd deps/rabbitmq-sharding
make dist

LICENSE

See the LICENSE file.

Extra information

Some information about how the plugin affects message ordering and some other details can be found in the file README.extra.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].