Performance optimization for Magento shops

23.08.2021
extendedLogo

Good performance is the be-all and end-all of any online shop. A decisive factor here is the load time. If a shop loads too slowly, the user experience suffers considerably. This has a negative impact on the conversion rate and quickly leads to a loss of sales.

Numerous studies prove that there is a direct connection between the speed of a website and the bounce rate. Slow load times are therefore a possible cause for users leaving the online shop they are currently visiting before completing a conversion and, in the worst case, buying from a competitor's shop. In the following, we explain how to recognise performance problems of Magento shops, which tools can help and how the performance can be specifically increased.

Ratio of page load time and bounce rateRatio of page load time and bounce rate | Source: Pingdom

Recognising performance problems

The performance of a shop can be checked using various scenarios. Although a slow website is often noticed very quickly, it is most effective if one or more tools are used to monitor the load time of a Magento shop. In this way, the performance behaviour can also be continuously observed over longer periods of time. At the latest when shop operators have the feeling that the load time does not correspond to the usual value or end customers give corresponding feedback, concrete measurements should be taken.

A slow load time can be the cause of sharp drops in the conversion rate and should be checked from this point of view. This is necessary because the conversion rate can also be influenced by other factors, e.g. unclear navigation structures. There is also a need for action if unexpectedly high load times occur despite an implemented full-page cache such as Varnish.

Tools like Google Analytics measure the speed of a websiteTools like Google Analytics measure the speed of a website | Source: maxcluster

Load time terms

Not all load times are the same. When we talk about the speed or load time of a website, we may be referring to different parameters. Before problems can be solved, it must be ensured that all those involved in the process have the same level of knowledge and have established a uniform definition in advance. In this way, measured values can be precisely determined and analysed.

The most relevant metrics in this context are the "total load time" of the website (incl. JavaScript and images) and the "Time To First Byte" (TTFB). TTFB is the time between the online shop being called up and the first byte being loaded by the web server. It is essentially dependent on the PHP execution time of the Magento shop, but can also be influenced by the network.

In contrast to the TTFB, the total load time of the website refers to the time required to visually display the shop in the end user's browser. For this purpose, the web browser must also load JavaScript, CSS and images and execute the Javascript. Consequently, the total load time of a website is always significantly greater than the TTFB.

Tools for analysis

If you want to sustainably increase and improve the performance of your shop, you must be able to react quickly as soon as problems occur. To do this, it is necessary to keep an eye on all relevant key figures and metrics. The following tools can support the analysis:

  • Google Analytics: The web analysis tool is inserted into pages via JavaScript and measures the complete page load time from the end user's point of view as standard. Factors such as the location and internet connection of the end user (which cannot be influenced by the shop operator) are also included. In addition, Google Analytics can measure the TTFB and display the conversion rate of the page.
  • Matomo (formerly Piwik): This tool is an alternative to Google Analytics. Matomo stores the data on the server itself and is consequently safer than Google Analytics in terms of data protection.
  • WebPageTest: The service provider WebPageTest offers the possibility to execute calls several times from different locations like a browser. In this way, it is possible to see which resources have the greatest influence on the overall load time.
  • Browser tools: Firefox, Google Chrome and also other web browsers can read the total load time of a website, the TTFB, but also the load times of other resources as well as the rendering of the DOM tree (display time of the Document Object Model tree, the data structure of HTML-coded documents, in the browser of the end user) with the help of developer tools already integrated in the browsers. Since both browser tools can already gather a lot of information about a website, problems such as the use of image files that are too large may already be detected here.
  • Google PageSpeed Insight / Google Lighthouse: The Google tools go beyond measuring the speed of websites. In addition, they interpret the results of the measurements and provide concrete tips on how the load time can be improved or which aspects should be examined more closely.
  • Pingdom / Uptime Robot: Some service providers such as Pingdom or Uptime Robot offer monitoring of the availability or load time of online shops. Depending on the tariff booked, either only the TTFB or optionally the entire loading time of a page is measured.
  • Profiler / APM: Profiling or APM tools such as Tideways, New Relic APM or Blackfire IO are used to measure PHP execution times of a website in the background and create traces. If execution times fall below the threshold or many PHP errors occur, the tools can trigger alarms.
Tools What is measured?
Google Analytics, Matomo
Total load time (from user perspective), TTFB, Conversion Rate
    .
WebPageTest
Total load time (simulates accesses from different sites), TTFB
    .
Browser tools
Total load time, TTFB, DOM tree rendering, other load times
    .
Google PageSpeed Insight, Google Lighthouse
TTFB (incl. optimisation tips for frontends)
Pingdom, Uptime Robot
Total load time, TTFB
Tideways, New Relic APM, Blackfire IO
PHP execution time

General tips for increasing performance

There are numerous possibilities for shop operators to improve the load times of Magento shops in general on the application, server and frontend side. We have compiled some tips and tricks for optimising shop performance:

Application optimisation

If you run a Magento online shop, you can modify some settings of the application and enhance it by implementing additional services to improve load times and stability:

Use current PHP version

The release of new PHP versions is usually accompanied by a clear performance boost. It can therefore be worthwhile to operate your own shop with one of the newer PHP versions. Since the release of Magento 2.4.4 in April 2022, Magento has been compatible with PHP 8.1. This will additionally benefit from the JIT compiler introduced with PHP 8.0.

Optimise Magento index management

Magento uses data structures in MySQL and Elasticsearch to retrieve data such as prices or availability more quickly. For example, Magento does not have to calculate the price individually every time a product is called up. Since the status of this data can also change (e.g. in the case of price increases), indexers must be regularly rebuilt. This requires efficient index management and can be done either immediately after a change is saved or via cronjob at a fixed rhythm. Since certain indexes in realtime mode can also be rewritten by user actions, a realtime index may impair performance. If possible, it is recommended to set the corresponding indexers to "update by schedule". Details on this can be found in the Magento documentation.

Use Varnish

An important aspect of Magento performance is caching. The Magento HTTP cache is active by default and can be optionally placed in the file system, Redis or Varnish. For complex websites with dynamic content, experience has shown that the best performance is achieved with the full-page cache Varnish. Information on configuration can be found in the Magento documentation.

Magento HTTP Cache

The Magento HTTP Cache stores complete rendered web pages so that the generation of the pages does not have to be done individually for each user. User-specific information such as the contents of the shopping basket are loaded via additional Ajax requests.

Use Redis

For medium and larger online shops, it is recommended to move the Magento cache and sessions from the file system to Redis. We have summarised all relevant information about this in a separate blog series.

Magento Cache

In addition to the HTTP cache, Magento also has a number of other caches, which are summarised under the term "Magento Cache". This avoids computationally intensive operations during customer requests. For example, layout information, individual blocks or translation data are stored here. Magento modules can also create their own caches.

Sessions

Sessions link visitors to a website with data. This allows, for example, shopping carts to be restored on a later visit.

Server-side optimisation

On the server side, certain settings can also be made and services and modules can be integrated to make a Magento shop more stable and perform better:

Optimise FPM

While it is in principle possible to run PHP directly from Apache via mod_php, it is much more efficient to outsource this process to an independent service using PHP-FPM, a FastCGI process manager. PHP-FPM creates a pool of PHP workers that process the individual requests. Various settings can be made for PHP-FPM. The most important are the number of PHP workers and the scheduler.

The number of PHP workers should depend on the available hardware resources and the expected traffic. Shops with low traffic can easily manage with 10 PHP workers. For shops with increased traffic, however, it is advisable to increase the number.

The chosen PHP scheduler also has an impact on performance. The OnDemand Scheduler terminates PHP workers that are no longer needed very quickly. This means that the PHP RAM load is significantly lower than with the Dynamic Scheduler. However, if the traffic increases, new workers must first be started at the expense of performance. The selection of the correct scheduler is therefore a question of relation of resources and performance.

Optimise PHP OPCache

PHP is a script language that must first be converted into a machine-readable format before it can be executed. To speed up this process, it is possible to cache the result in memory using the so-called PHP OPCache. The current status of the OPCache can be analysed via a special website or the PHP socket with the CLI tool cachetool.

Set up software compression

With the activation of the gzip module, all delivered data is additionally compressed. With the Brotli module, however, there is already a much more efficient method of website compression. The function of Brotli can be checked with the browser tools, for example.

Optimise MySQL settings

The settings of the database server can also have a strong impact on the performance of a Magento shop. Experience shows that the size of the InnoDB buffer pool is the most important setting in this context. This should be large enough to be able to completely cache all InnoDB used.

Use HTTP/2

HTTP protocols also evolve over time. The original HTTP/1.0 protocol from 1991 describes how browsers and web servers communicate with each other. Since 1996, the HTTP/1.1 protocol has existed, which, among other things, allows multiple files to be transferred over the same TCP connection. A major upgrade came in 2015 with the HTTP/2 protocol, which includes multiplexing and improved data transfer between web server and browser. It is recommended to enable HTTP/2 on the server side. This can also be checked with browser or web tools. In 2018, the HTTP/3 standard, which uses the UDP-based transport protocol QUIC instead of TCP, was also completed in the meantime. NGINX and Apache, however, do not currently (as of August 2021) support HTTP/3.

Use IPv6

Since IPv4 addresses have reached their limit, there is already a successor in the form of the IPv6 protocol. The changeover has been taking place in the background for many years. Most users do not even notice it, because even if a provider no longer makes an IPv4 address available to end customers, pure IPv4 web services remain accessible through transitional techniques such as DSLite. Nevertheless, there are advantages to ensuring that the web server is reachable via IPv6. On the one hand, IPv6 is more performant than IPv4, on the other hand, the transition techniques can have a negative impact on performance. In addition, they have sometimes been affected by disruptions in the past. Furthermore, it is conceivable that individual providers will switch off IPv4 completely in the future.

Frontend optimisation

The frontend of a Magento shop can also be optimised with regard to performance and fast loading times:

Compress CSS and JS files.

The more extensive the design of an online shop, the more "Cascading Style Sheets" (CSS for short) are needed. Design elements such as formatting or colour values are stored in CSS files, which are requested by the web server in addition to the HTML documents and multimedia content (images, videos, etc.) when a page is called up. Depending on the size and number of these files, the loading time of the website increases. Compression is achieved, for example, by removing superfluous whitespaces, line breaks or comments. Magento has settings in the backend to perform this process automatically.

Optimise images

A common cause of slow online shops are large images. Google PageSpeed Insight, for example, can provide information about this. For the images, appropriate scaling and efficient coding should be used. There are tools that support the optimisation of images: These include, for example, jpegoptim, jpegtran, pngcrush, optipng, pngout and cwebp. Some service providers also offer the optimisation of images. Although Magento itself does not yet support the WebP format, it is possible to retrofit it with plugins.

Setting up an alternative frontend

When optimising the frontend, you will often find that the "Luma theme" supplied by Magento 2 can only be optimised up to a certain point. This also applies to themes based on the Luma theme.

If the performance is to be increased beyond that, it is possible to run Magento without the Luma theme. Instead, Hyvä, a theme for Magento developed from scratch and designed for performance, can be used. Alternatively, the use of a theme based on a PWA (Progressive Web App) is also worth considering. With PWA Studio, Magento itself offers an alternative PWA frontend. Another option is the PWA solution Vue Storefront, which is largely independent of the underlying shop system.

Excursus: SEO

The subject area of search engine optimisation includes the performance of a website in addition to the quality or structure of its content. Since the speed of web pages can have an impact on conversions and, in e-commerce, also on the sales volume of an online shop (keyword usability), it has been a relevant ranking factor for the Google bot during crawling and indexing since 2010. With regard to SEO, the load time can be shortened, for example, by compressing image files or applying the "lazy load method" (when a web page is called up, the browser only loads the objects that are in the user's immediately visible area).

Solve other performance bottlenecks

While the aforementioned tips can improve the load time and stability of a website in many cases, there are situations in which performance is affected by a specific problem. This can be due to certain Magento modules, for example. In such a case, general optimisation tips do not help, as the cause of the performance bottleneck must first be found. This can be in the server settings, the hardware resources, the PHP processing or even the Magento frontend.

For the server settings, the parameters of the services used, e.g. the PHP workers, should be checked. Even if existing hardware resources are not sufficient, this can have a negative effect on performance. In particular, it should be ensured that enough RAM is available and that the CPU load is always below the number of CPU cores in the medium term.

If the cause lies in the frontend, tools such as Google Pagespeed Insight or WebPageTest can be helpful in narrowing down the problem more precisely. If, on the other hand, the PHP processing is the bottleneck, this can be analysed with a profiler such as Tideways. We have published a separate blog post on this. The video recording linked here contains an introduction to Tideways.

Please feel free to contact our support team if you have any questions or problems. You can reach our service team by phone at 05251/414130 or by email at support@maxcluster.de. Our experienced system admins will be happy to check relevant settings and parameters for you and provide technical support if problems arise.

Performance optimisation at maxcluster

maxcluster customers can carry out numerous performance optimisations conveniently via our Managed Center. Many services and tools from our e-commerce stack are already pre-configured there, and others can be integrated and individually adapted with just a few clicks. In the PDF linked to the download, you will find detailed instructions for the step-by-step performance optimisation of your Magento shop via the Managed Center and the Magento settings. If you have any further questions, our service team will be happy to hear from you or give us a call.

Conclusion

If an online shop loads too slowly, this can have a wide variety of causes. There are many small adjusting screws that can generally contribute to better performance. Caching, software compression or theme optimisation in the Magento frontend are just a few of them. The selection of the right settings depends on the size and requirements of each Magento shop.

If, on the other hand, there is a specific performance problem, its cause must first be found before a concrete solution can be brought about. Numerous tools that measure load times, give recommendations for action or can also recognise bottlenecks provide support here. As soon as the shop performs quickly and stably (again) and any problems are solved, the basis for a good conversion rate and increasing sales is laid.


Last updated on 29.06.2022 | DR, JH

You have questions, requests, criticism, suggestions or just want to tell us your opinion about our blog? Here you have the opportunity to contact us directly.

Send e-mail