diff --git a/src/CraneCtld/TaskScheduler.cpp b/src/CraneCtld/TaskScheduler.cpp index a258ce25..a76a8231 100644 --- a/src/CraneCtld/TaskScheduler.cpp +++ b/src/CraneCtld/TaskScheduler.cpp @@ -2007,6 +2007,15 @@ bool MinLoadFirst::CalculateRunningNodesAndStartTime_( } auto& time_avail_res_map = node_selection_info.node_time_avail_res_map.at(craned_index); + // Number of tasks is not less than map size. + // When condition is true, the craned has too many tasks. + if (time_avail_res_map.size() >= kAlgoMaxTaskNumPerNode) { + if constexpr (kAlgoTraceOutput) { + CRANE_TRACE("Craned {} has too many tasks. Skipping this craned.", + craned_index); + } + continue; + } auto craned_meta = craned_meta_map.at(craned_index).GetExclusivePtr(); // If any of the follow `if` is true, skip this node. @@ -2084,6 +2093,9 @@ bool MinLoadFirst::CalculateRunningNodesAndStartTime_( absl::Time last_time = absl::InfinitePast(); while (!pq.empty()) { absl::Time time = pq.top()->it->first; + if (time - now > kAlgoMaxTimeWindow) { + return false; + } while (!pq.empty() && pq.top()->it->first == time) { auto tmp = pq.top(); pq.pop(); diff --git a/src/CraneCtld/TaskScheduler.h b/src/CraneCtld/TaskScheduler.h index 4c1c2e91..3cd0fd77 100644 --- a/src/CraneCtld/TaskScheduler.h +++ b/src/CraneCtld/TaskScheduler.h @@ -18,6 +18,8 @@ #pragma once +#include + #include "CtldPublicDefs.h" // Precompiled header comes first! @@ -144,6 +146,8 @@ class MinLoadFirst : public INodeSelectionAlgo { private: static constexpr bool kAlgoTraceOutput = false; static constexpr bool kAlgoRedundantNode = true; + static constexpr uint32_t kAlgoMaxTaskNumPerNode = 1000; + static constexpr absl::Duration kAlgoMaxTimeWindow = absl::Hours(24 * 7); /** * This map stores how much resource is available