diff --git a/golem/core/fileshelper.py b/golem/core/fileshelper.py index 81d0edbd9c..b7432f5222 100644 --- a/golem/core/fileshelper.py +++ b/golem/core/fileshelper.py @@ -193,11 +193,7 @@ def du(path): logger.info("Can't open dir {}: {}".format(path, str(err))) return "-1" - human_readable_size, idx = memoryhelper.dir_size_to_display(size) - return "{} {}".format( - human_readable_size, - memoryhelper.translate_resource_index(idx) - ) + return memoryhelper.dir_size_to_display(size) def relative_path(path, prefix): diff --git a/golem/task/taskserver.py b/golem/task/taskserver.py index 3673ba2a7f..c1fa97d502 100644 --- a/golem/task/taskserver.py +++ b/golem/task/taskserver.py @@ -92,6 +92,7 @@ from golem.task.taskbase import AcceptClientVerdict from golem.task.taskconnectionshelper import TaskConnectionsHelper from golem.task.taskstate import TaskOp +from golem.tools import memoryhelper from golem.utils import decode_hex from .server import concent from .server import helpers @@ -1101,6 +1102,9 @@ def should_accept_provider( # pylint: disable=too-many-return-statements provider_perf: float, max_memory_size: int, offer_hash: str) -> bool: + # max_memory_size: int KiB + max_memory_size_b = int(max_memory_size) * 1024 # Bytes + node_name_id = short_node_id(node_id) ids = f'provider={node_name_id}, task_id={task_id}' @@ -1141,9 +1145,22 @@ def should_accept_provider( # pylint: disable=too-many-return-statements }) return False - if min_memory > (int(max_memory_size) * 1024): - logger.info('insufficient provider memory size: ' - f'{min_memory} B < {max_memory_size} KiB; {ids}') + if min_memory > max_memory_size_b: + logger.info( + 'insufficient provider memory size:' + ' %(available)s < %(min_memory)s;' + ' Free at least %(missing)s; %(ids)s', + { + 'min_memory': memoryhelper.dir_size_to_display(min_memory), + 'available': memoryhelper.dir_size_to_display( + max_memory_size_b, + ), + 'missing': memoryhelper.dir_size_to_display( + min_memory - max_memory_size_b, + ), + 'ids': ids, + } + ) self.notify_provider_rejected( node_id=node_id, task_id=task_id, reason=self.RejectedReason.memory_size, diff --git a/golem/tools/memoryhelper.py b/golem/tools/memoryhelper.py index b6d93ab9e2..1f26488c59 100644 --- a/golem/tools/memoryhelper.py +++ b/golem/tools/memoryhelper.py @@ -1,30 +1,11 @@ -import logging - -logger = logging.getLogger("tools") - -options = { - 0: 'kB', - 1: 'MB', - 2: 'GB' -} - - def dir_size_to_display(dir_size): if dir_size // (1024 * 1024 * 1024) > 0: dir_size = round(float(dir_size) / (1024 * 1024 * 1024), 1) - index = 2 - elif dir_size // (1024 * 1024) > 0: + return f'{dir_size} GiB' + if dir_size // (1024 * 1024) > 0: dir_size = round(float(dir_size) / (1024 * 1024), 1) - index = 1 - else: + return f'{dir_size} MiB' + if dir_size // 1024 > 0: dir_size = round(float(dir_size) / 1024, 1) - index = 0 - return dir_size, index - - -def translate_resource_index(index): - if index in options: - return options[index] - else: - logger.error("Wrong memory unit index: {} ".format(index)) - return '' + return f'{dir_size} KiB' + return f'{dir_size} B' diff --git a/tests/golem/task/test_taskserver.py b/tests/golem/task/test_taskserver.py index 1939416625..7070684a24 100644 --- a/tests/golem/task/test_taskserver.py +++ b/tests/golem/task/test_taskserver.py @@ -471,8 +471,8 @@ def test_should_accept_provider_insufficient_memory_size(self, *_args): _assert_log_msg( cm, f'INFO:{logger.name}:insufficient provider memory size: ' - f'{estimated_memory} B < {DEFAULT_MAX_MEMORY_SIZE_KB} ' - f'KiB; {ids}') + f'4.0 KiB < 4.0 KiB; Free at least 1 B;' + f' {ids}') listener.assert_called_once_with( sender=ANY,