Skip to content

Commit dde0f6f

Browse files
committed
Troubleshooting multiprocess cpu seconds
1 parent 867a605 commit dde0f6f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/_ert/forward_model_runner/forward_model_step.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,4 @@ def _get_processtree_data(
483483
), child.oneshot():
484484
memory_rss += child.memory_info().rss
485485
cpu_seconds += child.cpu_times().user
486-
return (memory_rss, cpu_seconds, oom_score)
486+
return memory_rss, cpu_seconds, oom_score

tests/ert/unit_tests/forward_model_runner/test_forward_model_step.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import os
33
import pathlib
4+
import random
45
import stat
56
import sys
67
import textwrap
@@ -43,7 +44,7 @@ def test_run_with_process_failing(mock_process, mock_popen, mock_check_executabl
4344
next(run)
4445

4546

46-
@pytest.mark.flaky(reruns=10)
47+
# @pytest.mark.flaky(reruns=10)
4748
@pytest.mark.integration_test
4849
@pytest.mark.usefixtures("use_tmpdir")
4950
def test_cpu_seconds_can_detect_multiprocess():
@@ -64,34 +65,39 @@ def test_cpu_seconds_can_detect_multiprocess():
6465
"""\
6566
import time
6667
now = time.time()
67-
while time.time() < now + 2:
68+
while time.time() < now + 5:
6869
pass"""
6970
)
7071
)
71-
scriptname = "saturate_cpus.sh"
72+
r = random.randint(1, 1000)
73+
scriptname = f"saturate_cpus_{r}.sh"
7274
with open(scriptname, "w", encoding="utf-8") as script:
7375
script.write(
7476
textwrap.dedent(
7577
"""\
7678
#!/bin/sh
7779
python busy.py &
80+
python busy.py &
81+
python busy.py &
82+
python busy.py &
7883
python busy.py"""
7984
)
8085
)
8186
executable = os.path.realpath(scriptname)
8287
os.chmod(scriptname, stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG)
88+
8389
fmstep = ForwardModelStep(
8490
{
8591
"executable": executable,
8692
},
8793
0,
8894
)
89-
fmstep.MEMORY_POLL_PERIOD = 0.05
95+
fmstep.MEMORY_POLL_PERIOD = 0.01
9096
cpu_seconds = 0.0
9197
for status in fmstep.run():
9298
if isinstance(status, Running):
9399
cpu_seconds = max(cpu_seconds, status.memory_status.cpu_seconds)
94-
assert 2.5 < cpu_seconds < 4.5
100+
assert 23 < cpu_seconds < 27
95101

96102

97103
@pytest.mark.integration_test

0 commit comments

Comments
 (0)