From a9c5eb25639acd33092e50d579900e277b8021c1 Mon Sep 17 00:00:00 2001 From: Jon Holba Date: Tue, 10 Sep 2024 14:44:24 +0200 Subject: [PATCH] Fix error in job dispatch's memory reporting Updated the test so that it will not work if process is counted number of child processes times. --- src/_ert_forward_model_runner/job.py | 2 +- tests/unit_tests/forward_model_runner/test_job.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/_ert_forward_model_runner/job.py b/src/_ert_forward_model_runner/job.py index 8c8c662d32e..dfdd90caf6e 100644 --- a/src/_ert_forward_model_runner/job.py +++ b/src/_ert_forward_model_runner/job.py @@ -400,6 +400,6 @@ def _get_rss_and_oom_score_for_processtree( else oom_score_child ) with contextlib.suppress(NoSuchProcess, AccessDenied, ZombieProcess): - memory_rss += process.memory_info().rss + memory_rss += child.memory_info().rss return (memory_rss, oom_score) diff --git a/tests/unit_tests/forward_model_runner/test_job.py b/tests/unit_tests/forward_model_runner/test_job.py index 1ef7c81978a..3a36560d427 100644 --- a/tests/unit_tests/forward_model_runner/test_job.py +++ b/tests/unit_tests/forward_model_runner/test_job.py @@ -53,12 +53,12 @@ def test_memory_usage_counts_grandchildren(): import sys import time - counter = int(sys.argv[-1]) - numbers = list(range(int(1e6))) + counter = int(sys.argv[-2]) + numbers = list(range(int(sys.argv[-1]))) if counter > 0: parent = os.fork() if not parent: - os.execv(sys.argv[-2], [sys.argv[-2], str(counter - 1)]) + os.execv(sys.argv[-3], [sys.argv[-3], str(counter - 1), str(int(1e7))]) time.sleep(1)""" # Too low sleep will make the test faster but flaky ) ) @@ -69,7 +69,7 @@ def max_memory_per_subprocess_layer(layers: int) -> int: job = Job( { "executable": executable, - "argList": [str(layers)], + "argList": [str(layers), str(int(1e6))], }, 0, ) @@ -84,7 +84,7 @@ def max_memory_per_subprocess_layer(layers: int) -> int: # comparing the memory used with different amounts of forks done. # subtract a little bit (* 0.9) due to natural variance in memory used # when running the program. - memory_per_numbers_list = sys.getsizeof(int(0)) * 1e6 * 0.9 + memory_per_numbers_list = sys.getsizeof(int(0)) * 1e7 * 0.90 max_seens = [max_memory_per_subprocess_layer(layers) for layers in range(3)] assert max_seens[0] + memory_per_numbers_list < max_seens[1]