Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessOIer committed Oct 18, 2024
1 parent dd60dcb commit 842a45b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions build/_deps/backward-src
Submodule backward-src added at 51f070
1 change: 1 addition & 0 deletions build/_deps/fpm-src
Submodule fpm-src added at 464cf6
1 change: 1 addition & 0 deletions build/_deps/libuv-src
Submodule libuv-src added at f0bb7e
26 changes: 20 additions & 6 deletions src/CraneCtld/TaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,6 @@ void MinLoadFirst::CalculateNodeSelectionInfoOfPartition_(
// Sort all running task in this node by ending time.
std::vector<std::pair<absl::Time, uint32_t>> end_time_task_id_vec;

std::vector<std::string> running_task_ids_str;
for (const auto& [task_id, res] : craned_meta->running_task_resource_map) {
const auto& task = running_tasks.at(task_id);

Expand All @@ -1867,8 +1866,14 @@ void MinLoadFirst::CalculateNodeSelectionInfoOfPartition_(
absl::Time end_time = std::max(task->StartTime() + task->time_limit,
now + absl::Seconds(1));
end_time_task_id_vec.emplace_back(end_time, task_id);
}

running_task_ids_str.emplace_back(std::to_string(task_id));
if constexpr (kAlgoTraceOutput) {
std::string running_task_ids_str;
for (const auto& [end_time, task_id] : end_time_task_id_vec)
running_task_ids_str.append(fmt::format("{}, ", task_id));
CRANE_TRACE("Craned node {} has running tasks: {}", craned_id,
running_task_ids_str);
}

std::sort(
Expand All @@ -1888,8 +1893,8 @@ void MinLoadFirst::CalculateNodeSelectionInfoOfPartition_(
}
}

// Calculate delta resources at [now, first task end,
// second task end, ...] in this node.
// Calculate how many resources are available at [now, first task end,
// second task end, ...] in this node.
auto& time_avail_res_map =
node_selection_info_ref.node_time_avail_res_map[craned_id];
node_selection_info_ref.node_res_total_map[craned_id] =
Expand Down Expand Up @@ -1927,6 +1932,16 @@ void MinLoadFirst::CalculateNodeSelectionInfoOfPartition_(
*/
std::tie(cur_time_iter, ok) =
time_avail_res_map.emplace(end_time, cur_time_iter->second);

if constexpr (kAlgoTraceOutput) {
CRANE_TRACE(
"Insert duration [now+{}s, inf) with resource: "
"cpu: {}, mem: {}, gres: {}",
absl::ToInt64Seconds(end_time - now),
craned_meta->res_avail.allocatable_res.cpu_count,
craned_meta->res_avail.allocatable_res.memory_bytes,
util::ReadableDresInNode(craned_meta->res_avail));
}
}

/**
Expand Down Expand Up @@ -2454,8 +2469,7 @@ CraneErr TaskScheduler::AcquireTaskAttributes(TaskInCtld* task) {
task_mem_per_cpu = part_meta.default_mem_per_cpu;
} else if (part_meta.max_mem_per_cpu != 0) {
// If a task sets its memory bytes,
// check if memory/core ratio is greater than the partition's maximum
// value.
// check if memory/core ratio is greater than the partition's maximum value.
task_mem_per_cpu =
std::min(task_mem_per_cpu, (double)part_meta.max_mem_per_cpu);
}
Expand Down
3 changes: 1 addition & 2 deletions src/CraneCtld/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ class TaskScheduler {

void TerminateTasksOnCraned(const CranedId& craned_id, uint32_t exit_code);

// Temporary inconsistency may happen. If 'false' is returned, just ignore
// it.
// Temporary inconsistency may happen. If 'false' is returned, just ignore it.
void QueryTasksInRam(const crane::grpc::QueryTasksInfoRequest* request,
crane::grpc::QueryTasksInfoReply* response);

Expand Down

0 comments on commit 842a45b

Please sign in to comment.