diff --git a/src/mock/ray/gcs/gcs_server/gcs_resource_scheduler.h b/src/mock/ray/gcs/gcs_server/gcs_resource_scheduler.h deleted file mode 100644 index e354d7aa4362b..0000000000000 --- a/src/mock/ray/gcs/gcs_server/gcs_resource_scheduler.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright The Ray Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ray { -namespace gcs { - -class MockNodeScorer : public NodeScorer { - public: - MOCK_METHOD(double, - Score, - (const ResourceRequest &required_resources, - const SchedulingResources &node_resources), - (override)); -}; - -} // namespace gcs -} // namespace ray - -namespace ray { -namespace gcs { - -class MockLeastResourceScorer : public LeastResourceScorer { - public: - MOCK_METHOD(double, - Score, - (const ResourceRequest &required_resources, - const SchedulingResources &node_resources), - (override)); -}; - -} // namespace gcs -} // namespace ray - -namespace ray { -namespace gcs { - -class MockGcsResourceScheduler : public GcsResourceScheduler { - public: -}; - -} // namespace gcs -} // namespace ray diff --git a/src/ray/common/task/scheduling_resources.cc b/src/ray/common/task/scheduling_resources.cc index 34e1797494bba..384a5f9b9bbfa 100644 --- a/src/ray/common/task/scheduling_resources.cc +++ b/src/ray/common/task/scheduling_resources.cc @@ -250,109 +250,4 @@ const absl::flat_hash_map &ResourceSet::GetResourceAmou return resource_capacity_; }; -/// SchedulingResources class implementation - -SchedulingResources::SchedulingResources() - : resources_total_(ResourceSet()), - resources_available_(ResourceSet()), - resources_load_(ResourceSet()) {} - -SchedulingResources::SchedulingResources(const ResourceSet &total) - : resources_total_(total), - resources_available_(total), - resources_load_(ResourceSet()) {} - -SchedulingResources::~SchedulingResources() {} - -const ResourceSet &SchedulingResources::GetAvailableResources() const { - return resources_available_; -} - -void SchedulingResources::SetAvailableResources(ResourceSet &&newset) { - resources_available_ = newset; -} - -const ResourceSet &SchedulingResources::GetTotalResources() const { - return resources_total_; -} - -void SchedulingResources::SetTotalResources(ResourceSet &&newset) { - resources_total_ = newset; -} - -const ResourceSet &SchedulingResources::GetLoadResources() const { - return resources_load_; -} - -void SchedulingResources::SetLoadResources(ResourceSet &&newset) { - resources_load_ = newset; -} - -// Return specified resources back to SchedulingResources. -void SchedulingResources::Release(const ResourceSet &resources) { - return resources_available_.AddResourcesCapacityConstrained(resources, - resources_total_); -} - -// Take specified resources from SchedulingResources. -void SchedulingResources::Acquire(const ResourceSet &resources) { - resources_available_.SubtractResourcesStrict(resources); -} - -// The reason we need this method is sometimes we may want add some converted -// resource which is not exist in total resource to the available resource. -// (e.g., placement group) -void SchedulingResources::AddResource(const ResourceSet &resources) { - resources_total_.AddResources(resources); - resources_available_.AddResources(resources); -} - -void SchedulingResources::UpdateResourceCapacity(const std::string &resource_name, - int64_t capacity) { - const FixedPoint new_capacity = FixedPoint(capacity); - const FixedPoint ¤t_capacity = resources_total_.GetResource(resource_name); - if (current_capacity > 0) { - // If the resource exists, add to total and available resources - const FixedPoint capacity_difference = new_capacity - current_capacity; - const FixedPoint ¤t_available_capacity = - resources_available_.GetResource(resource_name); - FixedPoint new_available_capacity = current_available_capacity + capacity_difference; - if (new_available_capacity < 0) { - new_available_capacity = 0; - } - resources_total_.AddOrUpdateResource(resource_name, new_capacity); - resources_available_.AddOrUpdateResource(resource_name, new_available_capacity); - } else { - // Resource does not exist, just add it to total and available. Do not add to load. - resources_total_.AddOrUpdateResource(resource_name, new_capacity); - resources_available_.AddOrUpdateResource(resource_name, new_capacity); - } -} - -void SchedulingResources::DeleteResource(const std::string &resource_name) { - resources_total_.DeleteResource(resource_name); - resources_available_.DeleteResource(resource_name); - resources_load_.DeleteResource(resource_name); -} - -const ResourceSet &SchedulingResources::GetNormalTaskResources() const { - return resources_normal_tasks_; -} - -void SchedulingResources::SetNormalTaskResources(const ResourceSet &newset) { - resources_normal_tasks_ = newset; -} - -std::string SchedulingResources::DebugString() const { - std::stringstream result; - - auto resources_available = resources_available_; - resources_available.SubtractResources(resources_normal_tasks_); - - result << "\n- total: " << resources_total_.ToString(); - result << "\n- avail: " << resources_available.ToString(); - result << "\n- normal task usage: " << resources_normal_tasks_.ToString(); - return result.str(); -}; - } // namespace ray diff --git a/src/ray/common/task/scheduling_resources.h b/src/ray/common/task/scheduling_resources.h index 07fb240a22af6..a6669f668351e 100644 --- a/src/ray/common/task/scheduling_resources.h +++ b/src/ray/common/task/scheduling_resources.h @@ -177,117 +177,6 @@ class ResourceSet { absl::flat_hash_map resource_capacity_; }; -/// \class SchedulingResources -/// SchedulingResources class encapsulates the state of all local resources and -/// manages accounting of those resources. Resources include configured resource -/// bundle capacity, and GPU allocation map. -class SchedulingResources { - public: - /// SchedulingResources constructor: sets configured and available resources - /// to an empty set. - SchedulingResources(); - - /// SchedulingResources constructor: sets available and configured capacity - /// to the resource set specified. - /// - /// \param total: The amount of total configured capacity. - SchedulingResources(const ResourceSet &total); - - /// \brief SchedulingResources destructor. - ~SchedulingResources(); - - /// \brief Request the set and capacity of resources currently available. - /// - /// \return Immutable set of resources with currently available capacity. - const ResourceSet &GetAvailableResources() const; - - /// \brief Overwrite available resource capacity with the specified resource set. - /// - /// \param newset: The set of resources that replaces available resource capacity. - /// \return Void. - void SetAvailableResources(ResourceSet &&newset); - - /// \brief Request the total resources capacity. - /// - /// \return Immutable set of resources with currently total capacity. - const ResourceSet &GetTotalResources() const; - - /// \brief Overwrite total resource capacity with the specified resource set. - /// - /// \param newset: The set of resources that replaces total resource capacity. - /// \return Void. - void SetTotalResources(ResourceSet &&newset); - - /// \brief Request the resource load information. - /// - /// \return Immutable set of resources describing the load information. - const ResourceSet &GetLoadResources() const; - - /// \brief Overwrite information about resource load with new resource load set. - /// - /// \param newset: The set of resources that replaces resource load information. - /// \return Void. - void SetLoadResources(ResourceSet &&newset); - - /// \brief Release the amount of resources specified. - /// - /// \param resources: the amount of resources to be released. - /// \return Void. - void Release(const ResourceSet &resources); - - /// \brief Acquire the amount of resources specified. - /// - /// \param resources: the amount of resources to be acquired. - /// \return Void. - void Acquire(const ResourceSet &resources); - - /// \brief Add a new resource to available resource. - /// - /// \param resources: the amount of resources to be added. - /// \return Void. - void AddResource(const ResourceSet &resources); - - /// Returns debug string for class. - /// - /// \return string. - std::string DebugString() const; - - /// \brief Update total, available and load resources with the specified capacity. - /// Create if not exists. - /// - /// \param resource_name: Name of the resource to be modified - /// \param capacity: New capacity of the resource. - /// \return Void. - void UpdateResourceCapacity(const std::string &resource_name, int64_t capacity); - - /// \brief Delete resource from total, available and load resources. - /// - /// \param resource_name: Name of the resource to be deleted. - /// \return Void. - void DeleteResource(const std::string &resource_name); - - /// \brief Get the resources used by normal tasks. - /// - /// \return Resources used by normal tasks. - const ResourceSet &GetNormalTaskResources() const; - - /// \brief Set the amount of resources used by normal tasks. - /// - /// \param newset: The new resource set to update. - /// \return Void. - void SetNormalTaskResources(const ResourceSet &newset); - - private: - /// Static resource configuration (e.g., static_resources). - ResourceSet resources_total_; - /// Dynamic resource capacity (e.g., dynamic_resources). - ResourceSet resources_available_; - /// Resource load. - ResourceSet resources_load_; - /// Resources used by normal tasks. - ResourceSet resources_normal_tasks_; -}; - std::string format_resource(std::string resource_name, double quantity); } // namespace ray