1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00
webvirtcloud/webvirtcloud/tests/test_gunicorn_conf.py
catborise 58b733d5b7 feat(webvirtcloud): a request waiting on a host holds one thread, not a worker
A host that is up but does not answer (a hung NFS mount, for one) keeps
a libvirt call waiting: libvirt's keepalive does not end it, since the
daemon still answers keepalives. Each such request held a whole sync
worker, and once they held every worker the panel stopped answering,
pages without libvirt too; F5 added another.

gunicorn now runs threaded workers, 4 threads each, and a worker takes
no more connections than it has threads, so one whose threads are all
busy leaves new requests to the others. A threaded worker keeps
reporting in while a thread waits, so gunicorn's timeout no longer ends
the request: the worker now exits itself when a request runs past the
timeout (600 s), and gunicorn starts a new one. Short claims expire on
that bound.

The address search runs one at a time in a process, as it did with one
request per worker.
2026-11-02 21:19:01 +03:00

32 lines
1,017 B
Python

"""gunicorn runs a bounded number of sync workers."""
import runpy
import unittest
from pathlib import Path
from unittest.mock import patch
from django.conf import settings
CONF = str(Path(settings.BASE_DIR) / "gunicorn.conf.py")
def load(cpus):
with patch("os.sysconf", return_value=cpus):
return runpy.run_path(CONF)
class GunicornConfTestCase(unittest.TestCase):
def test_worker_count_is_capped(self):
self.assertEqual(load(64)["workers"], 8)
def test_small_hosts_keep_two_per_cpu_plus_one(self):
self.assertEqual(load(2)["workers"], 5)
def test_unknown_cpu_count_falls_back(self):
self.assertEqual(load(-1)["workers"], 3)
def test_workers_run_requests_in_threads(self):
conf = load(2)
self.assertEqual((conf["worker_class"], conf["threads"]), ("webvirtcloud.gunicorn_worker.Worker", 4))
# a worker with every thread busy takes no new connection
self.assertEqual((conf["worker_connections"], conf["keepalive"]), (4, 0))