Skip to content

Commit

Permalink
buildrequestdistributor: Sort pending builders only once
Browse files Browse the repository at this point in the history
Sorting pending builder each time the list is updated is unnecessary overhead.
This can be done once the list is passed on to BuildRequestDistributor._activityLoop.
  • Loading branch information
vibbo committed Apr 16, 2024
1 parent d4e7aaa commit 01cfbab
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions master/buildbot/process/buildrequestdistributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,14 @@ def maybeStartBuildsOn(self, new_builders):

@defer.inlineCallbacks
def _maybeStartBuildsOn(self, new_builders):
new_builders = set(new_builders)
existing_pending = set(self._pending_builders)

# if we won't add any builders, there's nothing to do
if new_builders < existing_pending:
# if we won't add any new builders, there's nothing to do
if set(new_builders) < set(self._pending_builders):
return None

# reset the list of pending builders
@defer.inlineCallbacks
def resetPendingBuildersList(new_builders):
try:
# re-fetch existing_pending, in case it has changed
# while acquiring the lock
existing_pending = set(self._pending_builders)

# then sort the new, expanded set of builders
self._pending_builders = yield self._sortBuilders(
list(existing_pending | new_builders)
)
self._pending_builders = list(set(self._pending_builders + new_builders))

# start the activity loop, if we aren't already
# working on that.
Expand Down Expand Up @@ -436,12 +425,14 @@ def _activityLoop(self):
self.pending_builders_lock.release()
self.activity_lock.release()
break
# take that builder list, and run it until the end
# take that builder list, sort it and run it until the end
# we make a copy of it, as it could be modified meanwhile
pending_builders = copy.copy(self._pending_builders)
self._pending_builders = []
self.pending_builders_lock.release()

pending_builders = yield self._sortBuilders(pending_builders)

bldr_name = pending_builders.pop(0)

# get the actual builder object
Expand Down

0 comments on commit 01cfbab

Please sign in to comment.