From bdf7b9686d026818fb49a404c4995b48f8aaa7c0 Mon Sep 17 00:00:00 2001 From: Andrew Emelyaneko Date: Sat, 31 Oct 2026 20:14:18 +0300 Subject: [PATCH] Switch swap threshold default to absolute 3048 MB and disable percent threshold by default --- README.md | 13 +++++++++++++ config.example.json | 3 ++- scripts/install-agent.sh | 6 ++++-- src/ollama_swap_common.py | 4 ++-- tests/test_swap_agent.py | 1 + tests/test_swap_common.py | 9 ++++++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d8a4617..21ae1de 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,19 @@ sudo ufw allow from to any port 8731 proto tcp sudo systemctl restart ollama ``` +## Порог swap + +По умолчанию агент сравнивает общий объём **используемого** swap с конкретным размером: +`swap_threshold_mb = 3048`. Процентный режим выключен (`swap_threshold_percent = null`). + +Чтобы оставить прежнее процентное поведение, задайте, например: +```json +{ + "swap_threshold_percent": 25, + "swap_threshold_mb": null +} +``` + ## Проверка агента на сервере ```sh diff --git a/config.example.json b/config.example.json index 2eec77f..ca9ebf3 100644 --- a/config.example.json +++ b/config.example.json @@ -4,7 +4,8 @@ "token": "replace-with-strong-token", "allow_insecure": false, "poll_interval_seconds": 60, - "swap_threshold_percent": 25, + "swap_threshold_percent": null, + "swap_threshold_mb": 3048, "cooldown_seconds": 600, "max_restarts_per_hour": 2, "restart_force_after_seconds": 300, diff --git a/scripts/install-agent.sh b/scripts/install-agent.sh index 4d6ccab..5674fc7 100755 --- a/scripts/install-agent.sh +++ b/scripts/install-agent.sh @@ -30,7 +30,8 @@ case "${OS}" in "token": "replace-with-strong-token", "allow_insecure": false, "poll_interval_seconds": 60, - "swap_threshold_percent": 25, + "swap_threshold_percent": null, + "swap_threshold_mb": 3048, "cooldown_seconds": 600, "max_restarts_per_hour": 2, "restart_force_after_seconds": 300, @@ -94,7 +95,8 @@ PLIST "token": "replace-with-strong-token", "allow_insecure": false, "poll_interval_seconds": 60, - "swap_threshold_percent": 25, + "swap_threshold_percent": null, + "swap_threshold_mb": 3048, "cooldown_seconds": 600, "max_restarts_per_hour": 2, "restart_force_after_seconds": 300, diff --git a/src/ollama_swap_common.py b/src/ollama_swap_common.py index 6a7252e..2e72da3 100644 --- a/src/ollama_swap_common.py +++ b/src/ollama_swap_common.py @@ -18,8 +18,8 @@ DEFAULT_CONFIG = { "token": None, "allow_insecure": False, "poll_interval_seconds": 60, - "swap_threshold_percent": 25, - "swap_threshold_mb": None, + "swap_threshold_percent": None, + "swap_threshold_mb": 3048.0, "cooldown_seconds": 600, "max_restarts_per_hour": 2, "restart_force_after_seconds": 300, diff --git a/tests/test_swap_agent.py b/tests/test_swap_agent.py index 7ac3289..1b60646 100644 --- a/tests/test_swap_agent.py +++ b/tests/test_swap_agent.py @@ -20,6 +20,7 @@ def make_config(tmp_path): "state_file": str(tmp_path / "state.json"), "launch_agent_plist": str(tmp_path / "com.ollama.serve.plist"), "poll_interval_seconds": 60, + "swap_threshold_mb": 30, } ) diff --git a/tests/test_swap_common.py b/tests/test_swap_common.py index 57928c0..4ccdf63 100644 --- a/tests/test_swap_common.py +++ b/tests/test_swap_common.py @@ -67,4 +67,11 @@ def test_count_recent(): def test_load_config_missing_file(tmp_path): config = c.load_config(str(tmp_path / "config.json")) assert config["port"] == 8731 - assert config["swap_threshold_percent"] == 25 + assert config["swap_threshold_percent"] is None + assert config["swap_threshold_mb"] == 3048.0 + + +def test_threshold_absolute_default(): + config = c.merge_config({}) + assert c.threshold_exceeded(config, c.SwapStats(2048, 596.38, 1451.62)) is False + assert c.threshold_exceeded(config, c.SwapStats(2048, 3048, 0)) is True