ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
745 stars 911 forks source link

rospy logging makes unneccessary requests to roscore when /rosout_disable_topics_generation is unset #2337

Open jobafr opened 12 months ago

jobafr commented 12 months ago

Hi,

this is a follow-up to #1855, because I think the fix there was incomplete.

When the parameter /rosout_disable_topics_generation is unset, the call to get_param_cached in https://github.com/ros/ros_comm/blob/noetic-devel/clients/rospy/src/rospy/impl/rosout.py#L91 returns the default value (False), but does not persist that default into the local param cache. Every subsequent call to rospy.loginfo/warn/error will then again query roscore the same way.

I tested this on the current ros noetic ubuntu packages as well as on the current ros_comm noetic-devel branch. When using rospy logging a lot, this can lead to roscore consuming high amounts of CPU time and becoming unresponsive to more useful requests (which is how we noticed the problem).


Steps to reproduce:

Launch three terminal windows:

The second shell now prints this for each log call:

[rosmaster.master][INFO] 2023-07-12 18:54:16,598: +CACHEDPARAM [/rosout_disable_topics_generation] by /foo
[rosmaster.master][INFO] 2023-07-12 18:54:16,599: +CACHEDPARAM [/rosout_disable_topics_generation] by /foo
[rosmaster.master][INFO] 2023-07-12 18:54:16,600: +CACHEDPARAM [/rosout_disable_topics_generation] by /foo
[rosmaster.master][INFO] 2023-07-12 18:54:16,601: +CACHEDPARAM [/rosout_disable_topics_generation] by /foo
[rosmaster.master][INFO] 2023-07-12 18:54:16,603: +CACHEDPARAM [/rosout_disable_topics_generation] by /foo

If you open a fourth shell, and run rosparam set /rosout_disable_topics_generation False, and then execure the same python code again, no '+CACHEDPARAM' calls hit the roscore anymore.


I'm not sure what the correct behaviour would be here.

EricGallimore commented 10 months ago

We're also running into this issue, especially on machines without many CPU cycles to spare.

One simple approach might be to add <param name="rosout_disable_topics_generation" value="False" /> to rosdistro/etc/ros/roscore.xml

(This was inspired by this post: https://answers.ros.org/question/301590/how-to-always-load-a-parameter-without-adding-it-to-every-launch-file/ )

I think that this will preserve the ability to set the parameter in a different launch file, but would set a default so that the caching works.

For now, we're adding that parameter to our top-level launch files.

EricGallimore commented 10 months ago

I should add that has a huge impact on the CPU utilization of rosmaster. On our system, setting this parameter (to either true or false, it doesn't matter which) halves the rosmaster CPU utilization.

jobafr commented 8 months ago

I should add that has a huge impact on the CPU utilization of rosmaster.

Yes, this is how we found this issue in the first place.