// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you 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. #pragma once #include #include #include #include #include #include #include #include "resource/Resource.h" #include "utils/Log.h" namespace milvus { namespace scheduler { class ResourceMgr { public: ResourceMgr() = default; public: /******** Management Interface ********/ void Start(); void Stop(); ResourceWPtr Add(ResourcePtr&& resource); bool Connect(const std::string& name1, const std::string& name2, Connection& connection); void Clear(); inline void RegisterSubscriber(std::function subscriber) { subscriber_ = std::move(subscriber); } public: /******** Management Interface ********/ inline std::vector& GetDiskResources() { return disk_resources_; } // TODO(wxy): why return shared pointer inline std::vector GetAllResources() { return resources_; } std::vector GetComputeResources(); ResourcePtr GetResource(ResourceType type, uint64_t device_id); ResourcePtr GetResource(const std::string& name); uint64_t GetNumOfResource() const; uint64_t GetNumOfComputeResource() const; uint64_t GetNumGpuResource() const; public: // TODO(wxy): add stats interface(low) public: /******** Utility Functions ********/ std::string Dump(); std::string DumpTaskTables(); private: void post_event(const EventPtr& event); void event_process(); private: bool running_ = false; std::vector disk_resources_; std::vector resources_; mutable std::mutex resources_mutex_; std::queue queue_; std::function subscriber_ = nullptr; std::mutex event_mutex_; std::condition_variable event_cv_; std::thread worker_thread_; }; using ResourceMgrPtr = std::shared_ptr; using ResourceMgrWPtr = std::weak_ptr; } // namespace scheduler } // namespace milvus