From 60ad6799d8a67a955fd0d96786365aa901f45899 Mon Sep 17 00:00:00 2001 From: NamelessOIer <70872016+NamelessOIer@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:51:30 +0800 Subject: [PATCH] optimize efficiency --- src/CraneCtld/TaskScheduler.cpp | 5 ++--- src/CraneCtld/TaskScheduler.h | 12 ++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/CraneCtld/TaskScheduler.cpp b/src/CraneCtld/TaskScheduler.cpp index 0047d046..6ee30e37 100644 --- a/src/CraneCtld/TaskScheduler.cpp +++ b/src/CraneCtld/TaskScheduler.cpp @@ -2130,11 +2130,10 @@ bool MinLoadFirst::CalculateRunningNodesAndStartTime_( pq.pop(); if (tracker->satisfied()) { satisfied_trackers.try_push_back(tracker, time); + if (tracker->genNextUnsatisfied()) pq.emplace(tracker); } else { satisfied_trackers.try_erase(tracker); - } - if (tracker->genNext()) { - pq.emplace(tracker); + if (tracker->genNextSatisfied()) pq.emplace(tracker); } } if (pq.empty() || satisfied_trackers.kth_time() + task->time_limit <= diff --git a/src/CraneCtld/TaskScheduler.h b/src/CraneCtld/TaskScheduler.h index 1212d526..305c6cbd 100644 --- a/src/CraneCtld/TaskScheduler.h +++ b/src/CraneCtld/TaskScheduler.h @@ -141,7 +141,7 @@ class MinLoadFirst : public INodeSelectionAlgo { private: static constexpr bool kAlgoTraceOutput = false; - static constexpr bool kAlgoRedundantNode = true; + static constexpr bool kAlgoRedundantNode = false; static constexpr uint32_t kAlgoMaxTaskNumPerNode = 1000; static constexpr absl::Duration kAlgoMaxTimeWindow = absl::Hours(24 * 7); @@ -175,7 +175,15 @@ class MinLoadFirst : public INodeSelectionAlgo { bool satisfied() const { return *task_res <= it->second; } - bool genNext() { return ++it != end; } + bool genNextUnsatisfied() { + while (++it != end && satisfied()); + return it != end; + } + + bool genNextSatisfied() { + while (++it != end && !satisfied()); + return it != end; + } }; struct TrackerList {