Skip to content

Commit 5acd2f9

Browse files
committed
Tune libvirtd connection limits for OpenStack
The libvirt daemon ships with max_workers=20 and max_client_requests=5. Those defaults suit a multi-tenant host serving many mutually distrustful clients, where the per-client request cap protects the daemon from any single client monopolising it. Under Kolla-Ansible, nova-compute is effectively the sole privileged client of libvirtd, so the cap of 5 concurrent requests per client becomes the binding constraint rather than a safety net. When several instances build at once -- as they do during the tempest run of the upgrade jobs -- nova-compute's concurrent libvirt RPCs (instance defineXML calls plus the resource-tracker periodic) exceed five. Further requests queue, the connection's keepalive responses are starved, and after keepalive_interval (5s) x keepalive_count (5) = 25s libvirtd closes the connection. nova then sees "Cannot recv data: Input/output error" mid-defineXML, the build is rescheduled, and once all hosts are exhausted the instance is left in ERROR. This presents as flaky upgrade-job failures. Example failure, on the voting kolla-ansible-debian-bookworm-upgrade job (stable/2025.2): https://zuul.opendev.org/t/openstack/build/73ff5a97567d4e05b1774170e0f4aada with primary/logs/kolla/libvirt/libvirtd.txt showing libvirt's own recommendation to tune this parameter: warning : Client hit max requests limit 5. This may result in keep-alive timeouts. Consider tuning the max_client_requests server parameter ... error : connection closed due to keepalive timeout Raise the per-client cap to 20 -- comfortably above the handful of concurrent builds plus periodics seen in practice -- and the worker pool to 50 so that lifting the per-client limit does not starve other connections such as live migration, health checks and periodic tasks. Both values are exposed as variables (libvirt_max_client_requests and libvirt_max_workers) so operators can tune them further. This is not a Kolla-specific workaround -- the stock libvirtd.conf comment warns that setting max_client_requests too low "may cause keepalive timeouts", and since 2022 libvirtd emits the runtime warning quoted above. As Daniel Berrange explained when he added that warning, the keepalive packets "are subject to the 'max_client_requests' limit just like any API calls", so a client that saturates the limit can have its connection dropped: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/5NIJPA7SJVY55VSK7RTEDEHKWOZYJKT6/ Red Hat documents the same tuning for libvirt hosts under load in its knowledge base, notably "Too many active clients are dropping the connection" at https://access.redhat.com/solutions/28146. Assisted-By: Claude Opus 4.8 (1M context, medium effort) Partial-Bug: 2158515 Change-Id: I131c3d4d57dc73ca4dd421cc8f28465248c9830e Signed-off-by: Michael Still <mikal@stillhq.com>
1 parent e6c4dc0 commit 5acd2f9

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

ansible/roles/nova-cell/defaults/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,17 @@ libvirt_sasl_authname: "nova"
639639
libvirt_sasl_mech_list:
640640
- "{{ 'SCRAM-SHA-256' if libvirt_tls | bool else 'DIGEST-MD5' }}"
641641

642+
# Connection processing limits for libvirtd. nova-compute is effectively the
643+
# only privileged client of libvirtd under Kolla, so libvirt's stock per-client
644+
# request cap (max_client_requests=5) is the binding constraint rather than a
645+
# safety net: concurrent instance builds plus the resource-tracker periodic
646+
# routinely exceed five in-flight RPCs, which starves keepalive responses until
647+
# libvirtd drops the connection. Raise the per-client cap, and the worker pool
648+
# along with it so that lifting the per-client limit does not starve other
649+
# connections (live migration, health checks, periodics).
650+
libvirt_max_client_requests: 20
651+
libvirt_max_workers: 50
652+
642653
####################
643654
# Kolla
644655
####################

ansible/roles/nova-cell/templates/libvirtd.conf.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ listen_addr = "{{ migration_interface_address }}"
2525
# Enable read-only access to libvirt socket
2626
auth_unix_ro = "none"
2727
{% endif %}
28+
29+
# Connection processing limits. libvirt's defaults (max_workers=20,
30+
# max_client_requests=5) assume a multi-tenant host with many mutually
31+
# distrustful clients. Under Kolla, nova-compute is effectively the sole
32+
# privileged client, so the per-client cap of 5 becomes the binding
33+
# constraint: concurrent builds plus the resource-tracker periodic exceed
34+
# five in-flight RPCs and starve keepalive responses, causing libvirtd to
35+
# drop the connection after keepalive_interval (5s) x keepalive_count (5).
36+
max_workers = {{ libvirt_max_workers }}
37+
max_client_requests = {{ libvirt_max_client_requests }}

doc/source/reference/compute/libvirt-guide.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,26 @@ Since the Yoga release, the ``kolla-ansible certificates`` command generates
198198
certificates for libvirt TLS. A single key and certificate is used for all
199199
hosts, with a Subject Alternative Name (SAN) entry for each compute host
200200
hostname.
201+
202+
Libvirt Connection Limits
203+
=========================
204+
205+
By default ``libvirt`` is configured by upstream packages with reasonable
206+
defaults for an environment where many users are starting and stopping virtual
207+
machines. This isn't true for Kolla Hypervisor nodes, where a single
208+
``nova-compute`` container manages all of the virtual machine instances on the
209+
machine.
210+
211+
Kolla-Ansible therefore tunes the following values in ``libvirtd.conf``:
212+
213+
* libvirt_max_client_requests: raised to 20 compared to the usual default of
214+
5.
215+
* libvirt_max_workers: raised to 50 compared to the usual default of 20.
216+
217+
Both of these values may be overridden in ``globals.yml``.
218+
219+
This means that ``nova-compute`` can therefore perform 20 operations via
220+
libvirt simultaneously instead of the usual default of 5. These values should
221+
be safe, but if you see libvirt error messages saying ``Client hit max requests
222+
limit``, you may want to consider an additional increase -- especially if you
223+
have particularly large hypervisors.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
features:
3+
- |
4+
The ``nova_libvirt`` container's ``libvirtd.conf`` now raises libvirt's
5+
connection processing limits above their stock defaults, which are tuned
6+
for a multi-tenant host rather than for Kolla's single-privileged-client
7+
pattern. ``max_client_requests`` is raised from 5 to 20 and ``max_workers``
8+
from 20 to 50. Both are exposed as the ``libvirt_max_client_requests`` and
9+
``libvirt_max_workers`` variables so they can be tuned further.
10+
fixes:
11+
- |
12+
Fixed intermittent instance build failures (``Cannot recv data:
13+
Input/output error`` during ``defineXML``, leading to instances in
14+
``ERROR`` state) that occurred when several instances were built
15+
concurrently. nova-compute is effectively the sole client of ``libvirtd``,
16+
and libvirt's default per-client request cap of 5 was being exceeded by
17+
concurrent builds plus periodic tasks, starving keepalive responses until
18+
``libvirtd`` dropped the connection.

0 commit comments

Comments
 (0)