Commit d9d9785e authored by Igor Ponomarev's avatar Igor Ponomarev Committed by Paweł Wieczorek
Browse files

Schedule jobs for all device type simultaneously

Improves performance because it avoids extra queries for
different device types.

Comparison:

Before: 10010766 function calls (9764524 primitive calls) in 4.330 seconds

After: 9476569 function calls (9237052 primitive calls) in 3.910 seconds

Upstream MR: https://git.lavasoftware.org/lava/lava/-/merge_requests/1769
parent 65eba530
......@@ -250,21 +250,14 @@ def schedule_health_check(device, definition):
def schedule_jobs(logger, available_devices, workers):
logger.info("scheduling jobs:")
dts = list(available_devices.keys())
for dt in DeviceType.objects.filter(name__in=dts).order_by("name"):
with transaction.atomic():
schedule_jobs_for_device_type(
logger, dt, available_devices[dt.name], workers
)
with transaction.atomic():
# Transition multinode if needed
transition_multinode_jobs(logger)
logger.info("done")
def schedule_jobs_for_device_type(logger, dt, available_devices, workers):
devices = dt.device_set.select_for_update()
# Check that the device had been marked available by
# schedule_health_checks. In fact, it's possible that a device is made
# IDLE between the two functions.
# If that the case, we can miss an health-check. Better to only
# consider devices in available_devices.
dts_query = DeviceType.objects.filter(name__in=dts).order_by("name")
devices = Device.objects.filter(device_type__in=dts_query).select_for_update()
devices = filter_devices(devices, workers)
devices = devices.filter(health__in=[Device.HEALTH_GOOD, Device.HEALTH_UNKNOWN])
# Add a random sort: with N devices and num(jobs) < N, if we don't sort
......@@ -272,18 +265,21 @@ def schedule_jobs_for_device_type(logger, dt, available_devices, workers):
# never be used.
devices = devices.order_by("?")
with transaction.atomic():
schedule_jobs_for_all_device_type(logger, devices, workers)
with transaction.atomic():
# Transition multinode if needed
transition_multinode_jobs(logger)
logger.info("done")
def schedule_jobs_for_all_device_type(logger, devices, workers):
workers_limit = worker_summary()
print_header = True
for device in devices:
# Check that the device had been marked available by
# schedule_health_checks. In fact, it's possible that a device is made
# IDLE between the two functions.
# If that the case, we can miss an health-check. Better to only
# consider devices in available_devices.
if device.hostname not in available_devices:
continue
if workers_limit[device.worker_host.hostname].overused():
logger.debug(
"SKIP %s due to %s having %d jobs (greater than %d)"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment