When Magento was first released, it provided an eCommerce platform that offered functionality not seen before. It still does, but as Magento stores have grown, their requirements have changed. The platform’s functionality now needs to be delivered to an increasingly large customer base, and in an increasingly performant way. For this reason, we’ve made sure that our Magento solutions are optimized to make the best use of the resources available to them.
You’ve probably heard the statistic that “a 1-second delay in page response can result in a 7% reduction in conversions.” This may be overused, but it provides vital insight into what eCommerce customers expect. A single second can be the difference between a Magento store that drives traffic and generates as much profit as possible, and one that falls flat.
“Magento is capable of supporting eCommerce stores of any size, but making the most of that power requires careful optimization.“
Since Magento’s creation, Nexcess has worked to increase performance and optimize Magento environments. Our first guide, released in 2013, helped developers to create incredible, high-performance Magento stores. Stores which beat out the competition when it came to speed, efficiency, and responsiveness.
Our newest guide brings things into 2018 (now 2019), with everything from PHP optimizations, MySQL recommendations, and notes on how to implement Varnish and full-page caching effectively. Moreover, we’ve included all of this in a convenient 68-page book available for any Magento 2 developer who wants to know how to optimize a Magento 2 site.
What Has Changed With Magento 2?
From a technical perspective, Magento 2’s performance has improved since Magento 1; especially with regards to PHP utilization. Changes in how the application handles PHP threads has led to noticeable speed gains and better memory utilization.
Some of the reasons for this performance boost are that Magento 2 supports full-page caching, database improvements, native varnish, a modern code base, and has improved CLI tools.
This may be why in 2018, we saw the average monthly growth of Magento Cloud solutions remain stable at 21%, while by the end of the year, 64% of all hosting solutions supplied by Nexcess remained optimized for Magento.
Yet while the second version of the application originally brought the eCommerce platform in line with the increasing demands of a modern online marketplace, these demands continued to grow. Further performance optimizations have become essential to ensuring that eCommerce businesses are now able to keep pace with their competitors.
How Can I Optimize My Magento Store?
For a full list of Magento 2 optimizations, we highly recommend downloading The Definitive Guide to Optimizing Magento 2. We will cover only a few of the main environment optimizations here.
We also recommend checking out our article Four Ways We Make Your Magento Store Faster, for a more general overview of the techniques and technologies we use.
PHP Optimizations for Magento 2
We’ve discovered several PHP optimizations for Magento 2. These are specifically designed around increasing performance and load times for users.
From a high-level perspective, we’ve managed to improve Magento PHP performance even further by turning out back on mod_php, and opting to use php_fpm instead. Php_fpm allows for the serving of separate php processes to serve dynamic requests, so further performance tuning means improved responsiveness and a reduced memory footprint.
You’ll also find recommendations on php version usage in our guide. With our cloud solutions, it’s possible to set your php version as far back as 5.6. We don’t recommend this as using a newer php version, especially 7.0 or later, will lead to performance improvements and can dramatically reduce memory usage.
At last year’s Imagine, a third-party patch was needed to make Magento 1 compatible with PHP 7.0. As of September 2018, Magento released an official php 7.2 patch, which can be downloaded here.
Some of the PHP optimizations you’ll find in The Definitive Guide to Optimizing Magento 2 include:
- A PHP runtime limitation of 600 seconds.
- A script memory utilization limitation of 768MB
- A POST data size limitation of 512MB
PHP Opcache Optimizations for Magento 2
Opcache is a PHP-caching extension able to improve performance by optimizing what static code is stored in shared memory. This can improve PHP performance dramatically by skipping the intensive compilation process and reading files directly from memory.
By default, however, Opcache is not optimized for Magento. Instead of performance gains, you’re more likely to see performance losses. After careful testing, we found several settings that could easily be optimized by configuring the opcache.ini in the php.d directory.
Some of the Opcache optimizations we recommend are:
- Set opcache.memory_consumption to 512mb
- Set opcache.max_accelerated_files to 65407
- Set opcache.revalidate_freq to 4
MySQL Optimizations for Magento 2
For Magento 2 database optimization, we recommend implementing and optimizing MariaDB as a replacement in the MySQL section of your stack. MariaDB is fast and offers a simplified deployment over CentOS 7.
In general, MariaDB, by default, allocates too many resources to database processes. We’ve found that these numbers can easily be reduced while still providing improved performance.
Some of the MariaDB optimizations we’ve implemented include:
- Single server environments to incorporate a 50% buffer size pool. For systems dedicated to MariaDB this should be increased up to 80%.
- Set query cache size to 2% of your available memory, or 127MB.
We offer a full list of the settings for MariaDB in our GitHub repository at https://github.com/nexcess/magento-whitepaper-april-2018
Further Magento 2 Optimization Recommendations
Tune Your Stack
A well-tuned stack means optimizing the technology that helps to deliver your Magento store. Simply enabling NGINX microcaching can double store performance with no additional modifications. For more information on the stack we offer, see our application stack page.
Enable Full-Page Caching
It was introduced with Magento 2 for a reason. Even if Redis is not available and you need to use local files for caching, full-page caching will pull load away from the PHP interpreter and MySQL, increasing site speed.
Run Modern PHP
With the official update for Magento 1, there is now no excuse to not upgrade to PHP 7.0 or later. If you’re unsure on how it will affect your store, try using a dev site to test and develop safely.
Nexcess Cloud as Changing the Magento Environment
One of the biggest changes the Nexcess Cloud has brought to Magento 2 stores is the inclusion of Nexcess Cloud Auto Scaling. Auto Scaling is a feature which allows for your cloud account to scale the number of concurrent users automatically, whenever your Magento store picks up traffic spikes.
For instance, if you run a sales event which results in your store receiving double the number of guests it normally does, Nexcess Cloud Auto Scaling will allow your store’s concurrent user capacity to increase. This means no rejected page loads and no loss of potential income.