Skip to content
Snippets Groups Projects
Unverified Commit b9a21773 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

simulator: Fix timestamps manipulation

It's unclear whether the change in this mr triggers the bug in the simulator.
But it should be timestamp that needs manipulation and it's currently
datetimes. So this makes the current state fails with [1]

Adding the conversion layer from datetime to timestamps make the tests happier.

[1]
```
16:17:06  low = datetime.datetime(2025, 3, 14, 15, 17, 2, 139077, tzinfo=datetime.timezone.utc)
16:17:06  high = datetime.datetime(2025, 3, 14, 15, 17, 2, 139077, tzinfo=datetime.timezone.utc)
16:17:06
16:17:06      def _diff(low, high):
16:17:06          if low == high:
16:17:06              if low == 0:
16:17:06                  return 0.5
16:17:06              else:
16:17:06  >               return abs(low * 0.1)
16:17:06  E               TypeError: unsupported operand type(s) for *: 'datetime.datetime' and 'float'
16:17:06
```

Refs. swh/infra/sysadm-environment#5512
parent fed21704
No related branches found
No related tags found
No related merge requests found
Pipeline #14035 passed
......@@ -77,8 +77,24 @@ class SimulationReport:
[runtime for runtime in runtimes if runtime <= self.DURATION_THRESHOLD]
)
def _convert_timestamps(self, datetimes):
timestamps = []
convert_timestamps = False
for dt in datetimes:
if isinstance(dt, datetime):
convert_timestamps = True
timestamps.append(float(dt.timestamp()))
# If no conversion is needed, keep the initial timestamps
if not convert_timestamps:
timestamps = datetimes
return timestamps
def metrics_plot(self) -> str:
timestamps, metric_lists = zip(*self.scheduler_metrics)
datetimes, metric_lists = zip(*self.scheduler_metrics)
timestamps = self._convert_timestamps(datetimes)
known = [sum(m.origins_known for m in metrics) for metrics in metric_lists]
never_visited = [
sum(m.origins_never_visited for m in metrics) for metrics in metric_lists
......@@ -87,10 +103,13 @@ class SimulationReport:
figure = plotille.Figure()
figure.x_label = "simulated time"
figure.y_label = "origins"
figure.scatter(timestamps, known, label="Known origins")
figure.scatter(timestamps, never_visited, label="Origins never visited")
visit_timestamps, n_visits = zip(*self.visit_metrics)
visit_datetimes, n_visits = zip(*self.visit_metrics)
visit_timestamps = self._convert_timestamps(visit_datetimes)
figure.scatter(visit_timestamps, n_visits, label="Visits over time")
return figure.show(legend=True)
......
......@@ -22,8 +22,11 @@ def scheduler_runner_process(
task_queues: Dict[str, Queue],
min_batch_size: int,
) -> Iterator[Event]:
"""Scheduler runner. Grabs next visits from the database according to the
scheduling policy, and fills the task_queues accordingly."""
"""Simulate a scheduler runner process. This schedules tasks from the database
according to the scheduling policy, that means filling the task_queues first, then
update their status in the scheduler backend.
"""
while True:
for visit_type, queue in task_queues.items():
......@@ -49,6 +52,8 @@ def scheduler_runner_process(
for sim_task in sim_tasks:
yield queue.put(sim_task)
env.timeout(0.1)
# Then mark the sent tasks as scheduled
env.scheduler.mass_schedule_task_runs(
[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment