summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-12-07 18:16:17 +0000
committerBenjamin Schubert <contact@benschubert.me>2019-12-07 18:16:17 +0000
commit0e4cbd55020d835782bb42d6e543d489d6ea0924 (patch)
treeeaa0ac7b3325e21f03007ad19e67c5aaf613a3a3
parent454ed339046129b88b6300a3401d99a8e2f832dd (diff)
parenta1bd91bc8ec40e41d68a31a25b93b819b689442d (diff)
downloadbuildstream-0e4cbd55020d835782bb42d6e543d489d6ea0924.tar.gz
Merge branch 'bschubert/optimize-scheduling' into 'master'
scheduler.py: Optimize scheduling by not calling it unnecessarily See merge request BuildStream/buildstream!1755
-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()
#