Skip to content

Commit

Permalink
feat: Use parallel containers to improve performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
huerni committed Jan 8, 2025
1 parent 8223689 commit e2db715
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 64 deletions.
1 change: 1 addition & 0 deletions dependencies/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_subdirectory(mongodb-cxx-driver)
add_subdirectory(ranges-v3)
add_subdirectory(backward-cpp)
add_subdirectory(fpm)
add_subdirectory(parallel-hashmap)
add_subdirectory(libvault)


Expand Down
11 changes: 11 additions & 0 deletions dependencies/cmake/parallel-hashmap/CMakeLists.txt
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)
24 changes: 13 additions & 11 deletions src/CraneCtld/RpcService/CtldForCforedServer.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/**
* Copyright (c) 2023 Peking University and Peking University
* Copyright (c) 2024 Peking University and Peking University
* Changsha Institute for Computing and Digital Economy
*
* CraneSched is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of
* the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* 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 "CtldForCforedServer.h"
Expand Down
24 changes: 13 additions & 11 deletions src/CraneCtld/RpcService/CtldForCforedServer.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/**
* Copyright (c) 2023 Peking University and Peking University
* Copyright (c) 2024 Peking University and Peking University
* Changsha Institute for Computing and Digital Economy
*
* CraneSched is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of
* the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* 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
Expand Down
24 changes: 13 additions & 11 deletions src/CraneCtld/RpcService/CtldForCranedServer.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/**
* Copyright (c) 2023 Peking University and Peking University
* Copyright (c) 2024 Peking University and Peking University
* Changsha Institute for Computing and Digital Economy
*
* CraneSched is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of
* the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* 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 "CtldForCranedServer.h"
Expand Down
24 changes: 13 additions & 11 deletions src/CraneCtld/RpcService/CtldForCranedServer.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/**
* Copyright (c) 2023 Peking University and Peking University
* Copyright (c) 2024 Peking University and Peking University
* Changsha Institute for Computing and Digital Economy
*
* CraneSched is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of
* the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* 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
Expand Down
4 changes: 0 additions & 4 deletions src/CraneCtld/RpcService/SignServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class SignServer {
std::unique_ptr<SignServiceImpl> m_service_impl_;
std::unique_ptr<Server> m_server_;

inline static std::mutex s_sigint_mtx;
inline static std::condition_variable s_sigint_cv;
static void signal_handler_func(int) { s_sigint_cv.notify_one(); };

friend class SignServiceImpl;
};

Expand Down
1 change: 1 addition & 0 deletions src/Utilities/VaultClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ target_link_libraries(Utility_VaultClient PUBLIC
curl
vault
nlohmann_json
phmap
Utility_PublicHeader
)
15 changes: 3 additions & 12 deletions src/Utilities/VaultClient/VaultClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,13 @@ bool VaultClient::RevokeCert(const std::string& serial_number) {
return false;
}

{
util::write_lock_guard write_lock(rw_mutex_);
allowed_certs_.erase(serial_number);
}
allowed_certs_.erase(serial_number);

return true;
}

bool VaultClient::IsCertAllowed(const std::string& serial_number) {
{
util::read_lock_guard read_lock(rw_mutex_);
if (allowed_certs_.contains(serial_number)) return true;
}
if (allowed_certs_.contains(serial_number)) return true;

try {
auto response = ListRevokeCertificate_();
Expand All @@ -120,10 +114,7 @@ bool VaultClient::IsCertAllowed(const std::string& serial_number) {
return false;
}

{
util::write_lock_guard write_lock(rw_mutex_);
allowed_certs_.emplace(serial_number);
}
allowed_certs_.emplace(serial_number);

return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Utilities/VaultClient/include/crane/VaultClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <VaultClient.h>
#include <parallel_hashmap/phmap.h>

#include <expected>
#include <memory>
Expand All @@ -38,7 +39,7 @@ struct SignResponse {
std::string certificate;
};

using AllowedCerts = std::unordered_set<std::string>;
using AllowedCerts = phmap::parallel_flat_hash_set<std::string>;

class VaultClient {
public:
Expand Down Expand Up @@ -72,9 +73,8 @@ class VaultClient {
std::unique_ptr<Vault::Pki> pki_root_;
std::unique_ptr<Vault::Pki> pki_external_;

// TODO: 采用并行容器,提高性能
AllowedCerts allowed_certs_ ABSL_GUARDED_BY(rw_mutex_);
util::rw_mutex rw_mutex_;
// Use parallel containers to improve performance.
AllowedCerts allowed_certs_;

std::string address_;
std::string port_;
Expand Down

0 comments on commit e2db715

Please sign in to comment.