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

i852 Improve slow video processing speeds #955

Merged
merged 6 commits into from
Feb 13, 2024

Conversation

bkiahstroud
Copy link
Contributor

@bkiahstroud bkiahstroud commented Jan 4, 2024

Story

Refs

@orangewolf and I determined that the slowness identified in #852 is due to insufficient CPU resources; ffmpeg commands run on large files were being throttled and thus running extremely slowly.

To solve this, we decided that when an audio or video derivative job is triggered, we should put in into a separate Sidekiq queue (i.e. :resource_intensive). We'll have the default worker(s) run all queues other than :resource_intensive. We'll also have a new, separate worker that runs all the other queues plus the :resource_intensive queue. The new worker will have 4x the CPU resources that the default workers have, but only 1 thread.

This effectively creates a powerful "slow lane". :resource_intensive jobs will slow down the separate worker while they're running, but they won't bog down all the jobs since the other workers are still running.

Part 1

This PR implements the first part of the solution described above. Specifically, it:

  • Adds the new :resource_intensive Sidekiq queue
  • Builds out the logic that diverts only audio and video files on the :resource_intensive queue

Expected Behavior Before Changes

Video and audio files get processed by the CreateDerivativesJob in the :default Sidekiq queue

Expected Behavior After Changes

Video and audio files get processed by the CreateLargeDerivativesJob in the :resource_intensive Sidekiq queue

Screenshots / Video

image

Notes

Flow of logic introduced in this PR

flowchart TD
    0([CreateDerivativesJob#perform_later]) -->
    S[CreateDerivativesJob#perform]
    V{Is audio or video?}
    D[CreateDerivativesJobDecorator]
    L{Is CreateLargeDerivativesJob?}
    H([Hyrax logic])
    J[Spawn CreateLargeDerivativesJob]
    S --> D
    D --> L
    L --> |No|V
    L --> |Yes|H
    V --> |No|H
    V --> |Yes|J
    J --> |#super|S
    style H stroke:#f66,stroke-width:2px
    style V stroke:yellow
    style L stroke:yellow
    style 0 stroke:#0f0,stroke-width:2px
Loading

This sets us up for future improvements to derivative job processing
This doesn't work. This commit is only here to document that this
solution was attempted.
There is no way to reassign a job to another queue once it has been
created. To use the new :resource_intensive Sidekiq queue, we need a
separate job class that is configured to use that queue.

Enter CreateLargeDerivativesJob.

It functions exactly the same as CreateDerivativesJob, except that it
queues into the :resource_intensive queue and has a higher priority.
This way, we can have two separate job classes with different Sidekiq
configurations while using the same application logic for both.
At present, this is the only job going into this queue, so specifying a
higher priority doesn't make sense since all jobs in the queue will have
the same priority regardless
@bkiahstroud bkiahstroud marked this pull request as ready for review January 4, 2024 20:45
@bkiahstroud bkiahstroud merged commit 3dffacf into main Feb 13, 2024
6 of 7 checks passed
@bkiahstroud bkiahstroud deleted the i852-improve-slow-video-processing-speeds branch February 13, 2024 00:13
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.

2 participants