option to use imagick in preview generation with extended opts #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a PoC that introduces the option of using Imagick for JPEG images in the previews engine.
Motivation
See this blog post.
There are two main areas where we could try to work to optimize tis
Description
This is an attempt at improving this situation through a combination of
This PR would be part number one of said attempt.
The main attractive of imagick in native multithreaded execution if compiled with openMP (the default at least in Debian).
Since we are not interested in implementing everything from scratch but only try to improve the most performance sensitive areas, I have extended
OC_Image
with a new class that over-rides some if its methods.Since there are concerns about using imagick at all and in order to allow flexibility this new mechanism is optional. It can be enabled and tweaked through config options.
preview_use_imagick = false
or the lack ofphp-imagick
revert to the old behavior using GD. Also we allow to disable interpolation to achieve faster previews, which in my opinion is mostly OK since it doesn't matter that much for small thumbnails. An alternative option is to only enable interpolation for themax
preview (the one that shows big if you click on it in the gallery).Goal
Generate the previews as fast as possible without sacrificing much quality.
Testing procedure
I tested these changes with a dataset comprised of 1.5GiB of high quality photos (~100 x 15MiB photos) on a 16 core x86 machine with 64MiB of RAM.
For the reasons stated above, I ran the tests with the following configuration
All the files are already uploaded. The preview cache is cleaned every run with
In Imagick we are using a CATROM filter.
Results
(*) Default settings: 4096x4096 Max preview, all sizes enabled
(**) Awful, unacceptable quality
The multi-process tests (bottom half) are run using the modified Preview Generator -> nachoparker/previewgenerator#1
Conclusions
Imagick can outperform GD while retaining decent quality mainly due to the fact that is multi-threaded. Still the big bottleneck is in the PHP non native part. In order to improve that something like nextcloud#14953 would need to be implemented, or maybe try to optimize the current Previews code flow.
Since this is the case, better results are achieved by using the "multi-process" approach (nachoparker/previewgenerator#1). Even without server modifications, using the traditional GD method we can achieve a 4x speed boost, which would be 5x with Imagick (with the proposed settings).
Just configuring the Preview Generator properly will imply a 4x speed boost and lots of space saved without any other changes.
JPEG quality barely affects performance, but it mostly only affects storage space.
With these changes the user has more options to tweak performance according to their preferences and how powerful their machine is.
Future work
pthreads
orparallel
once there are ZTS PHP packages available (link link) instead of relying on an external script that launches several processes in parallel.Signed-off-by: nachoparker [email protected]