muralikg / puppetcam

Export puppeteer tab as webm video
MIT License
322 stars 62 forks source link

Long duration recordings #17

Open rajatbarman opened 4 years ago

rajatbarman commented 4 years ago

Hey,

My use case is to record a url where a video conference meeting is happening for more than an hour. There could be >30 meetings happening concurrently. There is a cron job which runs at 11AM daily, which fetches the scheduled meetings for today and spawns instances of export.js when the meeting starts. Some recordings do happen successfully but most of them emits one of the following errors -

Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed. Error: Page crashed! Error: Protocol error (Runtime.callFunctionOn): Target closed.

My guess was that the recording video chunks are kept in browser memory (in background.js) and then on stop they are written to disk, and if the video file is large the process runs out of memory, so I tried running node export.js script with --max-old-space-size=2048 but still the same errors. Does the puppeteer browser run out of memory? How to increase the limit for that? I saw the CPU usage of machine, it is well under limit.

Also this might not be the appropriate place to ask this, but I am desperate to get an answer.

MJunaidAhmad commented 4 years ago

Can you please tell me your server RAM size?

rajatbarman commented 4 years ago

70GB, I feel the machine is well resourced, its the processes that are not able to utilise the resources. Also, I see .crdownload files in Downloads folder, which indicates chrome was downloading the recorded blob and it crashed or something in between and the download couldn't complete.

Is --disable-dev-shm-usage flag useful?

muralikg commented 4 years ago

Does it crash after same duration everytime or after same size of exported video? That could indicate that the process could be running out of space. If that is the case you could simply write to multiple files and then concatenate the files after the recorder stops.

muralikg commented 4 years ago

Also check if /dev/shm has limited space. With limited space in /dev/shm --disable-dev-shm-usage might be helpful

rajatbarman commented 4 years ago

Thanks for the quick responses, will try with --disable-dev-shm-usage flag.

I couldn't see any pattern of time during crashes, sometimes it crashes in the middle of the recording, sometimes after it is done and the file is being written to disk.

rajatbarman commented 4 years ago

This is test-schedule.js https://gist.github.com/rajatbarman/43510e987040c763c3c22d45c13aa0c6

This is test.js https://gist.github.com/rajatbarman/f5587a9cf1a43199eeb6a519d85201dd

Then I do pm2 start test-schedule.js and getting those errors.