Blog

Magento 2 Performance Monitoring and Improvements

Magento 2 Performance Monitoring and Improvements

Optimization for a Magento 2 site is critical for improving sales or conversions. Any area of a Magento site that loads slowly will correlate to a dropoff in visitors, and ultimately a drop in revenue. Magento 2 is a complex eCommerce engine, so sometimes it can be difficult to pin down where problem areas are. Is a single page loading too many blocks? Is a template file loading too much data for a single product page view? Knowing exactly where a bottleneck is makes it that much easier for your web developer to deploy improvements.

There are server configurations that can help, usually these are in the form of cache. Cache tools like Redis, Varnish, etc. will be able to speed up your site, but they can only do so much. If there are problem functions in custom code or 3rd party extensions, these can still cause loads to be much slower than desired.

The same can be said for other optimizations, like Javascript/CSS minification, server compression, image optimization, and other common front-end speed increasing techniques. If a product query function is unoptimized and taking 10 seconds to complete, it won’t matter how small your javascript files are. The server will still have to chug through the unoptimized function.

Blackfire

Blackfire is a powerful utility that can be leveraged to find these performance bottlenecks. Blackfire provides a variety of metrics that can help your developers speed up and identify problem areas in your Magento installation. These metrics include wall time (i.e., the speed in which a function runs), I/O time, CPU time, memory consumption, query speed, and others. Basically, these metrics are extremely granular, and wouldn’t be possible to measure without a tool like Blackfire.

The granularity extends to a function by function basis, so you can determine the exact function in an extension or template that is taking too long to process. This makes it easy to diagnose the site page by page, removing the need for ‘educated guessing’. This helps diagnosing a site as large and complex as a Magento 2 installation much, much faster.

Blackfire Scenarios

Blackfire runs automated tests that you schedule how and when they are run. For example, on Magento Cloud, when you push code to the cloud environment, Blackfire automatically runs the scenario tests that you define and include in your filesystem.

Blackfire scenarios and tests are setup in a yml file. It looks a little something like:

tests:
Pages should be fast enough:
path: /.*
assertions:
- main.wall_time < 850ms
- main.io < 500ms
- main.cpu_time < 500ms

scenarios:
Home:
- /
Cart:
- /checkout/cart/

The structure of the yml file is pretty simple. First, define your tests. There is a lot of documentation here, but your developers will be able to define the tests that should be run. The default tests that come with Magento Cloud Blackfire setup that are a good starting point.

The second set of configurations are the scenarios (or URLs, basically) that you want to automate all the tests for. Blackfire will run all tests at every scenario you list. This can let you get tons and tons of data from a huge variety of URLs.

Blackfire for Chrome

Another cool feature of Blackfire is it’s Chrome extension. It can let you ‘at a glance’ get performance data while you browse around your Magento site. Visit the Chrome extension store and install Blackfire for Chrome. Once enabled you can browse to any URL on your site you would like to profile. Create a reference profile, then click the ‘Profile’ button. Within a few seconds you will have a Call Graph or Comparison Graph to view and see the results.

Take Control

Blackfire can help demystify your Magento 2 installation and provide real data for you and your developers to improve performance. Your reward will ultimately be a better shopping experience for your customers, and real improvemeents for your bottom line.

Share this post!

Leave a reply