-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User QoS resource total limit #370
base: master
Are you sure you want to change the base?
Changes from all commits
ac24230
290de2e
3d26835
0df3171
6ba3204
f64b25c
621237a
44180b3
16d6d7b
4a9bc01
a83d4d1
00c1401
475f71f
e7cdbe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
include(FetchContent) | ||
|
||
set(HASHMAP_SRC_URL "https://github.com/greg7mdp/parallel-hashmap/archive/refs/tags/v1.4.1.tar.gz") | ||
|
||
FetchContent_Declare(parallel-hashmap | ||
URL ${HASHMAP_SRC_URL} | ||
URL_HASH SHA256=949874f4207b8735422438b23b884fb1f4b926689bb5eebff38cc4d357d09cd2 | ||
INACTIVITY_TIMEOUT 5 | ||
) | ||
|
||
FetchContent_MakeAvailable(parallel-hashmap) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2024 Peking University and Peking University | ||
* Changsha Institute for Computing and Digital Economy | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "AccountMetaContainer.h" | ||
|
||
#include "AccountManager.h" | ||
|
||
namespace Ctld { | ||
|
||
bool AccountMetaContainer::CheckAndMallocQosResourceFromUser( | ||
const std::string& username, const TaskInCtld& task, const Qos& qos) { | ||
if (static_cast<double>(task.cpus_per_task) > qos.max_cpus_per_user || | ||
qos.max_jobs_per_user == 0) | ||
return false; | ||
|
||
bool result = true; | ||
|
||
ResourceView resource_view{}; | ||
resource_view.GetAllocatableRes().cpu_count = task.cpus_per_task; | ||
|
||
user_meta_map_[username].qos_resource_in_use.try_emplace_l( | ||
task.qos, | ||
[&](std::pair<const std::string, QosResource>& pair) { | ||
auto& val = pair.second; | ||
if (val.resource.CpuCount() + static_cast<double>(task.cpus_per_task) > | ||
qos.max_cpus_per_user || | ||
val.jobs_per_user >= qos.max_jobs_per_user) { | ||
result = false; | ||
return; | ||
} | ||
|
||
val.resource.GetAllocatableRes().cpu_count += task.cpus_per_task; | ||
val.jobs_per_user++; | ||
}, | ||
QosResource{resource_view, 1}); | ||
|
||
return result; | ||
} | ||
|
||
void AccountMetaContainer::FreeQosResource(const std::string& username, | ||
const TaskInCtld& task) { | ||
user_meta_map_[username].qos_resource_in_use.modify_if( | ||
task.qos, [&](std::pair<const std::string, QosResource>& pair) { | ||
auto& val = pair.second; | ||
val.resource.GetAllocatableRes().cpu_count -= task.cpus_per_task; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
val.jobs_per_user--; | ||
}); | ||
} | ||
|
||
} // namespace Ctld |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2024 Peking University and Peking University | ||
* Changsha Institute for Computing and Digital Economy | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CtldPublicDefs.h" | ||
// Precompiled header comes first! | ||
|
||
namespace Ctld { | ||
|
||
class AccountMetaContainer final { | ||
public: | ||
using UserResourceMetaMap = std::unordered_map<std::string, // username | ||
ResourcePerUser>; | ||
|
||
AccountMetaContainer() = default; | ||
~AccountMetaContainer() = default; | ||
|
||
bool CheckAndMallocQosResourceFromUser(const std::string& username, | ||
const TaskInCtld& task, | ||
const Qos& qos); | ||
|
||
void FreeQosResource(const std::string& username, const TaskInCtld& task); | ||
|
||
private: | ||
UserResourceMetaMap user_meta_map_; | ||
}; | ||
|
||
inline std::unique_ptr<Ctld::AccountMetaContainer> g_account_meta_container; | ||
|
||
} // namespace Ctld |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -703,6 +703,22 @@ inline bool CheckIfTimeLimitIsValid(absl::Duration d) { | |
return CheckIfTimeLimitSecIsValid(sec); | ||
} | ||
|
||
struct QosResource { | ||
ResourceView resource; | ||
uint32_t jobs_per_user; | ||
}; | ||
|
||
struct ResourcePerUser { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个东西可以放AccountMetaContainer.h里面吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以的,我开始就是放在里面的 |
||
using QosToQosResourceMap = phmap::parallel_flat_hash_map< | ||
std::string, // QosName | ||
QosResource, phmap::priv::hash_default_hash<std::string>, | ||
phmap::priv::hash_default_eq<std::string>, | ||
std::allocator<std::pair<const std::string, QosResource>>, 4, | ||
std::shared_mutex>; | ||
|
||
QosToQosResourceMap qos_resource_in_use; | ||
}; | ||
|
||
} // namespace Ctld | ||
|
||
inline std::unique_ptr<BS::thread_pool> g_thread_pool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该直接加task.requested_node_res_view*node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
噢噢对