uploads: generate thumbnails in parallel.

Make uploads faster by generating and saving thumbnails in parallel.

We generate each thumbnail in parallel, then send each thumbnail to the
backend image servers in parallel.

Most images have 5 variants: 'preview' (150x150), 180x180, 360x360,
720x720, and 'sample' (850px width). Plus the original file, that's 6
files we have to save. In production we have 2 image servers, so we have
to save each file twice, to 2 remote servers. Doing all this in parallel
should make uploads significantly faster.
This commit is contained in:
evazion
2022-02-04 15:39:00 -06:00
parent fd25cd6868
commit e7744cb6e3
5 changed files with 10 additions and 11 deletions

View File

@@ -271,7 +271,7 @@ class MediaAsset < ApplicationRecord
end
def distribute_files!(media_file)
variants.each do |variant|
Parallel.each(variants, in_threads: Etc.nprocessors) do |variant|
variant.store_file!(media_file)
end
end