diff options
author | Benjamin Schubert <bschubert15@bloomberg.net> | 2019-12-06 10:50:35 +0000 |
---|---|---|
committer | Benjamin Schubert <bschubert15@bloomberg.net> | 2019-12-06 10:50:35 +0000 |
commit | 68323e10516b0a6758fd4ed5e07ded6af17c258b (patch) | |
tree | 1ec879066613747910e022c5148d13570c19f8b1 | |
parent | 454ed339046129b88b6300a3401d99a8e2f832dd (diff) | |
download | buildstream-bschubert/optimize-scheduling.tar.gz |
scheduler.py: Optimize scheduling by not calling it unnecessarilybschubert/optimize-scheduling
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 shoudl 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.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py index 80bd9fb50..37a14c103 100644 --- a/src/buildstream/_scheduler/scheduler.py +++ b/src/buildstream/_scheduler/scheduler.py @@ -142,6 +142,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 +433,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() # |