Skip to content

Commit

Permalink
[sample] sample massive_pub_sub extended (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky authored Aug 20, 2024
1 parent d4fd7d6 commit 5779c07
Showing 1 changed file with 64 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#include <thread>
#include <vector>

const int subscriber_number (5000);
const int subscriber_number (10000);

const int publisher_number (5000);
const int publisher_number (10000);
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);
const int final_sleep_sec (0);

std::string GenerateSizedString(const std::string& name, size_t totalSize)
{
Expand All @@ -56,8 +56,11 @@ std::string GenerateSizedString(const std::string& name, size_t totalSize)

int main(int argc, char** argv)
{
// initialize eCAL API
eCAL::Initialize(argc, argv, "massive_pub_sub");
// initialize eCAL API with shm monitoring
eCAL::Configuration configuration;
configuration.registration.layer.shm.enable = true;
configuration.registration.layer.udp.enable = false;
eCAL::Initialize(configuration, "massive_pub_sub");

eCAL::Util::EnableLoopback(true);

Expand All @@ -82,7 +85,7 @@ int main(int argc, char** argv)

// 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;
std::cout << "Time taken for subscriber creation: " << duration << " milliseconds" << std::endl << std::endl;
}

// sleep for a few seconds
Expand Down Expand Up @@ -114,9 +117,62 @@ int main(int argc, char** argv)

// 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 << "Time taken for publisher creation: " << duration << " milliseconds" << std::endl << std::endl;
}

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

// wait for full registration
std::cout << "Wait for publisher/subscriber registration." << std::endl;
{
// start time measurement
auto start_time = std::chrono::high_resolution_clock::now();

size_t num_pub(0);
size_t num_sub(0);
while ((num_pub < publisher_number) || (num_sub < subscriber_number))
{
num_pub = eCAL::Registration::GetPublisherIDs().size();
num_sub = eCAL::Registration::GetSubscriberIDs().size();

std::cout << "Registered publisher : " << num_pub << std::endl;
std::cout << "Registered subscriber: " << num_sub << std::endl;

// sleep for 1000 milliseconds
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}

// 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 to get all registered: " << duration << " milliseconds" << std::endl << std::endl;
}

// get publisher information
std::cout << "Get publisher information. (";
size_t num_pub(0);
{
// start time measurement
auto start_time = std::chrono::high_resolution_clock::now();

const auto pub_ids = eCAL::Registration::GetPublisherIDs();
num_pub = pub_ids.size();
for (const auto& id : pub_ids)
{
eCAL::Registration::SQualityTopicInfo topic_info;
eCAL::Registration::GetPublisherInfo(id, topic_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 << num_pub << ")" << std::endl << "Time taken to get publisher information: " << duration << " milliseconds" << std::endl << std::endl;
}
std::cout << std::endl;

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

0 comments on commit 5779c07

Please sign in to comment.