Skip to content

Commit fd60470

Browse files
committed
Fix web concurrency Gunicorn worker calculation
#11 The README explains, "If either `MAX_WORKERS` or `WEB_CONCURRENCY` are set to 1, the total number of workers will be 1, overriding the default minimum of 2." This was true for `MAX_WORKERS`, but `WEB_CONCURRENCY` was still set to minimum 2. This commit will allow `WEB_CONCURRENCY` (number of Gunicorn workers) to have a minimum of 1.
1 parent edcc361 commit fd60470

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

inboard/gunicorn_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def calculate_workers(
1616
if max_workers_str and int(max_workers_str) > 0:
1717
use_max_workers = int(max_workers_str)
1818
if web_concurrency_str and int(web_concurrency_str) > 0:
19-
use_web_concurrency = max(int(web_concurrency_str), 2)
19+
use_web_concurrency = int(web_concurrency_str)
2020
return (
2121
min(use_max_workers, use_web_concurrency)
2222
if max_workers_str and web_concurrency_str

tests/test_start.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ def test_gunicorn_conf_workers_custom_max(self, monkeypatch: MonkeyPatch) -> Non
6969
== 1
7070
)
7171

72+
@pytest.mark.parametrize("number_of_workers", ["1", "2", "4"])
7273
def test_gunicorn_conf_workers_custom_concurrency(
73-
self, monkeypatch: MonkeyPatch
74+
self, monkeypatch: MonkeyPatch, number_of_workers: str
7475
) -> None:
7576
"""Test custom Gunicorn worker process calculation."""
76-
monkeypatch.setenv("WEB_CONCURRENCY", "4")
77+
monkeypatch.setenv("WEB_CONCURRENCY", number_of_workers)
7778
monkeypatch.setenv("WORKERS_PER_CORE", "0.5")
78-
assert os.getenv("WEB_CONCURRENCY") == "4"
79+
assert os.getenv("WEB_CONCURRENCY") == number_of_workers
7980
assert os.getenv("WORKERS_PER_CORE") == "0.5"
8081
assert (
8182
gunicorn_conf.calculate_workers(
8283
None,
8384
str(os.getenv("WEB_CONCURRENCY")),
8485
str(os.getenv("WORKERS_PER_CORE")),
8586
)
86-
== 4
87+
== int(number_of_workers)
8788
)
8889

8990
def test_gunicorn_conf_workers_custom_cores(self, monkeypatch: MonkeyPatch) -> None:

0 commit comments

Comments
 (0)