summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2019-12-06 10:50:35 +0000
committerBenjamin Schubert <contact@benschubert.me>2019-12-07 17:25:21 +0000
commita1bd91bc8ec40e41d68a31a25b93b819b689442d (patch)
treeeaa0ac7b3325e21f03007ad19e67c5aaf613a3a3
parent454ed339046129b88b6300a3401d99a8e2f832dd (diff)
downloadbuildstream-a1bd91bc8ec40e41d68a31a25b93b819b689442d.tar.gz
scheduler.py: Optimize scheduling by not calling it unnecessarily
This delays the call to the re-scheduling of jobs until the current event loop as terminated. This is in order to reduce the number of time we call this method per loop, which should reduce the pressure on the loop and allow faster event handling Since the call is now delayed, also ensure we only call it once per loop iteration.
-rw-r--r--src/buildstream/_scheduler/scheduler.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py
index 80bd9fb50..d9a0984da 100644
--- a/src/buildstream/_scheduler/scheduler.py
+++ b/src/buildstream/_scheduler/scheduler.py
@@ -1,5 +1,6 @@
#
# Copyright (C) 2016 Codethink Limited
+# Copyright (C) 2019 Bloomberg Finance LP
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -142,6 +143,8 @@ class Scheduler:
self._state = state
self._casd_process = None # handle to the casd process for monitoring purpose
+ self._sched_handle = None # Whether a scheduling job is already scheduled or not
+
# Bidirectional queue to send notifications back to the Scheduler's owner
self._notification_queue = notification_queue
self._notifier = notifier
@@ -431,20 +434,26 @@ class Scheduler:
# going back to sleep.
#
def _sched(self):
+ def real_schedule():
+ if not self.terminated:
+
+ #
+ # Run as many jobs as the queues can handle for the
+ # available resources
+ #
+ self._sched_queue_jobs()
- if not self.terminated:
+ # Reset the scheduling hand
+ self._sched_handle = None
#
- # Run as many jobs as the queues can handle for the
- # available resources
+ # If nothing is ticking then bail out
#
- self._sched_queue_jobs()
+ if not self._active_jobs:
+ self.loop.stop()
- #
- # If nothing is ticking then bail out
- #
- if not self._active_jobs:
- self.loop.stop()
+ if self._sched_handle is None:
+ self._sched_handle = self.loop.call_soon(real_schedule)
# _suspend_jobs()
#