I developed a transcoder (rtsp->decoder->encoder->rtmp) program based on Gstreamer. It worked as expected. I tested it with multiple child processes via fork(). I’ve noticed that if I spawned 8 processes, each consumed only 1% CPU. But if more processes were added, like 10, each one’s consumption jumped to 4% CPU. You can expect the same phenomenon when using gst-launch method. Attached please find the relevant screenshots.
How to explain this? Any advice to mitigate the CPU usage? Thanks!
I might be able to help optimize the GStreamer pipelines. Can you please share the GStreamer pipeline descriptions that you are using in your application?
Also try monitoring with tegrastats and see if there is memory/swap or else that may be cause the issue.
Also note that increased usage may come from your RTMP server. Monitor its usage with top or htop.
Your suggestion about multiple pipelines in one process reminds me that I developed a program a couple of days ago that created multiple transcoder pipelines/bins in one main loop. I go back to test that program and the result is encouraging in terms of CPU and memory usage. When 10 transcoders are running, the process uses just 10% CPU.
However, I can remember the reason why I switched to multi-process, I need to create/remove transcoders pipeline/bin dynamically. It seemed the resources could not be released completely after removing a pipeline/bin which caused the memory usage to rise steadily. I think I’ve done the clean-up properly after deleting the pipeline. I’ve googled this issue and could not find a solution. Do you think there are tricks of deleting pipelines cleanly but keeping a program running? Thanks!
Have you tried writing a gstreamer application that replicates this memory leak and monitoring with Valgrind? Without seeing how you are actually de-allocating the pipeline and where the leak is coming from it is hard to debug further.
AFAIK you should be able to run multiple pipelines, even with dynamic creation and deletion, within the same GStreamer context without issue.