Skip to content
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

[core] shm-monitoring-performance #1645

Merged
merged 9 commits into from
Jul 9, 2024
14 changes: 0 additions & 14 deletions ecal/core/include/ecal/config/monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ namespace eCAL
{
namespace Monitoring
{
namespace Types
{
enum Mode
{
none = 0,
udp_monitoring = 1 << 0,
shm_monitoring = 1 << 1
};

using Mode_Filter = char;
}

namespace UDP
{
struct Configuration
Expand All @@ -60,9 +48,7 @@ namespace eCAL

struct Configuration
{
Types::Mode_Filter monitoring_mode{}; //!< Specify which monitoring is enabled (Default: none)
eCAL::Types::ConstrainedInteger<1000, 1000> monitoring_timeout{}; //!< Timeout for topic monitoring in ms (Default: 5000)
bool network_monitoring{}; //!< Enable distribution of monitoring/registration information via network (Default: true)
UDP::Configuration udp_options{};
SHM::Configuration shm_options{};

Expand Down
2 changes: 0 additions & 2 deletions ecal/core/src/config/ecal_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ namespace eCAL

namespace Experimental
{
ECAL_API bool IsShmMonitoringEnabled () { return (GetConfiguration().monitoring.monitoring_mode & Monitoring::Types::Mode::shm_monitoring) != 0; }
ECAL_API bool IsNetworkMonitoringDisabled () { return !GetConfiguration().monitoring.network_monitoring; }
ECAL_API size_t GetShmMonitoringQueueSize () { return GetConfiguration().monitoring.shm_options.shm_monitoring_queue_size; }
ECAL_API std::string GetShmMonitoringDomain () { return GetConfiguration().monitoring.shm_options.shm_monitoring_domain;}
ECAL_API bool GetDropOutOfOrderMessages () { return GetConfiguration().transport_layer.drop_out_of_order_messages; }
Expand Down
3 changes: 0 additions & 3 deletions ecal/core/src/config/ecal_config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ namespace eCAL

// monitoring options
auto& monitoringOptions = monitoring;
auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? Monitoring::Types::Mode::shm_monitoring : Monitoring::Types::Mode::none;
monitoringOptions.monitoring_mode = static_cast<Monitoring::Types::Mode_Filter>(monitoringMode);
monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);;
monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED);
monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL);
monitoringOptions.filter_incl = iniConfig.get(MONITORING, "filter_incl", MON_FILTER_INCL);

Expand Down
6 changes: 0 additions & 6 deletions ecal/core/src/ecal_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ constexpr const char* EVENT_SHUTDOWN_PROC = "ecal_shutdown_pro
/**********************************************************************************************/
/* experimental */
/**********************************************************************************************/
/* enable distribution of monitoring/registration information via shared memory */
constexpr bool EXP_SHM_MONITORING_ENABLED = false;
/* enable distribution of monitoring/registration information via network (default) */
constexpr bool EXP_NETWORK_MONITORING_ENABLED = true;
/* queue size of monitoring/registration events */
constexpr unsigned int EXP_SHM_MONITORING_QUEUE_SIZE = 1024U;
/* domain name for shared memory based monitoring/registration */
Expand All @@ -200,5 +196,3 @@ constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100U;

/* enable dropping of payload messages that arrive out of order */
constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false;

constexpr eCAL::Monitoring::Types::Mode EXP_MONITORING_MODE = eCAL::Monitoring::Types::Mode::none;
4 changes: 0 additions & 4 deletions ecal/core/src/ecal_descgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,12 @@ namespace eCAL
topic_quality_info.quality = topic_quality_;

const std::unique_lock<std::mutex> lock(topic_info_map_.mtx);
topic_info_map_.map.erase_expired();
topic_info_map_.map[topic_info_key] = topic_quality_info;
}

void CDescGate::RemTopicDescription(SQualityTopicIdMap& topic_info_map_, const std::string& topic_name_, const Util::TopicId& topic_id_)
{
const std::unique_lock<std::mutex> lock(topic_info_map_.mtx);
topic_info_map_.map.erase_expired();
topic_info_map_.map.erase(STopicIdKey{ topic_name_, topic_id_ });
}

Expand All @@ -213,7 +211,6 @@ namespace eCAL
service_quality_info.response_quality = response_type_quality_;

const std::lock_guard<std::mutex> lock(service_method_info_map_.mtx);
service_method_info_map_.map.erase_expired();
service_method_info_map_.map[service_method_info_key] = service_quality_info;
}

Expand All @@ -222,7 +219,6 @@ namespace eCAL
std::list<SServiceIdKey> service_method_infos_to_remove;

const std::lock_guard<std::mutex> lock(service_method_info_map_.mtx);
service_method_info_map_.map.erase_expired();

for (auto&& service_it : service_method_info_map_.map)
{
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/registration/ecal_registration_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ namespace eCAL
{
if(m_created) return;

// send registration to shared memory and to udp
m_use_registration_udp = !Config::Experimental::IsNetworkMonitoringDisabled();
m_use_registration_shm = Config::Experimental::IsShmMonitoringEnabled();
// send registration over udp or shared memory
m_use_registration_udp = Config::IsNetworkEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'bool (*)()' -> bool [readability-implicit-bool-conversion]

Suggested change
m_use_registration_udp = Config::IsNetworkEnabled;
m_use_registration_udp = (Config::IsNetworkEnabled != nullptr);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config::IsNetworkEnabled() 😨

m_use_registration_shm = !m_use_registration_udp;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused. shouldn't the registration provider / receiver also be passed configuration objects (maybe just registration configuration) in their constructors? But maybe that's for a different PR.

if (m_use_registration_udp)
{
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/registration/ecal_registration_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ namespace eCAL
{
if(m_created) return;

// receive registration from shared memory and or udp
m_use_registration_udp = !Config::Experimental::IsNetworkMonitoringDisabled();
m_use_registration_shm = Config::Experimental::IsShmMonitoringEnabled();
// receive registration via udp or shared memory
m_use_registration_udp = Config::IsNetworkEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: implicit conversion 'bool (*)()' -> bool [readability-implicit-bool-conversion]

Suggested change
m_use_registration_udp = Config::IsNetworkEnabled;
m_use_registration_udp = (Config::IsNetworkEnabled != nullptr);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rex-schilasky 🤣 this is really bad, did this not generate a regular warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-(

m_use_registration_shm = !m_use_registration_udp;

if (m_use_registration_udp)
{
Expand Down
3 changes: 2 additions & 1 deletion ecal/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,7 @@ endif()

if(ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER)
add_subdirectory(cpp/benchmarks/perftool)
add_subdirectory(cpp/benchmarks/massive_pub_sub)
endif()

# misc
Expand Down
41 changes: 41 additions & 0 deletions ecal/samples/cpp/benchmarks/massive_pub_sub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2024 Continental Corporation
#
# 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.
#
# ========================= eCAL LICENSE =================================

cmake_minimum_required(VERSION 3.10)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)

project(massive_pub_sub)

find_package(eCAL REQUIRED)

set(massive_pub_sub_src
src/massive_pub_sub.cpp
)

ecal_add_sample(${PROJECT_NAME} ${massive_pub_sub_src})

target_link_libraries(${PROJECT_NAME}
eCAL::core
)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/benchmarks/massive_pub_sub)
128 changes: 128 additions & 0 deletions ecal/samples/cpp/benchmarks/massive_pub_sub/src/massive_pub_sub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
*
* 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.
*
* ========================= eCAL LICENSE =================================
*/

#include <ecal/ecal.h>

#include <iostream>
#include <chrono>
#include <sstream>
#include <thread>
#include <vector>

const int subscriber_number (5000);

const int publisher_number (5000);
const int publisher_type_encoding_size_bytes (10*1024);
const int publisher_type_descriptor_size_bytes (10*1024);

const int in_between_sleep_sec (5);
const int final_sleep_sec (120);

std::string GenerateSizedString(const std::string& name, size_t totalSize)
{
if (name.empty() || totalSize == 0) {
return "";
}

std::string result;
result.reserve(totalSize);

while (result.size() + name.size() <= totalSize) {
result += name;
}

if (result.size() < totalSize) {
result += name.substr(0, totalSize - result.size());
}

return result;
}

int main(int argc, char** argv)
{
// initialize eCAL API
eCAL::Initialize(argc, argv, "massive_pub_sub");

eCAL::Util::EnableLoopback(true);

// create subscriber
std::vector<eCAL::CSubscriber> vector_of_subscriber;
std::cout << "Subscriber creation started. (" << subscriber_number << ")" << std::endl;
{
// start time measurement
auto start_time = std::chrono::high_resolution_clock::now();

for (int i = 0; i < subscriber_number; i++)
{
// publisher topic name
std::stringstream tname;
tname << "TOPIC_" << i;

// create subscriber
vector_of_subscriber.emplace_back(tname.str());
}
// stop time measurement
auto end_time = std::chrono::high_resolution_clock::now();

// calculate the duration
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
std::cout << "Time taken for subscriber creation: " << duration << " milliseconds" << std::endl;
}

// sleep for a few seconds
std::this_thread::sleep_for(std::chrono::seconds(in_between_sleep_sec));

// create publisher
std::vector<eCAL::CPublisher> vector_of_publisher;
std::cout << "Publisher creation started. (" << publisher_number << ")" << std::endl;
{
// start time measurement
auto start_time = std::chrono::high_resolution_clock::now();

eCAL::SDataTypeInformation data_type_info;
data_type_info.name = "TOPIC_TYPE_NAME";
data_type_info.encoding = GenerateSizedString("TOPIC_TYPE_ENCODING", publisher_type_encoding_size_bytes);
data_type_info.descriptor = GenerateSizedString("TOPIC_TYPE_DESCRIPTOR", publisher_type_descriptor_size_bytes);

for (int i = 0; i < publisher_number; i++)
{
// publisher topic name
std::stringstream tname;
tname << "TOPIC_" << i;

// create publisher
vector_of_publisher.emplace_back(tname.str(), data_type_info);
}
// stop time measurement
auto end_time = std::chrono::high_resolution_clock::now();

// calculate the duration
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
std::cout << "Time taken for publisher creation: " << duration << " milliseconds" << std::endl;
}
std::cout << std::endl;

// sleep for a few seconds
std::this_thread::sleep_for(std::chrono::seconds(final_sleep_sec));

// finalize eCAL API
eCAL::Finalize();

return(0);
}
4 changes: 2 additions & 2 deletions ecal/samples/cpp/misc/config/src/config_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ int main(int argc, char **argv)
// creating config object
eCAL::Configuration my_config(argc, argv);

// setting configuration
my_config.monitoring.network_monitoring = true;
// setting a configuration
my_config.transport_layer.network_enabled = true;

// initialize eCAL API
eCAL::Initialize(my_config, "config sample");
Expand Down
5 changes: 0 additions & 5 deletions ecal/tests/cpp/config_test/src/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ TEST(core_cpp_config, user_config_passing)
const unsigned int mon_timeout = 6000U;
const std::string mon_filter_excl = "_A.*";
const eCAL_Logging_Filter mon_log_filter_con = log_level_warning;
const eCAL::Monitoring::Types::Mode monitoring_mode = eCAL::Monitoring::Types::Mode::udp_monitoring;

// Publisher options
const bool pub_use_shm = true;
Expand All @@ -69,7 +68,6 @@ TEST(core_cpp_config, user_config_passing)

custom_config.monitoring.monitoring_timeout = mon_timeout;
custom_config.monitoring.filter_excl = mon_filter_excl;
custom_config.monitoring.monitoring_mode = monitoring_mode;
custom_config.logging.filter_log_con = mon_log_filter_con;

custom_config.publisher.shm.enable = pub_use_shm;
Expand Down Expand Up @@ -102,9 +100,6 @@ TEST(core_cpp_config, user_config_passing)
// Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal)
EXPECT_EQ(mon_log_filter_con, eCAL::GetConfiguration().logging.filter_log_con);

// Test monitoring mode assignment, default is eCAL::Types::MonitoringMode::none
EXPECT_EQ(monitoring_mode, eCAL::GetConfiguration().monitoring.monitoring_mode);

// Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto
EXPECT_EQ(pub_use_shm, eCAL::GetConfiguration().publisher.shm.enable);

Expand Down
Loading