versatica / mediasoup

Cutting Edge WebRTC Video Conferencing
https://mediasoup.org
ISC License
6.18k stars 1.12k forks source link

Memory leak #1347

Closed runner365 closed 7 months ago

runner365 commented 7 months ago

Memory leak: Recurrence conditions: 1) 2 or 4 web users join the room; 2) Then push the stream to the room through the tool, such as pushing 20 streams (audio + video) 3) After stopping streaming, the web user also leaves; Finally, the memory cannot be restored. Repeat the above experiment, such as increasing the number of push streams. Even if the push stream is stopped and the user leaves the room, the memory will not be restored.

After repeated trials, if there are no users in the room, there will be no memory leaks by just pushing the stream. But if there are a large number of stream subscriptions, memory leaks will occur;

Because our mediasoup-work is a child process, it is started through nodejs. Memory leak detection tools like Valgrind cannot be used. Is there any good way to do memory testing? I can help reproduce these issues and resolve it.

Test streaming tool: https://github.com/runner365/cpp_streamer Supports using mpegts (h264+opus) as source file to push streaming pressure test mediasoup.

jmillan commented 7 months ago

Which memory is not released, the one of mediasoup-worker process?

The fact that malloc does not release the memory to the system does not necessarily mean that the is a memory leak.

Have you tried using jemalloc instead?

ibc commented 7 months ago

I'm afraid we cannot accept memory leak bug reports that are based on full apps or demo apps and do not precisely point to the exact memory leak. We do run mediasoup with Valgrind and we are not aware of memory leaks.

Another story is that, due to how malloc works, in some cases it takes long for the no longer used memory to be released as Jose said in comment above.

runner365 commented 7 months ago

I'am sorry that I didn't find:

export MEDIASOUP_USE_VALGRIND="true"
export MEDIASOUP_VALGRIND_OPTIONS=${MEDIASOUP_VALGRIND_OPTIONS:="--leak-check=full --track-fds=yes --log-file=./mediasoup_valgrind_%p.log"}

It can use valgrind to check memory leak.

so you said it cause by the system malloc, which will release slowly back to the system. Thanks, I will check whether they can be released back to system. And use valgrind to test them.

ibc commented 7 months ago

As Jose said above, using jemalloc mitigates the problem. We use it in production.

runner365 commented 7 months ago

jemalloc

Thanks, we will try it. we develop sfu server based on mediasoup-demo which is nodejs. we see you has developed rust interface api in mediasoup. Do you use rust in production and discard the nodejs?

ibc commented 7 months ago

Do you use rust in production and discard the nodejs?

We are not discarding NodeJS at all. We use it in production and others use Rust.