From 87d8c8fc3d0867f451edc3690d49f0b456842354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 4 Jan 2024 16:02:29 +0100 Subject: [PATCH] Make ready for review --- src/ert/scheduler/scheduler.py | 9 +------- tests/unit_tests/scheduler/test_scheduler.py | 23 +++++--------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/ert/scheduler/scheduler.py b/src/ert/scheduler/scheduler.py index 208a2c2747e..64c0a6f51aa 100644 --- a/src/ert/scheduler/scheduler.py +++ b/src/ert/scheduler/scheduler.py @@ -43,25 +43,18 @@ class _JobsJson: class SubmitSleeper: _submit_sleep: float _last_started: float - _starttime: float def __init__(self, submit_sleep: float): self._submit_sleep = submit_sleep self._last_started = ( time.time() - submit_sleep ) # Allow the first to start immediately - self._starttime = time.time() async def sleep_until_we_can_submit(self): now = time.time() - # next_start_time = self._last_started + self._submit_sleep next_start_time = max(self._last_started + self._submit_sleep, now) - delay = next_start_time - now self._last_started = next_start_time - print( - f"at {now - self._starttime}, sleeping {max(0, delay)} until {round(self._last_started - self._starttime, 3)}" - ) - await asyncio.sleep(max(0, delay)) + await asyncio.sleep(max(0, next_start_time - now)) class Scheduler: diff --git a/tests/unit_tests/scheduler/test_scheduler.py b/tests/unit_tests/scheduler/test_scheduler.py index 6a6689f3cac..a8e6a784723 100644 --- a/tests/unit_tests/scheduler/test_scheduler.py +++ b/tests/unit_tests/scheduler/test_scheduler.py @@ -1,8 +1,8 @@ import asyncio -import datetime import json import random import shutil +import time from pathlib import Path from typing import List @@ -348,7 +348,7 @@ async def wait(iens): @pytest.mark.parametrize( "submit_sleep, iens_stride, realization_runtime, expected_max_running", - [(0, 1, 0.1, 10), (0.1, 1, 0.1, 2), (0.1, 2, 0.1, 2), (0.1, 3, 0.4, 5)], + [(0, 1, 0.1, 10), (0.1, 1, 0.1, 2), (0.1, 2, 0.1, 2)], ) async def test_submit_sleep( submit_sleep, @@ -395,32 +395,22 @@ async def wait(): "submit_sleep, realization_max_runtime, max_running", [ (0.01, 0.01, 1), + (0.01, 0.01, 10), (0.01, 0.1, 5), - # (0.1, 1, 2), - # (0.05, 1, 5), ], ) async def test_submit_sleep_with_max_running( submit_sleep, realization_max_runtime, max_running, storage, tmp_path, mock_driver ): - print() - import time - run_start_times: List[float] = [] - iens = 0 - globalnow = time.time() async def wait(): - nonlocal run_start_times, iens, globalnow - origiens = iens - print(f"starting realization {iens} at {time.time() - globalnow}") + nonlocal run_start_times run_start_times.append(time.time()) # If the realization runtimes are constant, we will never get into # the situation where we can start many realizations at the same moment - iens += 1 runtime = realization_max_runtime * random.random() await asyncio.sleep(runtime) - print(f"a realization {origiens} finished in {round(runtime,3)} seconds") ensemble_size = 10 @@ -441,10 +431,7 @@ async def wait(): await sch.execute() deltas = [ - round(next_start - start, 3) + next_start - start for start, next_start in zip(run_start_times[:-1], run_start_times[1:]) ] - print(deltas) - # print([d.total_seconds() for d in deltas]) - # 20% deviation is allowed to let tests pass with short runtimes. assert min(deltas) >= submit_sleep * 0.8