1
0
Fork 0

feat(api): load-balance background jobs between devices

This commit is contained in:
Sean Sube 2023-02-04 16:22:50 -06:00
parent 7c96145397
commit efee374c16
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 7 additions and 4 deletions

View File

@ -1,3 +1,4 @@
from collections import Counter
from concurrent.futures import Future, ThreadPoolExecutor, ProcessPoolExecutor
from logging import getLogger
from multiprocessing import Value
@ -134,9 +135,11 @@ class DevicePoolExecutor:
return (None, 0)
def get_next_device(self):
device = self.next_device
self.next_device = (self.next_device + 1) % len(self.devices)
return device
job_devices = [job.context.device_index.value for job in self.jobs]
queued = Counter(job_devices).most_common()
logger.debug('jobs queued by device: %s', queued)
return queued[-1]
def prune(self):
self.jobs[:] = [job for job in self.jobs if job.future.done()]

View File

@ -1,5 +1,5 @@
{
"version": "0.5.0",
"version": "0.6.0",
"bottom": {
"default": 0,
"min": 0,