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 dd2dba8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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
4 changes: 1 addition & 3 deletions src/CraneCtld/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class MinLoadFirst : public INodeSelectionAlgo {
* In time interval [y, z-1], the amount of available resources is b.
* In time interval [z, ...], the amount of available resources is c.
*/

using TimeAvailResMap = std::map<absl::Time, ResourceInNode>;
struct TimeAvailResTracker {
const CranedId craned_id;
Expand Down Expand Up @@ -337,8 +336,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 dd2dba8

Please sign in to comment.