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

[QST] shm_msg based zero-copy, intra-process based zero-copy, and type adaption. #25

Closed
toan70411hd91 opened this issue Dec 6, 2022 · 10 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@toan70411hd91
Copy link

toan70411hd91 commented Dec 6, 2022

@ZhenshengLee thank you so much for your information and quick helps. May I ask you some questions related to ros2_shm_msgs?

  • In folder "intra", i found that you added intra type adaption within cpu. Currently, ros2_shm_msgs only support type adaption (within CPU) for image only, but not for pointcloud?
  • Is it correct if "zero-copy" in ros2_shm_msgs called "minimal copy" when we publish topics?
  • In your opinion, whether the performance (regarding to speed and CPU consumption) much better if we use type adaption?

Even I did not use https://github.com/IntelRealSense/realsense-ros#efficient-intra-process-communication, the performance of ROS2 Realsense Wrapper (regarding to speed and CPU consumption) is almost same with ros2_shm-msgs. I am not sure the hints inside since i am quite new in this topic. Maybe, my tested point-cloud data is small (camera resolution 640x480, with decimation filter).

@toan70411hd91 toan70411hd91 changed the title ros2_shm_msgs performance [Inquiry] ros2_shm_msgs performance Dec 6, 2022
@ZhenshengLee ZhenshengLee self-assigned this Dec 6, 2022
@ZhenshengLee ZhenshengLee added the documentation Improvements or additions to documentation label Dec 6, 2022
@ZhenshengLee ZhenshengLee added this to the doing milestone Dec 6, 2022
@ZhenshengLee
Copy link
Owner

ZhenshengLee commented Dec 6, 2022

ros2_shm_msgs only support type adaption (within CPU) for image only, but not for pointcloud?

type adaption feature is nothing with ros2_shm_msgs, but as a comparsion with shm_msg based zero-copy which provided by this repo.

There are currently two way to achieve zero-copy transport, one is intra-process, the other is shm_msg based zero-copy

  • intra-process comm is done in rclcpp, it doesn't depend on dds, but as it's about intra-process, the shortcoming of intra-process exist in this method.
  • shm_msg based zero-copy is done in rclcpp and dds by loaned api, why it's called shm_msg based is the zero-copy feature from cyclonedds and fastdds involves bounded size msg definition, which is provided by this repo.
  • shm_msg based zero-copy is with Intra-machine IPC, not intra-process

the type adaption is the feature extened from intra-process comm, so it's just the alternative of shm_msg based zero-copy.

@ZhenshengLee
Copy link
Owner

ros2_shm_msgs only support type adaption (within CPU) for image only, but not for pointcloud?

the type adaption feature mainly uses a data container to avoid type-conversion between ros-msg-type and algor-data-type, the algor-data-type is up to what library you are using. For example, opencv, pcl and open3d.

for example, the type adaption feature for opencv-image is implemented in ros-perception/vision_opencv#441 , this is done by the application developer, not middleware developer. I've created an issue about support pointcloud type adaption here ros-perception/perception_pcl#386

in cuda folder, there are more data-containers with opencv-cuda-image and cuda-raw-image, and it's implementation specific.

@ZhenshengLee
Copy link
Owner

Is it correct if "zero-copy" in ros2_shm_msgs called "minimal copy" when we publish topics?

It depends on the scope we are talking about. If the scope is within dds, zero-copy means 0 copy of course, that's why it's called zero copy.

When the scope extends to ROS2, the question is: How many copies is it in the whole chain of pub and sub?

In IPC on top of DDS, there will be at least two types of copies that cannot be avoided, type-conversion and (de)serialization. So it's true that minimal copy happens in ros2_shm_msgs.

P.S. type-conversion can be avoided with type adaption feature ros2/rclcpp#1849, and (de)serialization will be avoided in the future by type adaption feature ros2/rclcpp#1665

But as what I said before, type adaption is about intra-process-comm, no related with shm_msg based zero-copy provided in this repo.

@ZhenshengLee
Copy link
Owner

In your opinion, whether the performance (regarding to speed and CPU consumption) much better if we use type adaption?

I think you want to ask if type adaption will improve the performance.
The answer is yes, because some copies is avoided, see more info about type adaption in design page, https://github.com/ros-infrastructure/rep/blob/master/rep-2007.rst

@ZhenshengLee
Copy link
Owner

Even I did not use https://github.com/IntelRealSense/realsense-ros#efficient-intra-process-communication, the performance of ROS2 Realsense Wrapper (regarding to speed and CPU consumption) is almost same with ros2_shm-msgs. I am not sure the hints inside since i am quite new in this topic. Maybe, my tested point-cloud data is small (camera resolution 640x480, with decimation filter).

More info is needed of your test.

But the conclusion I can tell you is that

this article https://www.apex.ai/post/zero-copy-strings-and-bounded-vectors is using the idea of this repo, which creates a new msg definition in idl that is Bounded Vectors.

This repo uses array, which is a type in cpp std with bounded size, see

char[256] data
uint8 size 0
uint8 MAX_SIZE=255

@ZhenshengLee
Copy link
Owner

Feel free to star the repo if it helps.

Thanks.

@ZhenshengLee ZhenshengLee changed the title [Inquiry] ros2_shm_msgs performance [QST] shm_msg based zero-copy, intra-process based zero-copy, and type adaption. Dec 6, 2022
@toan70411hd91
Copy link
Author

@ZhenshengLee Thank you so much for your explanation in details, and it deserves to be starred. If you don't mind, I would like to ask you a bit more. I have checked the ROS2 Humble, and I found this information: "By default, Loaned Messages will try to borrow the memory from underlying middleware if it supports Loaned Messages. The ROS_DISABLE_LOANED_MESSAGES environment variable can be used to disable Loaned Messages, and fallback to normal publisher and subscription behavior, without any code changes or middleware configuration", in this https://docs.ros.org/en/humble/How-To-Guides/Disabling-ZeroCopy-loaned-messages.html. I do not understand clearly "if it supports Loaned Messages". What "it" represents for? If "it" represents for underlying middleware, whether ROS2 Humble already supports Loaned Messages in default or we have to do something more to borrow the memory in ROS2 Humble?

@ZhenshengLee
Copy link
Owner

I do not understand clearly "if it supports Loaned Messages". What "it" represents for? If "it" represents for underlying middleware, whether ROS2 Humble already supports Loaned Messages in default or we have to do something more to borrow the memory in ROS2 Humble?

rclcpp depends on dds, so the loaned api needs to be supported by rclcpp and dds. specifically:

  • rclcpp >= Foxy
  • FastDDS >= v2.3
  • CycloneDDS >= 0.8.x

Please read more about the arch of ros2, make sure you know about the relationship between ros2 and dds

https://design.ros2.org/articles/ros_on_dds.html
https://docs.ros.org/en/foxy/Concepts/About-Internal-Interfaces.html

@toan70411hd91
Copy link
Author

@ZhenshengLee Thanks so much for your info ...

@ZhenshengLee
Copy link
Owner

Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants