Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vine: check worker has committable resources #4039

46 changes: 46 additions & 0 deletions taskvine/src/manager/vine_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,46 @@ int check_worker_have_enough_disk_with_inputs(struct vine_manager *q, struct vin
return ok;
}

/* Check if any of the resources is defined and committable on a given worker.
* @param q Manager info structure
* @param resource @vine_resources.h:struct vine_resources
* @return 1 if the resource type is defined and can be allocated to a task, 0 otherwise.
*/
static int is_resource_committable(struct vine_manager *q, struct vine_resource resource)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are unnecessarily copying the struct vine_resource data. In this case, I think it will be clearer if you do the resource.total > 0 && resource.inuse < overcommitted_resource_total(q, resource.total); per resource inside check_worker_have_committable_resources.

{
return resource.total > 0 && resource.inuse < overcommitted_resource_total(q, resource.total);
}

/* Check if this worker has committable resources for any type of task.
* If it returns false, neither a function task, library task nor a regular task can run on this worker.
* If it returns true, the worker has either free slots for function calls or sufficient resources for regular tasks.
* @param q Manager info structure
* @param w The worker info structure.
*/
static int check_worker_have_committable_resources(struct vine_manager *q, struct vine_worker_info *w)
{
/* If any slots are committable */
uint64_t task_id;
struct vine_task *t;
ITABLE_ITERATE(w->current_libraries, task_id, t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe first check that itable_size > 0 before setting the iteration?

{
if (t->function_slots_inuse < t->function_slots_total) {
return 1;
}
}

/* A regular task has to use both memory and disk */
if (is_resource_committable(q, w->resources->memory) && is_resource_committable(q, w->resources->disk)) {
/* If either cores or gpus are committable. */
if (is_resource_committable(q, w->resources->cores) || is_resource_committable(q, w->resources->gpus)) {
return 1;
}
}

/* If reach here, no free resources on this worker */
return 0;
}

/* Check if this task is compatible with this given worker by considering
* resources availability, features, blocklist, and all other relevant factors.
* Used by all scheduling methods for basic compatibility.
Expand All @@ -172,6 +212,7 @@ int check_worker_against_task(struct vine_manager *q, struct vine_worker_info *w
if (w->draining) {
return 0;
}

// if worker's end time has not been received
if (w->end_time < 0) {
return 0;
Expand All @@ -195,6 +236,11 @@ int check_worker_against_task(struct vine_manager *q, struct vine_worker_info *w
return 0;
}

/* if worker has free resources to use */
if (!check_worker_have_committable_resources(q, w)) {
return 0;
}

/* Compute the resources to allocate to this task. */
struct rmsummary *l = vine_manager_choose_resources_for_task(q, w, t);

Expand Down