100% cpu usage
Hi, i've been using audio-mixer in my recent project and noticed 100% audio usage.
The use case where i noticed this is :
- Discord Bot 1 adds audio streams to the mixer
- Discord Bot 2 is reading the mixer to output voice
This test case also has this problem :
- Discord Bot 1 adds audio streams to the mixer
- The mixer outputs the streams in a file
You could think that it would be caused by too many streams, but actually even this test case works:
- Discord Bot 1 is able to add audio streams, but does not (mixer has no Input)
- The mixer outpus the streams in a file -> 100% cpu usage for a while -> the file is empty
When using the profiler, i'm noticing 99% cpu usage for calls to epoll_pwait in c++ wrapper.
I'm guessing this has to do with the usage of ffmpeg ? Is mixer always encoding even when there is no input ? I hope you can help with this :)
I've just implemented the library in the same manner and unfortunately I have 100% cpu usage without even adding an input as well.
I have the same issue
Unfortunately it seems this repo is no longer maintained. I was able to fork the repo (to our company repo) - you will be able to fix the CPU issue by doing the following here: https://github.com/ConnorChristie/Audio-Mixer/blob/master/src/mixer.ts#L82
Replace this bit:
clearImmediate(this._timer)
this._timer = setImmediate(this._read.bind(this));
with
clearTimeout(this._timer)
this._timer = setTimeout(this._read.bind(this), 0);
I dont know what kind of impact it would have in terms of realtime processing. But for our use-case it works and all 2000 unit tests are still passing after this change. But CPU basically went down to 0 :)
@Adrriii I'm guessing this has to do with the usage of ffmpeg - there is no usage of ffmpeg
May I ask: Did you find any alternative ?
@timo-klarshift I don't remember why I mentionned ffmpeg at all, and looking at my project it seems like I didn't seek an alternative. Thank you for the fix though :) I'll close since it's not maintained and a good solution has been provided.
@Adrriii Thanks for answering, but I dont think we should close it :)
Alright :)
Haha super legit 🤣