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

Fix slowness problem on the Electron version #1636

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rafaellehmkuhl
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl commented Jan 29, 2025

This patch performs several changes in order to deal with the performance issue caused by the loading of video files that are in the Cockpit video folder:

  • Stop loading all videos automatically to the memory
  • Stop mounting the video-library on startup
  • Loads videos to memory only when they are selected

I've also removed the download-video-button from the electron version, since the video is already on disk. This also helps directing the user to the folder button, which opens the folder that contains the videos.

After this patch, when the user clicks the video, loading it to memory usually takes less than a second (tested with 0-800MB videos). The memory usage increases during that second but goes away right after.

Electron startup before (top is memory usage in mega bytes, bottom is application frames per second):

After:
image

Startup and usage after the patch:

Kapture.2025-01-30.at.16.19.30.mp4

Fix #1608

@rafaellehmkuhl rafaellehmkuhl marked this pull request as ready for review January 30, 2025 18:53
@rafaellehmkuhl rafaellehmkuhl changed the title [WIP] Fix slowness problem on the Electron version Fix slowness problem on the Electron version Jan 30, 2025
@ES-Alexander
Copy link
Contributor

Nice! 😃

Minor concerns:

  1. Could loading a video fully into memory when clicked on cause issues for videos that are larger than the available RAM supports?
    • IIRC part of the benefit of Cockpit's application variant over its browser variant is not being limited by memory capacity for doing long/high-res video recordings, which is kind of lost if you then can't view the files later (but I'm not sure how hard it would be to support loading/unloading chunks, and/or streaming the desired frames from the file)
  2. Is there some way to have thumbnails without loading the full video into memory?
    • At the moment it looks like it would be hard to differentiate the videos without loading each of them, which seems cumbersome
    • Maybe the first frame of a recording can be saved at the start of the recording process, and deleted when the video is?
    • If/when we support Eventing #594 we could store a frame per event and have hover thumbnails for pre-scrubbing when viewing a video as well, and possibly switch the thumbnail to just the frame from the first event (when there is one), but those are future considerations

@rafaellehmkuhl
Copy link
Member Author

Nice! 😃

Minor concerns:

  1. Could loading a video fully into memory when clicked on cause issues for videos that are larger than the available RAM supports?

    • IIRC part of the benefit of Cockpit's application variant over its browser variant is not being limited by memory capacity for doing long/high-res video recordings, which is kind of lost if you then can't view the files later (but I'm not sure how hard it would be to support loading/unloading chunks, and/or streaming the desired frames from the file)
  2. Is there some way to have thumbnails without loading the full video into memory?

    • At the moment it looks like it would be hard to differentiate the videos without loading each of them, which seems cumbersome
    • Maybe the first frame of a recording can be saved at the start of the recording process, and deleted when the video is?
    • If/when we support Eventing #594 we could store a frame per event and have hover thumbnails for pre-scrubbing when viewing a video as well, and possibly switch the thumbnail to just the frame from the first event (when there is one), but those are future considerations
  1. Yes. If you try to load a video bigger than your available memory, your OS will start using swap (or the Windows equivalent) and slow down, but this is expected. At some point we should implement streaming of the video file, but this will take more time, specially because this is not supported on the browser without secure context, so we will need to have separated behaviors for browser vs electron. For the time this patch solves the bug and doesn't affect the UX at all, so it should be enough.
  2. Thumbnails should be working as they were before. They don't appear on my video because they are external big videos that I injected in my instance just for testing, so I didn't had thumbnails for them. The current recording pipeline already stores the first frame as the thumnail in a Base64 format. Are the thumbnails not working there?

Copy link
Contributor

@ArturoManzoli ArturoManzoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing the modifications on the video recording/storing/playing methods, I had the following results:


On Electron:
TEST 1: (Videos recorder on the first Cockpit startup after starting the electron app)

Auto processing:
video 1 - No thumb, not playable
video 2 - No thumb, playble
video 3 - No thumb, not playable
Manual processing:
video 4 - No thumb, playable
video 5 - No thumb, playable
video 6 - No thumb, not playable
video 7 - No thumb, playable


On Electron:
TEST 2: (Rebooted Cockpit keeping the electron app running)

Auto processing:
video 1 - No thumb, playable
video 2 - No thumb, playable
video 3 - No thumb, playable
Manual processing: (after processing videos are not playable right away)
video 4 - thumb while unprocessed, playable only after selecting other video and then this one again
video 5 - thumb while unprocessed, playable only after selecting other video and then this one again
video 6 - thumb while unprocessed, playable only after selecting other video and then this one again


TEST 3: (Cockpit running as web app)
Same results as TEST 2


Main problems are the videos not having thumbs after processed and not being playable right after being processed, needing to be de-selected and re-selected to be playable.

Also Electron performance on first boot wasn't good for video recording. Might be just a coincidence, but half the videos weren't playable.

Below: Video not playable after processing:
image

Below: Videos not playable after recording on fist Electron app startup:
image

@rafaellehmkuhl
Copy link
Member Author

While testing the modifications on the video recording/storing/playing methods, I had the following results:

On Electron: TEST 1: (Videos recorder on the first Cockpit startup after starting the electron app) Auto processing: video 1 - No thumb, not playable video 2 - No thumb, playble video 3 - No thumb, not playable Manual processing: video 4 - No thumb, playable video 5 - No thumb, playable video 6 - No thumb, not playable video 7 - No thumb, playable

On Electron: TEST 2: (Rebooted Cockpit keeping the electron app running) Auto processing: video 1 - No thumb, playable video 2 - No thumb, playable video 3 - No thumb, playable Manual processing: (after processing videos are not playable right away) video 4 - thumb while unprocessed, playable only after selecting other video and then this one again video 5 - thumb while unprocessed, playable only after selecting other video and then this one again video 6 - thumb while unprocessed, playable only after selecting other video and then this one again

TEST 3: (Cockpit running as web app) Same results as TEST 2

Main problems are the videos not having thumbs after processed and not being playable right after being processed, needing to be de-selected and re-selected to be playable.

Also Electron performance on first boot wasn't good for video recording. Might be just a coincidence, but half the videos weren't playable.

Below: Video not playable after processing:

Below: Videos not playable after recording on fist Electron app startup:

Will check about on the thumbs problem.

About the performance not being good for video recording, can you check memory-usage and fps plots and compare with the same numbers on master? There shouldn't be anything worsening the performance in any case, only the opposite.

Also about the thumbs and videos being playable, can you check against master as well?

@ArturoManzoli
Copy link
Contributor

About the performance not being good for video recording, can you check memory-usage and fps plots and compare with the same numbers on master? There shouldn't be anything worsening the performance in any case, only the opposite.

Also about the thumbs and videos being playable, can you check against master as well?

Sure, I'll check those

The video is already in the disk and using this would cause the video to be loaded into memory unnecessarily.
…ents

This way, even if the application is closed by an external player, the last known state is preserved.
@ArturoManzoli
Copy link
Contributor

Test 1 - On Master - Electron
3 videos auto processed, 3 manually.

All videos normal but video 4, that had no thumbnail before being manually processed

Screenshare.-.2025-01-31.2_46_25.PM.mp4

Test 2 - On Master - Web app
3 videos auto processed, 3 manually.**
All videos normal but video 6, that had no thumbnail before being manually processed

Screenshare.-.2025-01-31.2_56_30.PM.mp4


Retesting On Branch - fix-electron-slow
3 videos auto processed, 3 manually.**

Test 1 - Electron App - Using app on first load
No thumbnails generated
Video 3, 5 and 6 were not playable

Screenshare.-.2025-01-31.3_02_40.PM.mp4

**Test 2 - Electron App after reloading
No thumbnails
Only videos 2 and 6 were playable

Screenshare.-.2025-01-31.3_10_26.PM.mp4

Test 3 - Web App
Thumbnail only on video 5

Only video 6 wasn't playable

Screenshare.-.2025-01-31.3_15_14.PM.mp4

This prevents unnecessarily loading big video files into memory, which was happening already on the application startup, causing severe performance issues.
As it deals with heavy data, we have to take more care with it, and not load it when not necessary.
Thumbnail was not being stored after the video was processed. The new approach removes the `thumbnail` property from the video file and instead saves a thumbnail file in the storage.
It was not working, as it was trying to remove a file with the name of the hash, and not files that included the hash.
@rafaellehmkuhl
Copy link
Member Author

rafaellehmkuhl commented Jan 31, 2025

Test 1 - On Master - Electron 3 videos auto processed, 3 manually. All videos normal but video 4, that had no thumbnail before being manually processed

Test 2 - On Master - Web app 3 videos auto processed, 3 manually.** All videos normal but video 6, that had no thumbnail before being manually processed

Retesting On Branch - fix-electron-slow 3 videos auto processed, 3 manually.**

Test 1 - Electron App - Using app on first load No thumbnails generated Video 3, 5 and 6 were not playable

**Test 2 - Electron App after reloading No thumbnails Only videos 2 and 6 were playable

Test 3 - Web App Thumbnail only on video 5

Only video 6 wasn't playable

There were indeed some caveats into the pipeline! There was no thumbnail stored for processed videos. Thanks for the report!
Fixed that and the other problems.
Also fixed a bug that was already on master of not being able to discard unprocessed videos.

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

Successfully merging this pull request may close these issues.

Desktop version of Cockpit (electron) is taking a long time to boot
3 participants