ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
123 stars 139 forks source link

High memory usage on log burst #691

Open kamibo opened 1 year ago

kamibo commented 1 year ago

Bug report

Required Info:

Steps to reproduce issue

Launch one or many nodes that logs a lot (using functions such as RCLCPP_INFO and a 1ms timer for instance).

Expected behavior

ros2 launch should be stable regarding regarding memory usage.

Actual behavior

ros2 launch keeps on consuming memory.

Additional information

launch_service queue (asyncio.Queue()) has no limit. And only one event is handled per loop cycle (this_loop.create_task(self._process_one_event())). So the queue keeps growing until no memory left.

Note that trying to handle many events in _process_one_event seems to solve the issue.

ZhenshengLee commented 9 months ago

@kamibo Thanks for your report!

I also noticed about the heavy memory usage of launch.py, in Foxy version.

Could you tell me which command you use to monitor the memory usage of ros2 nodes or processes? Any recommendation tool besides top?

Thanks.

kamibo commented 9 months ago

@ZhenshengLee Actually I've used htop.

HyeKaguya233 commented 8 months ago

Could you share the method you used to solve this?I also had this problem.

kamibo commented 8 months ago

Could you share the method you used to solve this?I also had this problem.

Actually I'm not sure about the proper way to fix this. But you can try to add a while loop around message handling in _process_one_event.

launch_service.py

async def _process_one_event(self) -> None:                                                                                                                                                            
    while not self.__context._event_queue.empty():
        next_event = await self.__context._event_queue.get()
        await self.__process_event(next_event)   
HyeKaguya233 commented 8 months ago

i will try,thx!!