Skip to content

ZhenshengLee/ros2_shm_msgs

Repository files navigation

ros2_shm_msgs

fou Chinese reader please refer 简体中文

introduction

motivation

Zero copy can save times of copy in IPC, thus reduces cpu usage and transport latency, which can be used in time-critical systems or resource-constrained computing platforms.

For intra-process context, the zero copy can be achieved with rclcpp intra-process communication, which is avaiable since dashing.

For zero-copy with inter-process-communication in ros2, there's loaned-api provided since ros2-foxy, see ros2_design: Zero Copy via Loaned Messages

related work

what ros2_shm_msgs do

This repo is inspired by projects above, with providing unified image and pointcloud2 msg definition, type conversion function, rviz bridge, and demos with performance test, in a scalable way to have a good support to true zero copy transportation in IPC(intra-machine, inter-process) context.

application status

Currently tested in ros2 galactic with the following layers:

  • rmw_cyclonedds_cpp
    • cyclonedds(0.8.x)+iceoryx(1.0.x)
  • rmw_fastrtps_cpp
    • fastdds(>=2.3.x)

the performance of zero copy can be seen in ros2_jetson_benchmarks, which is tested within GitHub - ZhenshengLee/performance_test: Github repo for apex.ai performance_test for more middlewares.

this lib has been used in the custom version of ros2_v4l2_camera and the custom version of rslidar_sdk, and the performance improvement is awesome!

For example, in my pc of dell 3630, the zero-copy transport of a shm_msgs::msg::Image1m can save about 80% of transport time, from 1.4ms to 0.3ms.

design

software components

this package includes ros2 msg definitions and demos that supports the msgs.

  • shm_msgs::msg::PointCloud8k
  • shm_msgs::msg::Image8k
  • PointCloud2Modifier8k
  • open3d_conversions
  • opencv_conversions
  • pcl_conversions
  • shm_pcl_bridge
  • shm_image_bridge
  • shm_open3d_bridge

development status

pointcloud and image are currently supported.

feature Status
pointcloud8k ✔️
pointcloud512k ✔️
pointcloud1m ✔️
pointcloud2m ✔️
pointcloud4m ✔️
pointcloud8m ✔️
image8k ✔️
image512k ✔️
image1m ✔️
image2m ✔️
image4m ✔️
image8m ✔️
open3d_conversions ✔️
opencv_conversions ✔️
pcl_conversions ✔️
shm_image_bridge ✔️
shm_open3d_bridge ✔️
shm_pcl_bridge ✔️

demo

select rmw

for rmw_cyclonedds

export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export CYCLONEDDS_URI=file:///$HOME/shm_cyclonedds.xml

# t0
iox-roudi

for rmw_fastrtps_cpp

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=$HOME/shm_fastdds.xml
export RMW_FASTRTPS_USE_QOS_FROM_XML=1

check if zero copy

for rmw_cyclonedds_cpp

iox-introspection-client --all
# to check if iceoryx_rt process has been created

for rmw_fastrtps_cpp, to check if there is fastdds shm file being created

# check if shm-transport
ls /dev/shm/fastrtps_
# check if data-sharing
ls /dev/shm/fast_datasharing*

shm_image examples

run image talker and listener

# t1
cd ./install/shm_msgs/lib/shm_msgs/
./image1m_talker

# t2
cd ./install/shm_msgs/lib/shm_msgs/
./image1m_listener

run bridge and rviz2

# configure topic remapping
ros2 launch shm_msgs shm_image_bridge.launch.py

to check the msg flow and visualize the msg

rqt_graph

rviz2

shm_pcl example

run pcl talker and listener

# t1
cd ./install/shm_msgs/lib/shm_msgs/
./pcl2m_talker

# t2
cd ./install/shm_msgs/lib/shm_msgs/
./pcl2m_listener

run bridge and rviz2

# configure topic remapping
ros2 launch shm_msgs shm_pcl_bridge.launch.py

to check the msg flow and visualize the msg

rqt_graph_pcl

rviz2_pcl

shm_open3d example

run open3d talker and listener

# t1
cd ./install/shm_msgs/lib/shm_msgs/
./open3d2m_talker

# t2
cd ./install/shm_msgs/lib/shm_msgs/
./open3d2m_listener

discussions

Comments have been given from github and ros2 community.

Feel free to create issues in the repo.

Basics

zero copy

Zero_copy is a transport layer to get a better performance especially when payload size exceeds 64k.

Please refer Using_Zero_Copy_In_ROS2.pdf for more info of concept of z copy.

In short, zero copy needs api support through all software layers.

For CycloneDDS, see doc from cyclonedds and doc from rmw_cyclonedds for details

For FastDDS, see doc from fastdds and doc from rmw_cyclonedds

minimum copy

Without fixed-length msg, a serialization is needed before IPC, so copy can not be avoided.

But time of copy can still be reduced comparing to Loopback Network Communication(such as udp multicast), which is the default transport layer in most cases of dds.

Performance can still be improved with minimum copy.

dds involved

The eCAL by Continental provides iceoryx transport layer to get true zero copy, but extra cmake based compilation is needed.

refer The performance of eCAL, and Enable ECAL_LAYER_ICEORYX for more details.

eCAL also provides default shm based transport layer to get minimum copy performance, see this issue for details.

Cyclonedds and eCAL both use iceoryx as the z copy transport layer.

Iceoryx alos provide direct access to rmw, see rmw_iceoryx for details.

FastDDS provide zero-copy since v2.2, so with rmw_fastrtps the loaned-api canbe used since ros2-galactic.

acknowledgement

Q&A

todo.

About

ROS2 shm_msg based zero-copy for image and pointcloud.

Topics

Resources

Stars

Watchers

Forks