-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Catalog image resizing performance problems #8145
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
Tracking internally in one ticket as MAGETWO-60316 |
What is the status of this? It is a BIG issue. |
This is a small update with some new observations seen by testing Magento CE 2.1.6. Watch out, my initial post was about the In my initial post, for the second problem, I suggested to remove the |
And another update: instead of removing |
And yet another update. Manipulating My new proposition is to change this in diff --git a/app/code/Magento/Catalog/Model/View/Asset/Image.php b/app/code/Magento/Catalog/Model/View/Asset/Image.php
index 05f7044cbf1..0fd6690224d 100755
--- a/app/code/Magento/Catalog/Model/View/Asset/Image.php
+++ b/app/code/Magento/Catalog/Model/View/Asset/Image.php
@@ -194,7 +194,20 @@ class Image implements LocalInterface
*/
private function getMiscPath()
{
- return $this->encryptor->hash(implode('_', $this->miscParams), Encryptor::HASH_VERSION_MD5);
+ $miscParams = $this->miscParams;
+
+ // since 'image_type' has no influence as to how an image is manipulated (the resulting files are binary the same if all the other params match),
+ // it makes no sense to include it in the hash caluclation
+ // the best solution would be to remove it, but to avoid introducing new backwards incompatible hashes being generated here,
+ // we decided to hardcode 'image_type' to one which was already in use before: 'thumbnail'
+ // if we simply removed it, we would have to re-run `bin/magento catalog:images:resize`, to again generate all new images, and that's just very annoying
+
+ if (isset($miscParams['image_type']))
+ {
+ $miscParams['image_type'] = 'thumbnail';
+ }
+
+ return $this->encryptor->hash(implode('_', $miscParams), Encryptor::HASH_VERSION_MD5);
}
/** This is for Magento 2.1.6, I haven't checked out the latest |
@hostep, thank you for your report. |
@magento-engcom-team, out of curiosity: any chance you can point me to some commits which fix this? I've search the commit messages for |
@magento-engcom-team: I just retested this on a clean 2.2.0 installation, and can't see any difference in the results, so this issue is definitely not fixed, please reopen :) Evidence for issue number 1 (Magento Blank theme is active on frontend, Luma theme not):Squeeze in a couple of new lines of code on line 63 of the Product\Image\Cache model: // if ($theme->getThemeTitle() == 'Magento Luma') continue;
echo "executing '{$theme->getThemeTitle()}'\n"; $ rm -R pub/media/catalog/product/cache/*
$ php bin/magento catalog:images:resize
executing 'Magento Blank'
executing 'Magento Luma'
.
Product images resized successfully
$ find pub/media/catalog/product/cache -type f | wc -l
35 Now change the newly introduced code and uncomment the first line, so only the Magento Blank theme is processed $ rm -R pub/media/catalog/product/cache/*
$ php bin/magento catalog:images:resize
executing 'Magento Blank'
.
Product images resized successfully
$ find pub/media/catalog/product/cache -type f | wc -l
29 There are less images being produced when only generating them for one single theme, which should happen by default, since Magento Luma isn't in use anywhere. Evidence for issue number 2:$ php bin/magento catalog:images:resize
executing 'Magento Blank'
.
Product images resized successfully
$ find pub/media/catalog/product/cache -type f | wc -l
29
$ find pub/media/catalog/product/cache -type f -exec shasum {} \; | sort
0cc30892e82612b64bc8a69a0ede6e977773341a pub/media/catalog/product/cache/926507dc7f93631a094422215b778fe0/s/c/screen_shot_2017-09-30_at_11.43.47.png
0cc30892e82612b64bc8a69a0ede6e977773341a pub/media/catalog/product/cache/afad95d7734d2fa6d0a8ba78597182b7/s/c/screen_shot_2017-09-30_at_11.43.47.png
0cc30892e82612b64bc8a69a0ede6e977773341a pub/media/catalog/product/cache/c687aa7517cf01e65c009f6943c2b1e9/s/c/screen_shot_2017-09-30_at_11.43.47.png
27734c04683faaf56fbab8694783ac85f49af19c pub/media/catalog/product/cache/cdec6e528c16187a547aea54d9e1d6ee/s/c/screen_shot_2017-09-30_at_11.43.47.png
27734c04683faaf56fbab8694783ac85f49af19c pub/media/catalog/product/cache/dca4079c45c8bedb9968e3d3d4e45631/s/c/screen_shot_2017-09-30_at_11.43.47.png
387c943f6bf316cadbc7f777c25360a936b86358 pub/media/catalog/product/cache/806d6fa663c29d159ca59727157b4a59/s/c/screen_shot_2017-09-30_at_11.43.47.png
4166ad59674e5e41ebe0d7b321d45749dcd2d717 pub/media/catalog/product/cache/2f067dfaa2eefc9cc6820ffd207e9866/s/c/screen_shot_2017-09-30_at_11.43.47.png
4166ad59674e5e41ebe0d7b321d45749dcd2d717 pub/media/catalog/product/cache/3cf5799449660ed39031217945ace72a/s/c/screen_shot_2017-09-30_at_11.43.47.png
43b15e0154462edc6ca4385c843592bc7ceeb296 pub/media/catalog/product/cache/15dc7e9ba1a6bafcd505d927c7fcfa03/s/c/screen_shot_2017-09-30_at_11.43.47.png
43b15e0154462edc6ca4385c843592bc7ceeb296 pub/media/catalog/product/cache/2b4546e5ba001f3aea4287545d649df0/s/c/screen_shot_2017-09-30_at_11.43.47.png
4a205dba28e0a569c55197f04d2eb7602be07da4 pub/media/catalog/product/cache/914b1ba9268f8c1d0e58a8e7ce614488/s/c/screen_shot_2017-09-30_at_11.43.47.png
597873debbacf71bd76fab47d5c85af492753f46 pub/media/catalog/product/cache/0f831c1845fc143d00d6d1ebc49f446a/s/c/screen_shot_2017-09-30_at_11.43.47.png
60e6e629c454e7747ddef89101cc5d601dfeb924 pub/media/catalog/product/cache/633177f689f3c479eab7d48212fd720b/s/c/screen_shot_2017-09-30_at_11.43.47.png
7e1122d6679e7af404873917104af678a4ecabbb pub/media/catalog/product/cache/9b0529d63c590f29ded60308ccd979ee/s/c/screen_shot_2017-09-30_at_11.43.47.png
86c6e5ee0dbb48c5f5b4f54b91fb8f74eb608139 pub/media/catalog/product/cache/a2d2345650965cd6042e53fd7d716674/s/c/screen_shot_2017-09-30_at_11.43.47.png
873706d62738fc28e5ad408a3dee8906f0e218a7 pub/media/catalog/product/cache/81ea8665b1d657e2313096e2818a187e/s/c/screen_shot_2017-09-30_at_11.43.47.png
973b0ad14825f1dcf2cd3cb3faff5d33def81510 pub/media/catalog/product/cache/f073062f50e48eb0f0998593e568d857/s/c/screen_shot_2017-09-30_at_11.43.47.png
98f583c4f2a63ac96d3e0a6467905ecfeda9ef8c pub/media/catalog/product/cache/fd09478435d4f3d9e62d28584118149d/s/c/screen_shot_2017-09-30_at_11.43.47.png
98f583c4f2a63ac96d3e0a6467905ecfeda9ef8c pub/media/catalog/product/cache/fd4c882ce4b945a790b629f572e4ef93/s/c/screen_shot_2017-09-30_at_11.43.47.png
9a424621957c6949cbb316067eebd0691e71821e pub/media/catalog/product/cache/6633e7fcc9a7e88021adbe9a2450a512/s/c/screen_shot_2017-09-30_at_11.43.47.png
9cc63a227559842bfbd478a3f32ca5f6a496def8 pub/media/catalog/product/cache/75eed2686e01eb22cb4050b2f40ddf97/s/c/screen_shot_2017-09-30_at_11.43.47.png
ab9b1014c3905a7718ce99c7dcf31020a725849f pub/media/catalog/product/cache/8a4e709a70e03bf31b178a318a79cf0e/s/c/screen_shot_2017-09-30_at_11.43.47.png
ab9b1014c3905a7718ce99c7dcf31020a725849f pub/media/catalog/product/cache/ee4ee1fe1bbe32e9b93a354df94c32e2/s/c/screen_shot_2017-09-30_at_11.43.47.png
b3efa42d422f39088d1eeb137b114edd138ed8a3 pub/media/catalog/product/cache/3f695f7dd477cbb47cd99d2622d93108/s/c/screen_shot_2017-09-30_at_11.43.47.png
e361be9aefc08e9d924b07b7e6d5c67126e89984 pub/media/catalog/product/cache/ccf7793e39f95beba8c329ba40e7df07/s/c/screen_shot_2017-09-30_at_11.43.47.png
e361be9aefc08e9d924b07b7e6d5c67126e89984 pub/media/catalog/product/cache/f4a2bc458ca2feecb5750446998dc347/s/c/screen_shot_2017-09-30_at_11.43.47.png
e69edb0a25381abe75d0150da41de13b1c4bebe7 pub/media/catalog/product/cache/2f5bcdd08b6b861f73e29326ee14ef04/s/c/screen_shot_2017-09-30_at_11.43.47.png
e69edb0a25381abe75d0150da41de13b1c4bebe7 pub/media/catalog/product/cache/f485795eb4b45ff97c82d72651274f10/s/c/screen_shot_2017-09-30_at_11.43.47.png
f960c5eb18d957cfeb550b0bed7ae74d35c89155 pub/media/catalog/product/cache/3bb5001b99d4c204f1708e92b30dda97/s/c/screen_shot_2017-09-30_at_11.43.47.png You can see a bunch of duplicated hashes which isn't desirable since those images waste a lot of disk space and it takes longer to generate all of those duplicated files. |
@j0um: thanks for the feedback, very good to know! I dug in a little bit and found the commit where all the magic is supposed to be happening: de83f82842d I think the 2nd point from my initial post was tackled, since the It's a bit sad to see that they haven't hardcoded the (Disclaimer: I quickly went through the code, nothing tested yet, might be wrong about all this) Anyways, as for your suggestion to parallelise this process, that's a very good suggestion, you might want to create a new issue for that, maybe create it over at: https://github.com/magento/community-features/issues, otherwise they might close it claiming it is not a bug but a feature request. |
The Or should I update to 2.2.6 if that fixes? |
On Magento 2.2.5 a lot of duplicates. (28 or so per product with 1 image only) Check for your self like this. apt-get install fdupes -y
fdupes -r /var/www/vhosts/yoursite/httpdocs/pub/media/catalog/product/cache I should note, this is not from running the "bin/magento catalog:image:resize" command it just seems to happen over time after deleting the cache directory. Workaround: Replace duplicates with hardlinks shrugs use at own risk. cd yoursite/pub/media/catalog/product/cache
fdupes -r -1 . | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else ln -f ${line// .*/} $file; fi; done; done 4000+ products and the HDD is full... |
In reading though the 2.2.6. release notes, it's made clear that M2 has moved forward with its image generation tool. My only question is, will on-the-fly image generation still be supported? A 90% performance increase is unimportant when the operation takes days (and has never personally completed ever). Have the concerns raised in this ticket been addressed? To sum it up, M2 moved forward with their image generation tool, realized it worked terribly, and then walked it back and reverted to on-the-fly image generation again, which is superior. |
Any updates on if this is fixed? Magento 2.3 is out now. Edit: Nope, still running into this issue of duplicate images in cache. |
For reference to anyone coming by, I'll explain the current state of this command based on my latest experience. I'm using Magento The output of the Here are some of my current numbers:
In other words, it will take 44 hours for this tool to resize all the images in my store for the first time. That's truly devastating performance. At the very least, this is the first time I've discovered an approximate amount of time to run this whole thing, given the two pros mentioned earlier, so my expectations are set (extremely low). Of course, I actually have to run this completely through to see how resilient it is, or whether it can even finish. Other numbers:
More numbers again:
I am sure there is a way to bring that number of thumbnails per product down, but I've not discovered it, yet. I should mention that these images are being generated on a 512GB SSD, so the IOPS is quite high. Does anyone have suggestions to make this better? In its current state, it's clearly anything but an acceptable way of resizing catalog images. Edit: I'd like to note that in both |
Before leaving work yesterday I decided to see how long this operation would truly take. As is tradition, Magento2 failed catastrophically after 45 minutes without further details--providing a shallow message about a fart, when really it should be giving me all the gory details about its crap-filled underwear. Before I could do that, though, it failed multiple times about a This is so comically bad, it deserves its own Jimmy Fallon Thank You Notes bit:
|
Having run into this before; anyone needing to lint images before resize can use ImageMagicks Find malformed/invalid images recursively
EDIT to ignore cache directory use (note the -not -path):
|
a quick suggestion (i apologize if its redundant). Thanks, |
This is still a persistent issue on M2.3.3. I have a multi-store view with 7239 unique images and it's estimated 19 hours before the command completes. I'm watching duplicate images be generated. After upgrading from 2.2.7 -> 2.3.3 all images have to be regenerated due to a change in the way the image hash is generated. This isn't realistic to do when we upgrade a production environment. EDIT: I redeployed the MCloud environment and the current est is 5.9 hours... still way too long for an image set this small. |
@0x15f If you on Magento Cloud then you can try use Fastly image optimization |
That works for the Magento Cloud environment. Thanks! |
@hostep Questions for you: Regarding the
|
Hi @erikhansen We had PR #8142 implemented on one of our bigger shops as a composer patch, but that was on Magento 2.1.x If somebody else has more experience with if Magento 2.3.x still resizes images for non-used themes, feel free to share! |
@hostep Thanks for the details. I applied #8142 as a patch on a small 2.3.3 site with 10 products (each with a single image). The number of images in |
Are you making this up? I don't need another reason to rant. I'm not even over them changing the image hash format from M1 to M2. You saying starting in M233 I now need to host a third image cache (of 191GB) of the same images? It's like they hate search engines. |
unfortunately no joke. the change to the hashes was added in 2.3.0. regenerating the image caches took 5+ days for one of our customer with highres raw images... |
My images broke right after I upgraded and I was told they needed to be re-generated and it solved the issue. I saw something somewhere about the hash method changing. |
@heldchen I'm not seeing any mention of that in the 2.3.0 Release Notes, or in the 2.3.3 Release Notes @0x15f . I'm genuinely curious to know if this is a thing, as my team just upgraded to |
that's because there was no mention about this change. welcome to the wonderful world of magento upgrades... |
@heldchen I mean, I wouldn't be surprised, but to their credit they've been pretty alright about their release notes--and I say this as someone who takes his crapping-on-Magento very seriously. I know they did this sometime in the 2.2.x releases, where they legitimately changed how images get created, and then only later announced it as an addendum and much flack. |
Hi @engcom-Echo. Thank you for working on this issue.
|
Hi, @hostep. Thank you for your report. Please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines |
It looks like the issues brought up in here have been resolved more or less in Magento 2.3.x, so that's good, but I found another huge problem, for which I've created #26796 |
i use multistore - 13 web-sites, ~20.000 products, 31760 images, 2 additional themes. |
Cache folder seems somewhat pointless if you are using Cloudflare or other CDN. |
Preconditions
Steps to reproduce
bin/magento catalog:images:resize
Expected result
Actual result
Discussion
While trying to figure out why it takes over 12 hours to run the command
bin/magento catalog:image:resize
on a very beefy server with a Magento CE 2.1.2 shop with about 6500 products and 8500 images, I found a couple of performance problems in the code:Magento/blank
orMagento/luma
on the frontend, you still get images resized for those themes, and they take a lot of time to generate, so this is not goodIt was always caused by a difference in the
image type
(thumbnail, small_image, image, ...). All the other parameters (width, height, keep frame, transparency, quality, ...) to generate a unique file are correct I think. But I don't think the distinction onimage type
is important, but maybe I'm missing something?Possible solution
'image_type' => $this->getDestinationSubdir(),
Result
I ran a very small benchmark using a test shop with 3 products and 5 images in total. Only
Magento/blank
andMagento/luma
themes are installed and onlyMagento/luma
is active in frontend:After applying PR: 9 seconds, 135 files are generated
After removing line mentioned above: 9 seconds, 130 files are generated
Combined result of both optimizations:
After both optimizations: 7 seconds, 105 files are generated
I think this is a significant enough improvement for you guys to at least consider optimizing this :)
Thanks!
The text was updated successfully, but these errors were encountered: