Is it possible to use shared memory as IPC on ROS2 foxy?
We would like to compare different DDS vendors for ROS2. We have been using ROS1 so far and instrumented some processes to communicate over shared memory for performance reasons.
As I understood, both FastRTPS/FastDDS and CycloneDDS have or plan to have support for shared memory as IPC. Is anybody aware of what the state of the support is? And if it is supported, can it be used via the ROS middleware layer and how?
Asked by nyquist09 on 2020-09-17 06:35:57 UTC
Answers
Ok, so by aggregating comments from Miguel and Lukic, I successfully validate that DDS can be used with foxy.
To do so, you have to create an XML file called for example shm_profile.xml which will contains :
<?xml version="1.0" encoding="UTF-8" ?>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<transport_descriptors>
<!-- Create a descriptor for the new transport -->
<transport_descriptor>
<transport_id>shm_transport</transport_id>
<type>SHM</type>
</transport_descriptor>
</transport_descriptors>
<participant profile_name="SHMParticipant" is_default_profile="true">
<rtps>
<!-- Link the Transport Layer to the Participant -->
<userTransports>
<transport_id>shm_transport</transport_id>
</userTransports>
</rtps>
</participant>
</profiles>
Then, if you export the two environments variables :
export FASTRTPS_DEFAULT_PROFILES_FILE=`pwd`/shm_profile.xml RMW_IMPLEMENTATION=rmw_fastrtps_cpp
When you run two nodes that communicate on the same computer, you can observe in Wireshark that there are really few RTSP messages.
Now we can do latency, and bandwidth measurement, but that's another story !
Asked by Adrien BARRAL on 2020-10-02 06:04:06 UTC
Comments
As for fastdds, since version 2.3.4 shm_transport is the default transport layer in intral-machine communication, so you don't need any configurations. see https://fast-dds.docs.eprosima.com/en/latest/fastdds/transport/shared_memory/shared_memory.html#enabling-shared-memory-transport
There is the zero_copy transport layer provided for better performance, see this https://fast-dds.docs.eprosima.com/en/v2.3.4/fastdds/use_cases/zero_copy/zero_copy.html#use-case-zero-copy
for general usage for zero-copy transport with rmw_fastrtps, you can try with this repo, https://github.com/ZhenshengLee/ros2_shm_msgs
thanks.
Asked by zhenshengli on 2022-06-20 02:11:12 UTC
Comments
You can find here for FastDDS: https://fast-dds.docs.eprosima.com/en/latest/fastdds/transport/shared_memory/shared_memory.html#enabling-shared-memory-transport
Asked by lukicdarkoo on 2020-09-18 16:02:54 UTC
That's what I have found and got to run in a standalone DDS application. But is it exposed via RMW? How can I have two ROS processes communicating via shared memory when using the RMW?
Asked by nyquist09 on 2020-09-21 01:39:21 UTC
I am facing the same problem as you. I try to use the FastRTPS shared memory. If you look at this discourse post, it's said that Shared Memory is now ready to be used in FastRTPS in Foxy. In this gitub PR on rmw_fastrps, Miguel said that SHM is enabled by default.
I compiled foxy on my computer and when I send topics I can see them passing through the UDP loop back in wireshark.
The FastRTPS documentation say that Shared Memory is disabled by default. I tried to set a custom profile.xml file thanks to the environment variable FASTRTPS_DEFAULT_PROFILES_FILE to enable SHM, but it don't seems to work (I still see messages in wireshark).
So if someone know how to enable this feature, feel free to help us !
Asked by Adrien BARRAL on 2020-09-23 06:42:38 UTC
As I already answered here, you need to add
is_default_profile="true"
on the profile defined in the XML, otherwise ROS 2 will not take the profile into account.Asked by Miguel Company on 2020-10-02 02:40:51 UTC