diff options
author | John Eckersberg <jeckersb@redhat.com> | 2015-10-02 13:47:21 -0400 |
---|---|---|
committer | Flavio Percoco <flaper87@gmail.com> | 2015-10-20 22:01:19 +0900 |
commit | 30cb3cee44079b1683e95ccff8cec011848cdc61 (patch) | |
tree | fd1a673570540eecc1dedb89d7900f9c20d099e0 | |
parent | f8db9cdcb36b28d1a4dc7bafb4d63c27d2a68dda (diff) | |
download | oslo-messaging-30cb3cee44079b1683e95ccff8cec011848cdc61.tar.gz |
rabbit: shuffle hosts before building kombu URL
This restores behavior as it was back in the Juno cycle. This was
changed in a refactor during the Kilo cycle (973301aa) when the kombu
failover_strategy was set to shuffle. But the failover_strategy only
affects failovers; it does not influence which host receives the
initial connection.
Thus, if multiple hosts are given, the first host will receive all of
the initial connections. By shuffling the hosts before building the
URL given to kombu, rudimentary load balancing is achieved and
connections are more evenly spread across broker nodes.
Change-Id: Ieecaf5f286f49302db29df9854359ef5d36b7a89
(cherry picked from commit f2beb5eaf158f76cdb8be0ca72965503be423ee2)
-rw-r--r-- | oslo_messaging/_drivers/impl_rabbit.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py index fe279c4..9716b9c 100644 --- a/oslo_messaging/_drivers/impl_rabbit.py +++ b/oslo_messaging/_drivers/impl_rabbit.py @@ -17,6 +17,7 @@ import functools import itertools import logging import os +import random import socket import ssl import threading @@ -627,6 +628,7 @@ class Connection(object): LOG.warn(_LW('Selecting the kombu transport through the ' 'transport url (%s) is a experimental feature ' 'and this is not yet supported.') % url.transport) + random.shuffle(url.hosts) for host in url.hosts: transport = url.transport.replace('kombu+', '') transport = transport.replace('rabbit', 'amqp') @@ -644,6 +646,7 @@ class Connection(object): transport = url.transport.replace('kombu+', '') self._url = "%s://%s" % (transport, virtual_host) else: + random.shuffle(self.driver_conf.rabbit_hosts) for adr in self.driver_conf.rabbit_hosts: hostname, port = netutils.parse_host_port( adr, default_port=self.driver_conf.rabbit_port) |