M2 images slow loading, production mode -> out of memory


I have a M2 Community edition site. (I migrated my old M1 site to M2 with VPS)

  • digitalocean droplet (1 cpu/1G ram/6G swap I will upgrade to more ram, but now its in test phase)
  • php7.2
  • nginx
  • mysql
  • M2 2.3
  • 2-3k products with images

site: magentotest /dot/ xyz

So, the image loading process is so slow.

  • css and js minimify are off (could this be a solution?)
  • varnish off (could this be a solution?)

When I switch production mode and finished, the server gone with out of memory. Yes, eat 7GB memory wow. I think it’s a bug with cronjob, but the database cronjob table clean not a solution.

php-fpm config
memory limit: 1G
zlib compression: on
opcache save comments: 1

fpm pool
max children: 50
max request: 500

http2: on

If you have some tips for better security and performant, pls share me.
Some interesting question:

  • what is the best php-fpm mysql nginx configuration, how calculate it for a VPS with custom hardware (max children and request, compression, cache etc)
  • what is the minimum system requiement for magento2
  • magento2 community edition is very slow and limited? How much the enterprise edition?

Hi @Jsn and welcome.

I’ve not experienced “image loading process is so slow” even in Developer Mode with CSS/JS Minification off. Ideally, you’ll want your PHP memory_limit set to at least 2GB. I’ve found that this makes a huge difference. So, even when you have a High-Spec server, having the memory_limit to anything less has a high impact on performance because it sets a soft-limit.

See how that goes and let me know. Also, ensure that your Full Page Cache is enabled because that also can make your site grind to a halt.

To answer your other questions:

  • I’m not entirely sure on optimum server configuration. For the most part, my Web Server Provider manages most of this.
  • There are Magento’s Requirements
  • I honestly don’t find Magento 2 slow, even in Developer Mode. I think Enterprise Licence is around $30,000 per year.

For further speed tips, checkout Why is Magento 2 so slow? 12 EASY Tips to make Magento 2 faster


Thank you for your answer.

  • full page cache = on
  • I saw your video

So, the first I got php memory limit value.

php -i | grep memory
memory_limit => -1 => -1

-1? wow
My memory limit setting in php.ini is not worked.

I tired php-fpm conf:
php_admin_value[memory_limit] = 2048M
php_value[memory_limit] = 2048M

and in nginx params but not worked. I did restart the php-fpm service:
fastcgi_param PHP_VALUE "memory_limit = 2048M"

By the way, I checked the service status, and I had php7.1 :o how installated and why active this version? I don’t know. I shutted down.

Ok, the -1 value was in cli settings.
I don’t know, why my website is too slow :confused:

Many times the cronjob runs, I have set the value of 60 but still load the processor every 1 minute.
The image loading… oh my g… so slow. 10-15 sec 1 image, I think its not normal.

Cron Job is supposed to trigger every 1 minute, because that’s its heartbeat.

I just noticed, that you said your DO Droplet only has 1G Ram. That won’t do, even if you’re using swap. You want at least a 2G ram Droplet. That’s why increasing your memory_limit isn’t having any effect.

ok, thanks. :slight_smile:
After I set production mod and finished process, the ram will be full. Is it a bug?
Ok, I know just 1 GB ram avaliable on the Droplet, but the images is so so sooo slow. I’ve seen many websites with different engines, I’m new on this terrain, but I live terribly

Resized the droplet to 3cpu 1g memory.
The bug after I resized droplet and set production mode is gone.
PHP can use multi core while run magento builder?
Now the page is faster, but there are many requests and there is a delay in loading the images

If images are slow, then it’s unlikely to be a compilation issue - Because you’re simply trying to download a static asset. Is there a public URL where I can see this issue for myself?

Site public URL: magentotest [dot] xyz

In Chrome inspector network tab: image load 4-5 sec TTFB, the server does not serve for a while.
is it possible to wait for some JS files to load first?
The page is works fine, I immediately see prices, products, but without picture.
The droplet working with 1cpu and 1gb ram with swap at now.

So, I just ran one of your pages through GTMetrix. There’s room for improvement but nothing obvious that would fix your loading times.

As you mentioned, your TTFB for the images is very high. I would assume that’s related to your NginX configuration (not Magento or the Droplet Specs).

But what doesn’t help is that you don’t have any Leverage Browser Caching for your images. Therefore, every time I reload the page my web browser re-downloads the images each time. With Leverage Browser Caching set, my browser would know not to bother downloading the images and just use what it has in its cache. By default, the Magento .htaccess file controls this but relies on you having PHP mod_header enabled to work.

You can see if you have this module installed by checking your PHP Info file. If you don’t see it listed, then Google how to enable both mod_headers and mod_expires for NginX. If it’s anything like Apache, then it should only take 2 minutes to enable.

Also, a CDN wouldn’t hurt.

Thanks for your answer.
I checked my nginx config.

So I include this code
add_header X-debug-message "A media file was served" always;
in top of the nginx.conf.sample and showed in the response header of image content.

I tried again in location /media/ because the the cache control is in, but it didn’t put to image header. May not fall into the right condition.

To be honest, I don’t use NginX so I’m unable to offer anymore guidance on that topic. You’d be better off asking on https://serverfault.com or https://stackoverflow.com.

1 Like