sqexpress
sqexpress

Reputation: 13

opencart site becomes extremely slow after migrating to new server

Problem: site becomes extremely slow after migrating to a new (better) server, and it seems to be related to php image rendering?

Site setup: Opencart 2.0.3.1, ~100 products, ~10 categories. Uses customized theme and VQMod. Site is hosted with IIS (PHP 5.6, IIS PHP Manager) on Windows Server 2012 R2 (both old and new). MySQL DB that supports opencart is running on the same machine.

Old machine: Pentium G2020T (2-core 2-thread, 2.5GHz) with 10G DDR3 running Windows server 2012 R2. (There is an on board NVidia GT520 card, if that matters)

New Machine: Xeon-D 1540 (8-core 16-thread, 2.0-2.6GHz) with 32G DDR4 running Windows Server 2012 R2 (Aspeed AST2400 onboard video card, if that matters)

Symptoms: On the old setup, site loads immediately without any sort of delay, and it is very responsive when navigating through different products. On the new setup, however, it takes about 15-20 seconds just to load the home page, same applies to each individual product.

More details: The 2 servers have identical software setup. The way I migrated the site is by copying over the entire opencart directory over, plus doing the MySQL dump for site data. I cleaned up the cache directories (system/cache, vqmod/cache, etc) after the migration. What I noticed was that it seems like this is somehow related to php rendering images - any page with images loads very slow (on the new machine only). During the load, the "php-cgi" process took about 80% CPU time of a single core on the new host (and persisted for about 20 seconds). It seems php-gd2.dll is eating all that CPU cycles.

What I suspect: I have tried to install a fresh copy of opencart from the Microsoft Web Platform installer and the site was pretty responsive. So I think it rules out any hardware related issues. Here is my list of suspects & questions:

Thanks in advance!

Upvotes: 0

Views: 1675

Answers (2)

chris.dempsey
chris.dempsey

Reputation: 383

I don't have 50 reputation to comment on sqexpress's answer but experienced a similar issue with OpenCart 2.0.3.1 under IIS8 on Windows Server 2012 R2 with PHP 5.4.45 and 7.0.7.

Changing line #13 on /catalog/model/tool/image.php from

if (!is_file(DIR_IMAGE . $new_image) || (filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image))) {

to

if (!is_file(DIR_IMAGE . $new_image) || (filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image))) {

resolves the issue of cache files being re-created on every page load when the original was a file introduced by migrating to a new server.

OpenCart originally used filemtime back in version 1.5.6.4. Unsure when or why it changed to filectime.

Upvotes: 1

sqexpress
sqexpress

Reputation: 13

I figured out the issue - the image cache was not cleaned up during the migration. This caused the engine to try creating the image thumbnails every time the page is requested. After cleaning up the cache the issue was resolved.

Two things remain strange to me:

  1. After a failed caching attempt, why doesn't php-gd2 clean up the cached files and recreate new ones?
  2. The php-gd2 library seems to be very inefficient processing jpeg images - I am still having a hard time understanding the fact that it took a Broadwell 8-core machine 20 seconds to process ~10 pictures (each of them is about 4M in size). Is there any alternative to php-gd2 for image processing?

Upvotes: 0

Related Questions