From 6fc1e8f52ae445143b081f7c0a3636b0a278e479 Mon Sep 17 00:00:00 2001 From: Javier Gil Aviles Date: Mon, 16 Dec 2024 12:00:33 +0100 Subject: [PATCH] Refs #22321: Extra corrections and fixes Signed-off-by: Javier Gil Aviles --- examples/cpp/benchmark/PublisherApp.cpp | 2 +- examples/cpp/benchmark/README.md | 71 +++++++++++-------- examples/cpp/benchmark/SubscriberApp.cpp | 62 +++------------- examples/cpp/benchmark/main.cpp | 13 +++- .../cpp/benchmark/{ => types}/Benchmark.idl | 0 .../benchmark/{ => types}/Benchmark_big.idl | 0 .../{ => types}/Benchmark_medium.idl | 0 .../benchmark/{ => types}/Benchmark_small.idl | 0 versions.md | 1 + 9 files changed, 61 insertions(+), 88 deletions(-) rename examples/cpp/benchmark/{ => types}/Benchmark.idl (100%) rename examples/cpp/benchmark/{ => types}/Benchmark_big.idl (100%) rename examples/cpp/benchmark/{ => types}/Benchmark_medium.idl (100%) rename examples/cpp/benchmark/{ => types}/Benchmark_small.idl (100%) diff --git a/examples/cpp/benchmark/PublisherApp.cpp b/examples/cpp/benchmark/PublisherApp.cpp index 77c060450f4..092c18898d4 100644 --- a/examples/cpp/benchmark/PublisherApp.cpp +++ b/examples/cpp/benchmark/PublisherApp.cpp @@ -409,7 +409,7 @@ void PublisherApp::run() std::cout << vSamples[i] << ","; } std::cout << std::endl; - std::cout << "THROUGHTPUT BPS(Bytes per Second): "; + std::cout << "THROUGHPUT BPS(Bytes per Second): "; double mean_bps = static_cast(count) / (elapsed.count() / 1000.0); switch (msg_size_) { diff --git a/examples/cpp/benchmark/README.md b/examples/cpp/benchmark/README.md index 53628d20bbf..28afcbc642b 100644 --- a/examples/cpp/benchmark/README.md +++ b/examples/cpp/benchmark/README.md @@ -62,30 +62,30 @@ All the example available flags can be queried running the executable with the ` ### Expected output -Regardless of which application is run first, since the publisher will not start sending data until a subscriber is discovered, the expected output both for publishers and subscribers is a first displayed message acknowledging the match, followed by the sent and received data in each application, and finishing showing in the publisher the amount of data shared in each sample time during the running time. +Regardless of which application is run first, since the publisher will not start sending data until a subscriber is discovered, the expected output both for publishers and subscribers is a first displayed message acknowledging the match, followed by the sent and received data in each application, and finishing showing in the publisher the amount of data shared in each sample time during the running time with additional throughput data. ### Benchmark publisher ```shell -Publisher running for 1000 milliseconds. Please press Ctrl+C to stop the Publisher at any time. +Publisher running for 500 samples. Please press Ctrl+C to stop the Publisher at any time. Subscriber matched. Publisher matched. -First Sample with index: '0' (8388608 Bytes) SENT -Sample with index: '1' (8388608 Bytes) RECEIVED -Sample with index: '0' (8388608 Bytes) SENT -Sample with index: '1' (8388608 Bytes) RECEIVED -Sample with index: '0' (8388608 Bytes) SENT -Sample with index: '1' (8388608 Bytes) RECEIVED -Sample with index: '2' (8388608 Bytes) SENT -Sample with index: '3' (8388608 Bytes) RECEIVED -Sample with index: '4' (8388608 Bytes) SENT -Sample with index: '5' (8388608 Bytes) RECEIVED +First Sample with index: '0' (Array 8388608 Bytes) SENT +Sample with index: '1' (Array 8388608 Bytes) RECEIVED +Sample with index: '2' (Array 8388608 Bytes) SENT +Sample with index: '3' (Array 8388608 Bytes) RECEIVED +Sample with index: '4' (Array 8388608 Bytes) SENT +Sample with index: '5' (Array 8388608 Bytes) RECEIVED ... -Sample with index: '646' (8388608 Bytes) SENT -Sample with index: '647' (8388608 Bytes) RECEIVED -RESULTS after 1014 milliseconds: -COUNT: 647 -SAMPLES: 37,46,52,94,86,94,84,62,52,40, +Sample with index: '499' (Array 8388608 Bytes) RECEIVED +Sample with index: '500' (Array 8388608 Bytes) SENT +Publisher unmatched. +Subscriber unmatched. +RESULTS after 1206 milliseconds: +COUNT: 500 +SAMPLES: 41,46,44,42,44,42,52,46,48,44,48,4, +THROUGHPUT BPS(Bytes per Second): 3.48482 Gbps + ... ``` @@ -95,20 +95,15 @@ SAMPLES: 37,46,52,94,86,94,84,62,52,40, Publisher matched. Subscriber matched. Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. -Sample with index: '0' (8388608 Bytes) RECEIVED -Sample with index: '1' (8388608 Bytes) SENT -Sample with index: '0' (8388608 Bytes) RECEIVED -Sample with index: '1' (8388608 Bytes) SENT -Sample with index: '0' (8388608 Bytes) RECEIVED -Sample with index: '1' (8388608 Bytes) SENT -Sample with index: '2' (8388608 Bytes) RECEIVED -Sample with index: '3' (8388608 Bytes) SENT -Sample with index: '4' (8388608 Bytes) RECEIVED -Sample with index: '5' (8388608 Bytes) SENT +Sample with index: '0' (Array 8388608 Bytes) RECEIVED +Sample with index: '1' (Array 8388608 Bytes) SENT +Sample with index: '2' (Array 8388608 Bytes) RECEIVED +Sample with index: '3' (Array 8388608 Bytes) SENT +Sample with index: '4' (Array 8388608 Bytes) RECEIVED +Sample with index: '5' (Array 8388608 Bytes) SENT ... -Sample with index: '646' (8388608 Bytes) RECEIVED -Sample with index: '647' (8388608 Bytes) SENT -Publisher unmatched. +Sample with index: '499' (Array 8388608 Bytes) SENT +Sample with index: '500' (Array 8388608 Bytes) RECEIVED ... ``` @@ -117,9 +112,14 @@ The following is a possible output of the publisher application when stopping th ```shell ... -Publisher running for 10000 milliseconds. Please press Ctrl+C to stop the Publisher at any time. +Publisher running for 500 samples. Please press Ctrl+C to stop the Publisher at any time. Subscriber matched. Publisher matched. +First Sample with index: '0' (Array 8388608 Bytes) SENT +Sample with index: '1' (Array 8388608 Bytes) RECEIVED +Sample with index: '2' (Array 8388608 Bytes) SENT +Sample with index: '3' (Array 8388608 Bytes) RECEIVED +Sample with index: '4' (Array 8388608 Bytes) SENT Publisher unmatched. Subscriber unmatched. ``` @@ -222,6 +222,15 @@ Using argument **`-m`** `` or **`--msg-size`** `` configures the size - `BIG`: An integer value + an array of 8 MB. - **Default**: `NONE` +### Number of Samples + +Using argument **`-s`** `` or **`--samples`** `` configures the number of samples to send or receive during the test. + +- **Range**: `[0 <= <= 65535]` +- **Default**: `0` (until timeout) + +If a value is given, the timeout parameter is ignored, and the application will run until the specified number of samples is sent or received. + ### Builtin transports Using argument **``-t``** ```` or **``--transport``** ```` will configure the internal DomainParticipant using the selected builtin transport: diff --git a/examples/cpp/benchmark/SubscriberApp.cpp b/examples/cpp/benchmark/SubscriberApp.cpp index 95fc8ec8cfb..264554847d8 100644 --- a/examples/cpp/benchmark/SubscriberApp.cpp +++ b/examples/cpp/benchmark/SubscriberApp.cpp @@ -180,13 +180,13 @@ void SubscriberApp::on_publication_matched( { if (info.current_count_change == 1) { - matched_ = static_cast(info.current_count); + matched_++; std::cout << "Publisher matched." << std::endl; cv_.notify_one(); } else if (info.current_count_change == -1) { - matched_ = static_cast(info.current_count); + matched_--; std::cout << "Publisher unmatched." << std::endl; stop(); } @@ -203,10 +203,12 @@ void SubscriberApp::on_subscription_matched( { if (info.current_count_change == 1) { + matched_++; std::cout << "Subscriber matched." << std::endl; } else if (info.current_count_change == -1) { + matched_--; std::cout << "Subscriber unmatched." << std::endl; stop(); } @@ -231,19 +233,7 @@ void SubscriberApp::on_data_available( std::cout << "Sample with index: '" << benchmark_.index() << "' (Array 0 Bytes) RECEIVED" << std::endl; benchmark_.index(benchmark_.index() + 1); - while (matched_ == 0) - { - std::unique_lock initial_lock(mutex_); - auto check = cv_.wait_for(initial_lock, std::chrono::milliseconds(1), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } - } - if (benchmark_.index() >= samples_) + if (samples_ != 0 && benchmark_.index() >= samples_) { stop(); return; @@ -266,19 +256,7 @@ void SubscriberApp::on_data_available( benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << " Bytes) RECEIVED" << std::endl; benchmark_small_.index(benchmark_small_.index() + 1); - while (matched_ == 0) - { - std::unique_lock initial_lock(mutex_); - auto check = cv_.wait_for(initial_lock, std::chrono::milliseconds(1), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } - } - if (benchmark_small_.index() >= samples_) + if (samples_ != 0 && benchmark_small_.index() >= samples_) { stop(); return; @@ -304,19 +282,7 @@ void SubscriberApp::on_data_available( static_cast(benchmark_medium_.data().size()) << " Bytes) RECEIVED" << std::endl; benchmark_medium_.index(benchmark_medium_.index() + 1); - while (matched_ == 0) - { - std::unique_lock initial_lock(mutex_); - auto check = cv_.wait_for(initial_lock, std::chrono::milliseconds(1), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } - } - if (benchmark_medium_.index() >= samples_) + if (samples_ != 0 && benchmark_medium_.index() >= samples_) { stop(); return; @@ -341,19 +307,7 @@ void SubscriberApp::on_data_available( benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << " Bytes) RECEIVED" << std::endl; benchmark_big_.index(benchmark_big_.index() + 1); - while (matched_ == 0) - { - std::unique_lock initial_lock(mutex_); - auto check = cv_.wait_for(initial_lock, std::chrono::milliseconds(1), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } - } - if (benchmark_big_.index() >= samples_) + if (samples_ != 0 && benchmark_big_.index() >= samples_) { stop(); return; diff --git a/examples/cpp/benchmark/main.cpp b/examples/cpp/benchmark/main.cpp index 2116b311c92..8db54f654f7 100644 --- a/examples/cpp/benchmark/main.cpp +++ b/examples/cpp/benchmark/main.cpp @@ -81,8 +81,17 @@ int main( } else { - std::cout << app_name << " running for " << timeout << " milliseconds. Please press Ctrl+C to stop the " - << app_name << " at any time." << std::endl; + if (config.pub_config.samples != 0) + { + std::cout << app_name << " running for " << config.pub_config.samples << + " samples. Please press Ctrl+C " + << "to stop the " << app_name << " at any time." << std::endl; + } + else + { + std::cout << app_name << " running for " << timeout << " milliseconds. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } } stop_app_handler = [&](int signum) diff --git a/examples/cpp/benchmark/Benchmark.idl b/examples/cpp/benchmark/types/Benchmark.idl similarity index 100% rename from examples/cpp/benchmark/Benchmark.idl rename to examples/cpp/benchmark/types/Benchmark.idl diff --git a/examples/cpp/benchmark/Benchmark_big.idl b/examples/cpp/benchmark/types/Benchmark_big.idl similarity index 100% rename from examples/cpp/benchmark/Benchmark_big.idl rename to examples/cpp/benchmark/types/Benchmark_big.idl diff --git a/examples/cpp/benchmark/Benchmark_medium.idl b/examples/cpp/benchmark/types/Benchmark_medium.idl similarity index 100% rename from examples/cpp/benchmark/Benchmark_medium.idl rename to examples/cpp/benchmark/types/Benchmark_medium.idl diff --git a/examples/cpp/benchmark/Benchmark_small.idl b/examples/cpp/benchmark/types/Benchmark_small.idl similarity index 100% rename from examples/cpp/benchmark/Benchmark_small.idl rename to examples/cpp/benchmark/types/Benchmark_small.idl diff --git a/versions.md b/versions.md index c7751d51bcb..d57e8ef4cb4 100644 --- a/versions.md +++ b/versions.md @@ -10,6 +10,7 @@ Forthcoming * Machine UUID added to the Data(p) to check Participants in same host, instead of using GUIDs. * Windows ci example testing infrastructure and `hello world` example. * New property to configure the preferred key agreement algorithm. +* Refactor benchmark example. Version v3.1.0 --------------