builders: Rework least loaded worker finding in nextWorker()

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
This commit is contained in:
Mathieu Dubois-Briand 2025-03-07 15:02:15 +01:00 committed by Richard Purdie
parent 776469c3ae
commit ea0077dce7

View File

@ -178,25 +178,16 @@ def nextWorker(bldr, workers, buildrequest):
[resultspec.Filter('complete', 'eq', [False])], [resultspec.Filter('complete', 'eq', [False])],
) )
active = {} active = {worker.worker.workerid: 0 for worker in possible_workers}
maxbuilds = 0
for build in builds: for build in builds:
if build['workerid'] not in active: if build['workerid'] in active:
active[build['workerid']] = 1
else:
active[build['workerid']] += 1 active[build['workerid']] += 1
if maxbuilds > active[build['workerid']]: least_actives = [k for k, v in active.items() if v == min(active.values())]
maxbuilds = active[build['workerid']]
random.shuffle(possible_workers) possible_workers = [worker for worker in possible_workers
if worker.worker.workerid in least_actives]
for worker in possible_workers: if possible_workers:
if worker.worker.workerid not in active: return random.choice(possible_workers)
return worker
for i in range(maxbuilds):
for worker in possible_workers:
if active[worker.worker.workerid] == i:
return worker
return None return None
for w in possible_workers: for w in possible_workers: