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

topic statistics's message age include callback duration. #1491

Closed
hsgwa opened this issue Dec 11, 2020 · 2 comments · Fixed by #1492
Closed

topic statistics's message age include callback duration. #1491

hsgwa opened this issue Dec 11, 2020 · 2 comments · Fixed by #1492
Assignees
Labels
bug Something isn't working

Comments

@hsgwa
Copy link
Contributor

hsgwa commented Dec 11, 2020

Bug report

  • Operating System:
    • ubuntu 20.04
  • Installation type:
    • from source
  • Version or commit hash:
    • foxy branch
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

  1. add 100ms sleep to subscribe callback of topic_statistics_demo.
    Here is source code diff. This code calculates message age in callback as well. see message_age_ms.
  2. build and run demo
$ cd ~/ros2_ws/src
$ git clone -b topic_statistics_issue_reproduce git@github.com:hsgwa/demos.git
$ cd ~/ros2_ws
$ colcon build --symlink-install --packages-select topic_statistics_demo
$ ./build/topic_statistics_demo/display_topic_statistics imu

Expected behavior

[INFO] [1607690935.034977261] [imu_listener]: Listener heard: 1607690935 34339997. message_age_ms: 0.630387
[INFO] [1607690936.035295801] [imu_listener]: Listener heard: 1607690936 34443324. message_age_ms: 0.841733
[INFO] [1607690937.035266102] [imu_listener]: Listener heard: 1607690937 34452405. message_age_ms: 0.805826
[INFO] [1607690938.035036301] [imu_listener]: Listener heard: 1607690938 34468921. message_age_ms: 0.558657
[INFO] [1607690939.035153578] [imu_listener]: Listener heard: 1607690939 34527148. message_age_ms: 0.617793
[INFO] [1607690939.136186369] [statistics_listener]: Statistics heard:
Metric name: message_age source: imu_listener unit: ms
Window start: 135275560 end: 135798117
avg: 0.0  # message age without callback duration.
max: 0.0  # Their values should be almost message_age_ms which is calculated in sub callback.
min: 0.0   # current implementation remove floating point because of chrono::duration_cast
sample_count: 30.000000
std_dev: 0.471405
[INFO] [1607690939.136469027] [statistics_listener]: Statistics heard:
Metric name: message_period source: imu_listener unit: ms
Window start: 135275560 end: 135798117
avg: 999.655172
max: 1000.000000
min: 999.000000
sample_count: 29.000000
std_dev: 0.475312

Actual behavior

[INFO] [1607690935.034977261] [imu_listener]: Listener heard: 1607690935 34339997. message_age_ms: 0.630387
[INFO] [1607690936.035295801] [imu_listener]: Listener heard: 1607690936 34443324. message_age_ms: 0.841733
[INFO] [1607690937.035266102] [imu_listener]: Listener heard: 1607690937 34452405. message_age_ms: 0.805826
[INFO] [1607690938.035036301] [imu_listener]: Listener heard: 1607690938 34468921. message_age_ms: 0.558657
[INFO] [1607690939.035153578] [imu_listener]: Listener heard: 1607690939 34527148. message_age_ms: 0.617793
[INFO] [1607690939.136186369] [statistics_listener]: Statistics heard:
Metric name: message_age source: imu_listener unit: ms
Window start: 135275560 end: 135798117
avg: 100.666667 # message age include callback duration which is 100ms sleep in this sample case.
max: 101.000000
min: 100.000000
sample_count: 30.000000
std_dev: 0.471405
[INFO] [1607690939.136469027] [statistics_listener]: Statistics heard:
Metric name: message_period source: imu_listener unit: ms
Window start: 135275560 end: 135798117
avg: 999.655172
max: 1000.000000
min: 999.000000
sample_count: 29.000000
std_dev: 0.475312

Additional information

Actual behavior seems to be able to achieve by changing order of callback dispatch and now().
https://github.com/ros2/rclcpp/blob/master/rclcpp/include/rclcpp/subscription.hpp#L280

Why do we want to exclude the callback execution time from the message age?
Because if the performance is not as expected, we need to separate the bottleneck between communication and callback execution time.

However, one point to note is that subscribe callbacks delay due to executor's scheduling priority.
If nodes have both subscribe callbacks and timer callbacks, message age possibly include all timer callback duration.

@fujitatomoya
Copy link
Collaborator

Actual behavior seems to be able to achieve by changing order of callback dispatch and now().

sounds reasonable to me. I think this statistics intends to calculate communication latency but not execution time, which btw really depends on application. (https://index.ros.org/doc/ros2/Concepts/About-Topic-Statistics/#how-statistics-are-calculated)

@hsgwa
Copy link
Contributor Author

hsgwa commented Dec 14, 2020

Thank you for your comment!
Exactly, this issue depends on purpose and use-cases.
it looks to me that topic statistics purpose is to measure communication latency.
I posted a draft PR to discuss.
If modification is accepted, I'll add test case.

@ivanpauno ivanpauno added the bug Something isn't working label Dec 21, 2020
@ivanpauno ivanpauno self-assigned this Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants