diff --git a/cpu_governor_auto_adjust.xml b/cpu_governor_auto_adjust.xml index 59c0d37..f3ac9f6 100644 --- a/cpu_governor_auto_adjust.xml +++ b/cpu_governor_auto_adjust.xml @@ -46,7 +46,7 @@ 5 performance - 0.1 + 0.01 diff --git a/cpu_governor_auto_adjust/triggers/cpu_load.py b/cpu_governor_auto_adjust/triggers/cpu_load.py index 64b9c87..09460e7 100644 --- a/cpu_governor_auto_adjust/triggers/cpu_load.py +++ b/cpu_governor_auto_adjust/triggers/cpu_load.py @@ -2,31 +2,44 @@ from cpu_governor_auto_adjust.trigger import Trigger from cpu_governor_auto_adjust.config import Config from functools import cached_property from os import getloadavg +from datetime import datetime, timedelta class CpuLoadTrigger(Trigger): def __init__(self, _config: Config) -> None: super().__init__(_config) + self.timestamp_last_governor_change = datetime.now() - timedelta(minutes=10) @cached_property - def five_minute_load_threshold(self) -> float: - return float(self.config.custom_config['fiveMinuteLoadThreshold']) + def one_minute_load_threshold(self) -> float: + return float(self.config.custom_config['oneMinuteLoadThreshold']) @property def current_load(self) -> float: - return getloadavg()[1] + _current_load = getloadavg()[0] + self.log.debug("current load: %s", _current_load) + return _current_load def run(self) -> None: current_active = self.active - new_active = self.current_load >= self.five_minute_load_threshold + current_time = datetime.now() + new_active = self.current_load >= self.one_minute_load_threshold + if not current_active and new_active: self.log.info( "activating trigger, load: %s, threshold: %s, governor: %s", - self.current_load, self.five_minute_load_threshold, self.governor.name + self.current_load, self.one_minute_load_threshold, self.governor.name ) + self.timestamp_last_governor_change = current_time + elif current_active and not new_active: + if (current_time - timedelta(minutes=5)) < self.timestamp_last_governor_change: + self.log.info("cooldown period, staying on governor: %s", self.governor.name) + return + self.log.info( "deactivating trigger, load: %s, threshold: %s, governor: %s", - self.current_load, self.five_minute_load_threshold, self.governor.name + self.current_load, self.one_minute_load_threshold, self.governor.name ) + self.active = new_active diff --git a/pyproject.toml b/pyproject.toml index 11b89f1..553b818 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cpu_governor_auto_adjust" -version = "0.1.35" +version = "0.1.39" description = "This application has been developed to automatically change cpu governor based on certain triggers." authors = [ { name = "Martin Reurekas", email = "martin@semrks.nl" }