-
Notifications
You must be signed in to change notification settings - Fork 782
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
[22321] Benchmark example updated #5460
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending example tests
4c8a8db
to
54b8494
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good first iteration overall. The PR brings an interesting example.
In addition to my comments below, we would need to add this PR content Refactor benchmark example
to the versions.md
and replace the N/A
with a tick in the checklist.
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(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically recommend not to perform blocking operations in callbacks. I think it would make more sens moving these lines to the first part of the run()
method.
Additionally, I think we could change the matched_
condition to be greater of equal to 2 since we expect both of out endpoints to be matched with the publisher ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to make sure the subscriber not to sent back the data until the on_publication_match happen. To solve the case of the subscriber receiving the data but not sending it properly.
I don't understand how this could be moved to run()
.
Also, I understand the comment of change for matched_ to be greater or equal to 2 is for the publisher and not here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first thing in the run()
method would be:
{
// Wait for the data endpoints discovery
std::unique_lock<std::mutex> matched_lock(mutex_);
cv_.wait(matched_lock, [&]()
{
// at least one has been discovered
return ((matched_ >= 2) || is_stopped());
});
}
Then, I would remove all while (matched_ == 0){}
blocks from the on_data_available()
. This will make the subscriber to first wait to be matched and simplify the 'on_data_available()`. We should until greater or equal than 2 since both subscriber endpoints must be matched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats more, we could avoid waiting for any matched_
within run()
, since the reliability and durability will do the late-joining this for us when specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed in private chat, I just delated the blocking operation on the on_data_available()
.
examples/cpp/benchmark/README.md
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing locally I found a couple of strange things to me in the publisher side:
- The first index seems to be sent and received twice
- The RECEIVED is only printed for odd sample idexes (1,3,5,...)
Is that behavior correct ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem of repeating the first index is fix.
The RECEIVED is only printed for odd because they are sent by the subscriber and receive in the publisher, and the evens are sent by the publisher and receive by the subscriber
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I reviewed the logic and I first thought that the subscriber was not incrementing the index but it is doing it, so it is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, update the commands output in this document since the index 0, index 1, index 0,...
behavior was already corrected and no longer exists
b1e7b77
to
791e055
Compare
Signed-off-by: Javier Gil Aviles <[email protected]>
Signed-off-by: Javier Gil Aviles <[email protected]>
Signed-off-by: Javier Gil Aviles <[email protected]>
Signed-off-by: Javier Gil Aviles <[email protected]>
Signed-off-by: Javier Gil Aviles <[email protected]>
Signed-off-by: Javier Gil Aviles <[email protected]>
Signed-off-by: Javier Gil Aviles <[email protected]>
cc2b477
to
f51d7b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving just some comments on previous suggestions
Please, don't forget updating the |
return; | ||
} | ||
} | ||
if (benchmark_.index() >= samples_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are missing this here, otherwise when the example is launched without --samples
the subscriber will receive the first sample and skip.
if (benchmark_.index() >= samples_) | |
if (samples_ != 0 && benchmark_.index() >= samples_) |
Signed-off-by: Javier Gil Aviles <[email protected]>
Description
I remake the benchmark example to new example style maintaining the original functionality.
@Mergifyio backport 3.1.x 3.0.x
Fixes #5398
Contributor Checklist
versions.md
file (if applicable).Reviewer Checklist