Build of ROS2 package: Out of memory
Problem
I try to build a ros2 package and run out of memory so that the system gets unresponsive or the process is terminated.
I'm using ros2 foxy on ubuntu 20.04
Hardware
- CPU: 4 x ARM A53
- RAM: 4 GB
- Swap: 0 Byte
Package
It's a single node without any functionality. I've created about 65 custom ros messages as _idl_ files.
As soon as I create subscriber for each message with empty callback functions, the build process ends up in consuming whole memory.
Example Code:
// Subscriber
cust1_gen_Sub = this->create_subscription<my_pkg::msg::Cust1>("cust1_gen", 10, std::bind(&Nd::topic_callback_Cust1_gen, this, _1));
// Callback
void Nd::topic_callback_Cust1_gen(const my_pkg::msg::Cust1::SharedPtr msg) const
{
// empty
}
My CMakeLists.txt
is this
cmake_minimum_required(VERSION 3.5)
project(my_pkg)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Cust1.idl"
...
"msg/Cust65.idl"
DEPENDENCIES builtin_interfaces
)
ament_export_dependencies(rosidl_default_runtime)
include_directories(include/${PROJECT_NAME})
add_executable(Nd xs/nd.cpp)
ament_target_dependencies(Nd rclcpp std_msgs)
rosidl_target_interfaces(Nd
${PROJECT_NAME} "rosidl_typesupport_cpp")
ament_package()
Observation
Observed memory consumption during build by means of _htop_. While building the message file objects, it's up to 800 MB Mem usage
Sometimes it simply stucks for hours, sometimes the process gets aborted after 10 minuts.
Process which consumes whole memory as shown by ps aux
/usr/lib/gcc/aarch64-linux-gnu/9/cc1plus -quiet -I .../my_pkg -I build/my_pkg/rosidl_generator_cpp -imultiarch aarch64-linux-gnu -D_GNU_SOURCE -D DEFAULT_RMW_IMPLEMENTATION=rmw_fastrtps_cpp -D RCUTILS_ENABLE_FAULT_INJECTION -D ROS_PACKAGE_NAME="my_pkg" -D SPDLOG_COMPILED_LIB -isystem /opt/ros/foxy/include my_pkg/Nd.cpp -quiet -dumpbase Nd.cpp -mlittle-endian -mabi=lp64 -auxbase-strip CMakeFiles/Nd.dir/os/Nd/Nd.cpp.o -Wall -Wextra -Wpedantic -std=gnu++14 -fasynchronous-unwind-tables -fstack-protector-strong -Wformat-security -fstack-clash-protection -o /tmp/ccd6zsmm.s
What I've already tried
Building with
$ MAKEFLAGS="-j1 -l1"
$ colcon build --executor sequential
Questions
Is there anything I could try to solve the issue and speed up the build on my device? I was used to build my project on target in ROS1. Is this not suitable for devices of this performance?