From dbf2360ce1edc6e310536b5ebbcffb819fd3aa8b Mon Sep 17 00:00:00 2001 From: JinZhou5042 Date: Wed, 5 Feb 2025 13:52:21 -0500 Subject: [PATCH] remove from the data structure --- taskvine/src/manager/vine_manager.c | 32 ---------------- taskvine/src/manager/vine_schedule.c | 50 ++++++++++++++++++++++--- taskvine/src/manager/vine_worker_info.c | 1 - taskvine/src/manager/vine_worker_info.h | 1 - 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/taskvine/src/manager/vine_manager.c b/taskvine/src/manager/vine_manager.c index f2a6eb2f0e..3f9e0c0a97 100644 --- a/taskvine/src/manager/vine_manager.c +++ b/taskvine/src/manager/vine_manager.c @@ -2835,36 +2835,6 @@ static vine_result_code_t start_one_task(struct vine_manager *q, struct vine_wor return result; } -/* Check if any of the resources is overcommitted on a given worker. */ -static int is_resource_committable(struct vine_manager *q, struct vine_resource resource) -{ - return resource.inuse < overcommitted_resource_total(q, resource.total); -} -static int worker_has_free_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) - { - if (t->function_slots_inuse < t->function_slots_total) { - return 1; - } - } - - /* If both memory and disk are committable */ - if (is_resource_committable(q, w->resources->memory) && is_resource_committable(q, w->resources->disk)) { - /* Return true if either cores or GPUs are defined and committable. */ - if ((w->resources->cores.total > 0 && is_resource_committable(q, w->resources->cores)) || - (w->resources->gpus.total > 0 && is_resource_committable(q, w->resources->gpus))) { - return 1; - } - } - - /* If reach here, no free resources on this worker */ - return 0; -} - static void count_worker_resources(struct vine_manager *q, struct vine_worker_info *w) { w->resources->cores.inuse = 0; @@ -2902,8 +2872,6 @@ static void count_worker_resources(struct vine_manager *q, struct vine_worker_in } w->resources->disk.inuse += ceil(BYTES_TO_MEGABYTES(w->inuse_cache)); - - w->has_free_resources = worker_has_free_resources(q, w); } static void update_max_worker(struct vine_manager *q, struct vine_worker_info *w) diff --git a/taskvine/src/manager/vine_schedule.c b/taskvine/src/manager/vine_schedule.c index 089949e058..8033d449b9 100644 --- a/taskvine/src/manager/vine_schedule.c +++ b/taskvine/src/manager/vine_schedule.c @@ -137,6 +137,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) +{ + 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) + { + 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. @@ -156,11 +196,6 @@ int check_worker_against_task(struct vine_manager *q, struct vine_worker_info *w return 0; } - /* if worker has free resources to use */ - if (!w->has_free_resources) { - return 0; - } - /* Don't send tasks to this worker if it is in draining mode (no more tasks). */ if (w->draining) { return 0; @@ -189,6 +224,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); diff --git a/taskvine/src/manager/vine_worker_info.c b/taskvine/src/manager/vine_worker_info.c index cd0523887b..fef94e8b97 100644 --- a/taskvine/src/manager/vine_worker_info.c +++ b/taskvine/src/manager/vine_worker_info.c @@ -28,7 +28,6 @@ struct vine_worker_info *vine_worker_create(struct link *lnk) w->version = strdup("unknown"); w->factory_name = 0; w->workerid = 0; - w->has_free_resources = 0; w->resources = vine_resources_create(); w->features = hash_table_create(4, 0); diff --git a/taskvine/src/manager/vine_worker_info.h b/taskvine/src/manager/vine_worker_info.h index 05300dea90..e7e67122ad 100644 --- a/taskvine/src/manager/vine_worker_info.h +++ b/taskvine/src/manager/vine_worker_info.h @@ -73,7 +73,6 @@ struct vine_worker_info { int64_t total_bytes_transferred; int forsaken_tasks; int64_t inuse_cache; - int has_free_resources; timestamp_t total_task_time; timestamp_t total_transfer_time;