ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Running a node on multiple CPU cores

asked 2018-05-16 09:26:33 -0500

eirikaso gravatar image

Hi I am trying to publish a camera stream using the "uvc_camera" ( http://wiki.ros.org/uvc_camera ) package. All works well, but I get a low framerate on high resolution. This seems to be due to cpu overload. When I check the cpu usage with "htop", only one core seems to be used by ROS and all the capacity is used. On the other cores however, only avout 20% capacity is used.

Is there any way to make ROS run this node using multiple cpu cores?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-05-16 09:28:28 -0500

gvdhoorn gravatar image

updated 2018-05-16 09:43:46 -0500

No. Not unless the node itself already uses/supports multithreading.

Note that this is not a ROS limitation, but a basic OS/process scheduling constraint: there is no way to split workloads in the way you ask for by the OS if the program has not been created with multi-core support already.


Edit: something to check: if you built the pkg from source, be sure to build with optimisations enabled. Use a CMake build type that turns those on (ie: Release or RelWithDebInfo). Packages released through and installed from the ROS buildfarm already come with optimisations.

edit flag offensive delete link more

Comments

Interesting! Could you share a link to learn how to write such code? Or perhaps keywords I should search to find such resources? Thanks

parzival gravatar image parzival  ( 2021-04-10 02:26:45 -0500 )edit

Could you share a link to learn how to write such code?

what sort of code?

gvdhoorn gravatar image gvdhoorn  ( 2021-04-10 04:42:48 -0500 )edit

multithreading/multiprocessing

parzival gravatar image parzival  ( 2021-04-10 05:20:44 -0500 )edit

That wouldn't really be ROS specific. Standard multi-threading can be used.

In ROS 1, one thing to keep in mind is that using a MultiThreaded or Async spinner will not automatically make callback processing multithreaded.

gvdhoorn gravatar image gvdhoorn  ( 2021-04-10 05:28:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-16 09:26:33 -0500

Seen: 2,092 times

Last updated: May 16 '18