-
Notifications
You must be signed in to change notification settings - Fork 2k
Very bad ImageMagick resizing performance with PHP 7.1 and newer in Docker #1100
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
Comments
#493 is similar, or the same Do you get the same experience outside of Docker? Or with using Debian/Ubuntu packages over the compiled php that the image uses? |
Have you tried to use:
? |
@wglambert If I understand correctly, it’s not exactly the same: #493 is about a performance problem with PHP 7.0 in Docker, while this problem does not occur with PHP 7.0, but only with later versions. Also, that other issue seems to be caused by some Docker image/volume characteristics. It would be weird if that was the case here, since there’s such a huge difference between PHP 7.0 and later versions with this issue (while they share the same Docker host). Unless something radical changed between those PHP versions, which magnifies the Docker issue…
No — on the same EC2 instance, various PHP versions perform great outside of Docker:
I tried several PHP versions in Ubuntu/Debian using the following Dockerfile (using FROM [version]
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y php php-imagick
COPY ./ ./ This yielded the following results:
Interestingly, the problem is not present here in PHP 7.0 and 7.2, but it starts appearing from PHP 7.3 (and in PHP 7.4). So now I have no clue where the cause of the problem is, since we’re seeing the same problem but with different versions here… |
@krzysztof-kabala I did not use I just tried using The performance did not change notably. The big difference between PHP 7.0 and later versions was still present. |
I did some more research, and created the following table (data from
The PHP version does not seem to affect the issue, since versions 7.1 and 7.2 do or do not have the performance problem in different scenarios. Similarly, the Imagick version does not seem to affect it. However, all the scenarios with bad performance are using the same version of ImageMagick: 6.9.10-23. Maybe that points to something? |
WorkaroundAlright, I found a workaround: the They do seem slightly slower than the other performant environment, but that’s ‘just’ a ~50% increase of processing time, rather than 10 times slower (900% increase). I’ve updated the table above to include the specific versions. |
"base" php image:
log:
"custom" php image (with
log:
seems like ImageMagic issue, not a php or docker one :) |
Can confirm -- downloaded the example FROM debian:buster
RUN apt-get update && apt-get install -y --no-install-recommends imagemagick && rm -rf /var/lib/apt/lists/*
COPY imgbench.jpeg /in.jpg
CMD ["bash", "-c", "time convert /in.jpg -filter Lanczos -resize 4000x4000 /out.jpg"] The output is exactly in line with the 19s reported: $ docker run --rm 2d4ff9ec15a0
real 0m15.688s
user 0m19.005s
sys 0m12.027s However, if I replace $ docker run --rm ba076d35c429
real 0m0.391s
user 0m1.823s
sys 0m0.142s So this is firmly a case for a bug at https://bugs.debian.org/src:imagemagick (although possibly an upstream bug), and a potential workaround would be to try to use |
@tianon Thank for your efforts! I will see if I can report this to https://bugs.debian.org/src:imagemagick. For people finding this issue: I tried @tianon’s suggestion of using alternative packages. When using So the easy workaround seems to be using |
If someone reaches this thead: Docker: php:7.3-apache-buster 0.00 seconds - init Docker: php:7.3-apache-buster 0.00 seconds - init For us the easiest fix of the performance problem was to upgrade debian :) |
After updating (from non-Docker PHP 5) to PHP 7.4 in Docker, I was experiencing performance problems with resizing images using ImageMagick. (Details: https://serverfault.com/q/1045274/31887.) After some trial-and-error, it seems that some ImageMagick performance issue is present starting in PHP 7.1 when using the Docker image.
Test script & environment
To investigate the issue, I’ve made the following simple script, with a ~2MB JPEG as input, which resizes the image and prints the time taken for each step:
I created a new AWS EC2
t3.medium
instance with the Amazon Linux AMI and installed Docker usingsudo yum install docker
. Then, I built the following Dockerfile (usingdocker build -t imgbench .
; with[version]
substituted by some valid version):Finally, I ran the test script from above using
docker run -it imgbench php imgbench.php
.All the files used for this test, can be found here: imgbench.zip.
Results
I obtained the following output/results:
It is clear that starting from PHP 7.1, something is wrong with the performance of the
\Imagick::resizeImage()
operation, since it’s approximately 10 times slower than in PHP 7.0.Other factors
I also ran the test script on the same instance without Docker (using PHP from
sudo yum -y install php70-cli php70-common php70-pecl-imagick
) for PHP 7.0, 7.1, and 7.2. All versions showed similar (good) performance, indicating that the problem is not related to the PHP version itself, but rather something in the Docker image.Also, I tried a Dockerfile without using
install-php-extensions
from mlocati/php-extension-installer, by installing ImageMagick manually in the Dockerfile:RUN apt-get update \ && apt-get install -y libmagickwand-dev \ && pecl install imagick-3.4.4 \ && docker-php-ext-enable imagick
This yielded similar performance as reported above (i.e., good performance on PHP 7.0, and bad performance on newer versions).
The text was updated successfully, but these errors were encountered: