Package: rmq-cluster-rebalance
CLI application for rebalancing queues in a RabbitMQ clusterInstallationpipinstallrmq-cluster-rebalanceWhy?When you specify thequeue master locationin RabbitMQ
with value ofmin-masters, RabbitMQ will attempt to balance the distribution
of the master locations for queues across the cluster. However, when you restart
a RabbitMQ node in a cluster with HA queues, the master location for a queue on that
node will move to a different node. Given enough such events and depending on your HA
policies, you can end up with an uneven distribution of queues with a master location
on a minority of nodes. In this scenario, the nodes in cluster may not be utilized
as evenly, with higher CPU, memory, disk, and network utilization on nodes that
carry the larger quantity of master nodes.Rebalancing queues across nodes can also be useful when adding nodes to a cluster
with noqueue_master_locatorconfiguration set (which uses the default value ofclient-local), regardless of whether you use HA queues or not.MethodologyThe application use the RabbitMQ management UI to iterate through each queue
in the cluster. The queue is inspected and a policy namedrmq-cluster-rebalanceis created using the existing policy configuration used by the queue with the
addition or replacement ofha-mode, setting it toalland removingha-paramsandqueue-master-locatorif they are set. Once the queue has fully replicated
across all nodes in the cluster, thermq-cluster-rebalancepolicy is replaced
with a new policy that settingha-modetonodesand specifying only the
new master node inha-params. When the queue has fully moved, the policy will
then removed and the application will move on to the next queue.Nodes are assigned in a simple round-robin ordering. If a queue is already living
on the node where it would be assigned to, it will be skipped and no work is
performed on that queue.WarningThis approach should be safe for production use without interruption of publishers
or consumers. While it has worked for me without issue, your mileage may vary.This application requires a relatively current version of RabbitMQ and was only
tested with3.7.16.CLI Usageusage: rmq-cluster-rebalance [-h] [-u USERNAME] [-p PASSWORD] [--vhost VHOST]
                             [-L LOG_FILE] [-v] [--debug] [--version]
                             [URL]

Rebalances the queues in a RabbitMQ cluster

positional arguments:
  URL                   The RabbitMQ Management API base URL (default:
                        http://localhost:15672)

optional arguments:
  -h, --help            show this help message and exit
  -u USERNAME, --username USERNAME
                        The RabbitMQ Management API username (default: guest)
  -p PASSWORD, --password PASSWORD
                        The RabbitMQ Management API password (default: guest)
  --vhost VHOST         The RabbitMQ VHost to use (default: /)
  --version             output version information, then exit

Logging options:
  -L LOG_FILE, --log-file LOG_FILE
                        Log to the specified filename (default: STDOUT)
  -v, --verbose         Increase output verbosity (default: False)
  --debug               Extra verbose debug logging (default: False)