Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% cpu usage #5

Open
Adrriii opened this issue Feb 23, 2020 · 8 comments
Open

100% cpu usage #5

Adrriii opened this issue Feb 23, 2020 · 8 comments

Comments

@Adrriii
Copy link

Adrriii commented Feb 23, 2020

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

@busheezy
Copy link

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

@timo-klarshift
Copy link

I have the same issue

@timo-klarshift
Copy link

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

@timo-klarshift
Copy link

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

@Adrriii
Copy link
Author

Adrriii commented Dec 11, 2022

@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 Adrriii closed this as completed Dec 11, 2022
@timo-klarshift
Copy link

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

@Adrriii
Copy link
Author

Adrriii commented Dec 12, 2022

Alright :)

@Adrriii Adrriii reopened this Dec 12, 2022
karyeet added a commit to karyeet/Audio-Mixer that referenced this issue Dec 22, 2022
ConnorChristie#5 (comment)

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 :)
@marce1994
Copy link

Haha super legit 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants