Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1717)

Unified Diff: scripts/master/master_utils.py

Issue 2427413005: Improve slave-preference function (Closed)
Patch Set: Presubmit Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | scripts/master/unittests/master_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/master/master_utils.py
diff --git a/scripts/master/master_utils.py b/scripts/master/master_utils.py
index 5c6f6bb88798abfd1a58edd2154c626f181baa7d..ab516a83a44dca76fc7b83e4851030a98562d713 100644
--- a/scripts/master/master_utils.py
+++ b/scripts/master/master_utils.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import collections
import os
import random
import re
@@ -669,6 +670,45 @@ class PreferredBuilderNextSlaveFunc(object):
return random.choice(preferred_slaves or slave_builders)
+class PreferredBuilderNextSlaveFuncNG(object):
+ """
+ This object, when used as a Builder's 'nextSlave' function, will choose
+ a slave whose 'preferred_builder' value is the same as the builder
+ name. If there is no such slave, a slave is randomly chosen that doesn't
+ prefer any builder. If there is no such slave, a slave is randomly
+ chosen with preference on slaves whose preferred builder has largest
+ currently available capacity. If several sets of slaves have equally large
+ capacity, a set is chosen arbitrarily dependent on internal dictionary order.
+ """
+
+ def __init__(self, choice=random.choice):
+ # Allow overriding the choice function for testability.
+ self._choice = choice
+
+ def __call__(self, builder, slave_builders):
+ if not slave_builders:
+ return None
+
+ prefs = collections.Counter(
+ s.slave.properties.getProperty('preferred_builder')
+ for s in slave_builders)
+ if builder.name in prefs:
+ # First choice: Slaves that prefer this builder.
+ key = builder.name
+ elif None in prefs:
+ # Second choice: Slaves that don't prefer any builders.
+ key = None
+ else:
+ # Third choice: Slaves that prefer other builders but have largest
+ # capacity left. If several groups of slaves with equal capacity exist,
+ # one group will be chosen arbitrarily, the actual slave will be chosen
+ # randomly.
+ key = prefs.most_common()[0][0]
+ return self._choice(
+ s for s in slave_builders
+ if s.slave.properties.getProperty('preferred_builder') == key)
+
+
def SetMasterProcessName():
"""Sets the name of this process to the name of the master. Linux only."""
« no previous file with comments | « no previous file | scripts/master/unittests/master_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698