Skip to content

Commit

Permalink
EH: CS-757 Create a module test for sessions that also measures perfo…
Browse files Browse the repository at this point in the history
…rmance with 5M sessions
  • Loading branch information
ernst-bablick committed Oct 30, 2024
1 parent 8e0890a commit c5800f1
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/libs/sgeobj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ target_include_directories(test_sgeobj_schedd_conf PRIVATE "./")
target_link_libraries(test_sgeobj_schedd_conf PRIVATE sgeobj cull comm uti commlists ${SGE_LIBS})
add_test(NAME test_sgeobj_schedd_conf COMMAND test_sgeobj_schedd_conf)

add_executable(test_sgeobj_Session test_sgeobj_Session.cc)
target_include_directories(test_sgeobj_Session PRIVATE "./")
target_link_libraries(test_sgeobj_Session PRIVATE sgeobj cull comm uti commlists ${SGE_LIBS})
add_test(NAME test_sgeobj_Session COMMAND test_sgeobj_Session)

add_executable(test_sgeobj_utility test_sgeobj_utility.cc)
target_include_directories(test_sgeobj_utility PRIVATE "./")
target_link_libraries(test_sgeobj_utility PRIVATE sgeobj cull comm uti commlists ${SGE_LIBS})
Expand All @@ -74,5 +79,6 @@ if (INSTALL_SGE_TEST)
install(TARGETS test_sgeobj_range DESTINATION testbin/${SGE_ARCH})
install(TARGETS test_sgeobj_resource_quota DESTINATION testbin/${SGE_ARCH})
install(TARGETS test_sgeobj_schedd_conf DESTINATION testbin/${SGE_ARCH})
install(TARGETS test_sgeobj_Session DESTINATION testbin/${SGE_ARCH})
install(TARGETS test_sgeobj_utility DESTINATION testbin/${SGE_ARCH})
endif ()
146 changes: 146 additions & 0 deletions test/libs/sgeobj/test_sgeobj_Session.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*___INFO__MARK_BEGIN_NEW__*/
/***************************************************************************
*
* Copyright 2024 HPC-Gridware GmbH
*
* 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.
*
***************************************************************************/
/*___INFO__MARK_END_NEW__*/

#include <cassert>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <random>

#include "uti/sge_time.h"

#include "sgeobj/ocs_Session.h"

// Function to generate a random string of given length
std::string generate_random_string(size_t length) {
const std::string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_int_distribution<> distribution(0, characters.size() - 1);

std::string random_string;
for (size_t i = 0; i < length; ++i) {
random_string += characters[distribution(generator)];
}
return random_string;
}

static bool
check_session_performance(u_long64 sessions) {
bool ret = true;
std::vector<std::string> user_and_hostnames;

for (u_long64 i = 0; i < sessions; i++) {
user_and_hostnames.push_back(std::to_string(i));
if (i % 50000 == 0) {
std::cout << "." << std::flush;
}
}
std::cout << std::endl;
std::cout << "Generated " << sessions << " names" << std::endl;

u_long64 start = sge_get_gmt64();

// Create sessions
for (auto &name: user_and_hostnames) {
u_long64 session_id = ocs::SessionManager::get_session_id(name.c_str());
ocs::SessionManager::set_write_unique_id(session_id, 1);
}
std::cout << "Created " << sessions << " sessions" << std::endl;

// Update sessions
for (u_long64 i = 0; i < sessions; i++) {
ocs::SessionManager::set_process_unique_id(i);
}
std::cout << "Updated " << sessions << " sessions" << std::endl;

// Check sessions
for (auto &name: user_and_hostnames) {
u_long64 session_id = ocs::SessionManager::get_session_id(name.c_str());
ocs::SessionManager::is_uptodate(session_id);
}
std::cout << "Checked " << sessions << " sessions" << std::endl;

// Remove sessions
u_long64 end = sge_get_gmt64();
u_long32 delta = end - start;
std::cout << "Time for " << sessions << " sessions: " << delta << " us" << std::endl;

// Check if the time is within reasonable limits (5 us per session (including creation, update, and check))
if (delta > 5 * sessions) {
std::cout << "ERROR: Time for " << sessions << " sessions is too high" << std::endl;
ret = false;
}

return ret;
}

static bool
check_session_functionality() {
bool ret = true;

// Create a session
u_long64 session_id = ocs::SessionManager::get_session_id(generate_random_string(1000).c_str());
assert(session_id != GDI_SESSION_NONE);

// Check if the session is up-to-date
ret &= ocs::SessionManager::is_uptodate(session_id);

// Set the write unique ID
ocs::SessionManager::set_write_unique_id(session_id, 1);
ocs::SessionManager::set_process_unique_id(0);

// Check if the session is up-to-date
if (ocs::SessionManager::is_uptodate(session_id) != false) {
std::cout << "Session is up-to-date although this is not expected" << std::endl;
ret = false;
}

// Set the process unique ID
ocs::SessionManager::set_process_unique_id(1);

// Check if the session is up-to-date
if (ocs::SessionManager::is_uptodate(session_id) != true) {
std::cout << "Session is not up-to-date although it should be" << std::endl;
ret = false;
}

// Set the process unique ID
ocs::SessionManager::set_process_unique_id(5);

// Check if the session is up-to-date
if (ocs::SessionManager::is_uptodate(session_id) != true) {
std::cout << "Session is not up-to-date although it should be" << std::endl;
ret = false;
}

return ret;
}

int
main(int argc, char *argv[]) {
bool ret = true;

ret &= check_session_functionality();
ret &= check_session_performance(500 * 10000); // 500 users with 10000 hosts

return ret ? EXIT_SUCCESS : EXIT_FAILURE;
}

0 comments on commit c5800f1

Please sign in to comment.