Audio-Mixer icon indicating copy to clipboard operation
Audio-Mixer copied to clipboard

100% cpu usage

Open Adrriii opened this issue 6 years ago • 8 comments

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 :)

Adrriii avatar Feb 23 '20 23:02 Adrriii

I've just implemented the library in the same manner and unfortunately I have 100% cpu usage without even adding an input as well.

busheezy avatar May 25 '22 18:05 busheezy

I have the same issue

timofriedlberlin avatar Dec 11 '22 14:12 timofriedlberlin

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 :)

timofriedlberlin avatar Dec 11 '22 16:12 timofriedlberlin

@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 ?

timofriedlberlin avatar Dec 11 '22 16:12 timofriedlberlin

@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 avatar Dec 11 '22 16:12 Adrriii

@Adrriii Thanks for answering, but I dont think we should close it :)

timofriedlberlin avatar Dec 12 '22 10:12 timofriedlberlin

Alright :)

Adrriii avatar Dec 12 '22 12:12 Adrriii

Haha super legit 🤣

marce1994 avatar Feb 21 '24 04:02 marce1994