Skip to content

Commit

Permalink
Refs #22321: Extra corrections and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Gil Aviles <[email protected]>
  • Loading branch information
Javgilavi committed Dec 16, 2024
1 parent f51d7b1 commit 6fc1e8f
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 88 deletions.
2 changes: 1 addition & 1 deletion examples/cpp/benchmark/PublisherApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(count) / (elapsed.count() / 1000.0);
switch (msg_size_)
{
Expand Down
71 changes: 40 additions & 31 deletions examples/cpp/benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
```

Expand All @@ -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
...
```

Expand All @@ -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.
```
Expand Down Expand Up @@ -222,6 +222,15 @@ Using argument **`-m`** `<num>` or **`--msg-size`** `<num>` configures the size
- `BIG`: An integer value + an array of 8 MB.
- **Default**: `NONE`

### Number of Samples

Using argument **`-s`** `<num>` or **`--samples`** `<num>` configures the number of samples to send or receive during the test.

- **Range**: `[0 <= <num> <= 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``** ``<transport>`` or **``--transport``** ``<transport>`` will configure the internal DomainParticipant using the selected builtin transport:
Expand Down
62 changes: 8 additions & 54 deletions examples/cpp/benchmark/SubscriberApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ void SubscriberApp::on_publication_matched(
{
if (info.current_count_change == 1)
{
matched_ = static_cast<int16_t>(info.current_count);
matched_++;
std::cout << "Publisher matched." << std::endl;
cv_.notify_one();
}
else if (info.current_count_change == -1)
{
matched_ = static_cast<int16_t>(info.current_count);
matched_--;
std::cout << "Publisher unmatched." << std::endl;
stop();
}
Expand All @@ -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();
}
Expand All @@ -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<std::mutex> 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;
Expand All @@ -266,19 +256,7 @@ void SubscriberApp::on_data_available(
benchmark_small_.index() << "' (Array " << static_cast<int>(benchmark_small_.array().size()) <<
" Bytes) RECEIVED" << std::endl;
benchmark_small_.index(benchmark_small_.index() + 1);
while (matched_ == 0)
{
std::unique_lock<std::mutex> 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;
Expand All @@ -304,19 +282,7 @@ void SubscriberApp::on_data_available(
static_cast<int>(benchmark_medium_.data().size()) <<
" Bytes) RECEIVED" << std::endl;
benchmark_medium_.index(benchmark_medium_.index() + 1);
while (matched_ == 0)
{
std::unique_lock<std::mutex> 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;
Expand All @@ -341,19 +307,7 @@ void SubscriberApp::on_data_available(
benchmark_big_.index() << "' (Array " << static_cast<int>(benchmark_big_.data().size()) <<
" Bytes) RECEIVED" << std::endl;
benchmark_big_.index(benchmark_big_.index() + 1);
while (matched_ == 0)
{
std::unique_lock<std::mutex> 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;
Expand Down
13 changes: 11 additions & 2 deletions examples/cpp/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------
Expand Down

0 comments on commit 6fc1e8f

Please sign in to comment.