GithubHelp home page GithubHelp logo

Comments (12)

OwenRay avatar OwenRay commented on May 23, 2024

This is partially by design. Unused hls sessions should timeout after about 30 minutes, (that way you can pause the video and not have any activity for a while but still resume).
There is supossed to be a cpu throttling mechanism but it works "less then ideal" with hls.
I'll keep this open because of the cpu usage: we'll need to find a way to pause ffmpeg without it consuming a lot of cpu.

from remote-mediaserver.

sspilleman avatar sspilleman commented on May 23, 2024

I kinda figuered that one out ;-)

You are working with sessions right.... If hou keep a relation on the server between spawned processes and the session id.... Then if you get a new Play request (when seeking).... you are able to find the old spawned process and kill it.... Good idea?

Somewhere along the lines of:

const spawned = {} // this object must "live" outside of the scope of the request (obvously)

// new request
if (spawned[session_id]) spawned[session_id].kill(); // this is where you kill the previous
spawned[session_id] = new Ffmpeg() // this is where you store the pointer to the newly created process

from remote-mediaserver.

OwenRay avatar OwenRay commented on May 23, 2024

That's a good idea, maybe we should consider to reuse the previous session in some way, or properly signal session ending from the client. You don't want to be killing somebody else's session;)

from remote-mediaserver.

sspilleman avatar sspilleman commented on May 23, 2024

A session is unique to a browser session I think. So if you would be using that, you would never kill another users session right?

from remote-mediaserver.

OwenRay avatar OwenRay commented on May 23, 2024

right every single play attempt has a unique session id (including seeking).
as it is now, any time you start playing the hls an x-playback-session-id header is automatically passed by the browser, this is used to determine which session every subsequent request belongs to. If the session-id is not available one is generated.

So, sessions are unique, but right now there is no info who the session belongs to, so there is not enough information to determine which session to kill.
So the way sessions are handled might need a partial rewrite.

from remote-mediaserver.

sspilleman avatar sspilleman commented on May 23, 2024

So If I understand you correctly... Each play request starts another unique session. If so, we'll need to change that I guess... We do need to kill those CPU consuming processes

from remote-mediaserver.

OwenRay avatar OwenRay commented on May 23, 2024

Yes most certainly,
for reference 2 things have to change:

  • The session handling
  • the throttling mechanism

from remote-mediaserver.

sspilleman avatar sspilleman commented on May 23, 2024

As quick hack, we might consider linking the process to the file that is being played instead of the session id and kill if we get another play request for the same video. This will go alright as long as there are no other users playing the same file.... this obviously isn't sustainable ;-) But the current solution isn't sustainable for multiple users anyway based upon the CPU load as it is now.

I quickly don't understand the throttling mechanisch would have to change... You are doing it per request as it is now?

from remote-mediaserver.

OwenRay avatar OwenRay commented on May 23, 2024

well, the throttling mechanism is actually the core of the problem as I see it.
How it works right now:
It monitors the number of buffered chunks that haven't been read by the client. If there are enough chunks available the encoding process is paused. This should mean a dorment session has a 0 load cpu process.
Sadly the hack used to pause ffmpeg actually spins the cpu up to a 100% now.

this.proc.stdin.write('c');

So if we can find some other (cross-platform) way to pause ffmpeg that would already be enough of a solution for now imho.

for mpeg encoding the ffmpeg output stream is paused that works really well. This doesn't work for hls because ffmpeg writes directly to disk.

from remote-mediaserver.

sspilleman avatar sspilleman commented on May 23, 2024

Ah, I see your point.... You've implement the throttling to save on disk space I assume?

They are some pointers here: pause-and-resume-ffmpeg-encoding

Not entirely clear though what solution / platform combo's will work...

you could get the PID with pgrep ffmpeg then use kill -s SIGSTOP to suspend. Then resume kill -s SIGCONT .

This will probably work on unix based OS-es I guess, not sure on windows.... But I kinda assume, most people usinging your repo are on linux/macOS anyway ;-)

from remote-mediaserver.

OwenRay avatar OwenRay commented on May 23, 2024

I do know some people who are using rms on Windows, I don't want to break that support. But we could ofcourse use the current implementation as a fallback for Windows.

from remote-mediaserver.

OwenRay avatar OwenRay commented on May 23, 2024

@sspilleman let me know if this works for you, if not feel free to reopen it;)

from remote-mediaserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.