Skip to content

Commit 6c9b917

Browse files
JohnGarbuttmarkgoddard
authored andcommitted
Reduce RabbitMQ busy waiting, lowering CPU load
On machines with many cores, we were seeing excessive CPU load on systems that were not very busy. With the following Erlang VM argument we saw RabbitMQ CPU usage drop from about 150% to around 20%, on a system with 40 hyperthreads. +S 2:2 By default RabbitMQ starts N schedulers where N is the number of CPU cores, including hyper-threaded cores. This is fine when you assume all your CPUs are dedicated to RabbitMQ. Its not a good idea in a typical Kolla Ansible setup. Here we go for two scheduler threads. More details can be found here: https://www.rabbitmq.com/runtime.html#scheduling and here: https://erlang.org/doc/man/erl.html#emulator-flags +sbwt none This stops busy waiting of the scheduler, for more details see: https://www.rabbitmq.com/runtime.html#busy-waiting Newer versions of rabbit may need additional flags: "+sbwt none +sbwtdcpu none +sbwtdio none" But this patch should be back portable to older versions of RabbitMQ used in Train and Stein. Note that information on this tuning was found by looking at data from: rabbitmq-diagnostics runtime_thread_stats More details on that can be found here: https://www.rabbitmq.com/runtime.html#thread-stats Related-Bug: #1846467 Change-Id: Iced014acee7e590c10848e73feca166f48b622dc (cherry picked from commit 70f6f8e)
1 parent 0af6717 commit 6c9b917

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

ansible/roles/rabbitmq/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ rabbitmq_user: "openstack"
7171
rabbitmq_cluster_name: "openstack"
7272
rabbitmq_hostname: "{{ ansible_hostname }}"
7373
rabbitmq_pid_file: "/var/lib/rabbitmq/mnesia/rabbitmq.pid"
74-
rabbitmq_server_additional_erl_args: ""
74+
rabbitmq_server_additional_erl_args: "+S 2:2 +sbwt none"
7575
# Dict of TLS options for RabbitMQ. Keys will be prefixed with 'ssl_options.'.
7676
rabbitmq_tls_options: {}
7777
# To avoid split-brain

doc/source/reference/message-queues/rabbitmq.rst

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,25 @@ internal VIP. As such, traffic to this endpoint is encrypted when
8686
Passing arguments to RabbitMQ server's Erlang VM
8787
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8888

89-
Erlang programs run in Erlang VM (virtual machine) and use Erlang runtime.
90-
Erlang VM can be configured.
89+
Erlang programs run in an Erlang VM (virtual machine) and use the Erlang
90+
runtime. The Erlang VM can be configured.
9191

9292
Kolla Ansible makes it possible to pass arguments to the Erlang VM via the
93-
usage of ``rabbitmq_server_additional_erl_args`` variable. The contents of it
94-
are appended to ``RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS`` environment variable
95-
passed to RabbitMQ server startup script. Kolla Ansible already configures
96-
RabbitMQ server for IPv6 (if necessary). Any argument can be passed there as
97-
documented in https://www.rabbitmq.com/runtime.html
93+
usage of the ``rabbitmq_server_additional_erl_args`` variable. The contents of
94+
it are appended to the ``RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS`` environment
95+
variable which is passed to the RabbitMQ server startup script. Kolla Ansible
96+
already configures RabbitMQ server for IPv6 (if necessary). Any argument can be
97+
passed there as documented in https://www.rabbitmq.com/runtime.html
98+
99+
The default value for ``rabbitmq_server_additional_erl_args`` is ``+S 2:2 +sbwt
100+
none``.
101+
102+
By default RabbitMQ starts N schedulers where N is the number of CPU cores,
103+
including hyper-threaded cores. This is fine when you assume all CPUs are
104+
dedicated to RabbitMQ. Its not a good idea in a typical Kolla Ansible setup.
105+
Here we go for two scheduler threads (``+S 2:2``). More details can be found
106+
here: https://www.rabbitmq.com/runtime.html#scheduling and here:
107+
https://erlang.org/doc/man/erl.html#emulator-flags
108+
109+
The ``+sbwt`` argument prevents busy waiting of the scheduler, for more details
110+
see: https://www.rabbitmq.com/runtime.html#busy-waiting.

etc/kolla/globals.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,12 @@
395395
# See Kolla Ansible docs RabbitMQ section for details.
396396
# These are appended to args already provided by Kolla Ansible
397397
# to configure IPv6 in RabbitMQ server.
398-
#rabbitmq_server_additional_erl_args: ""
398+
# More details can be found in the RabbitMQ docs:
399+
# https://www.rabbitmq.com/runtime.html#scheduling
400+
# https://www.rabbitmq.com/runtime.html#busy-waiting
401+
# The default tells RabbitMQ to always use two cores (+S 2:2),
402+
# and not to busy wait (+sbwt none):
403+
#rabbitmq_server_additional_erl_args: "+S 2:2 +sbwt none"
399404
# Whether to enable TLS encryption for RabbitMQ client-server communication.
400405
#rabbitmq_enable_tls: "no"
401406
# CA certificate bundle in RabbitMQ container.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes an issue where RabbitMQ consumes a large amount of CPU, particularly
5+
on multi-core systems. The default RabbitMQ tuning assumes that RabbitMQ
6+
is running on a dedicated host, which is the opposite of a typical Kolla
7+
Ansible container setup. For more details on tuning RabbitMQ in your
8+
environment, please see: https://www.rabbitmq.com/runtime.html#busy-waiting
9+
https://www.rabbitmq.com/runtime.html#scheduling
10+
upgrade:
11+
- |
12+
Modifies the default value of ``rabbitmq_server_additional_erl_args`` from
13+
an empty string to ``+S 2:2 +sbwt none``.

0 commit comments

Comments
 (0)