Blackfire Load Testing with Magento and Magento2 – As we all know that if a webpage takes too much time in loading then no one will visit that website, so it is very important for a website a take a less load time. We all know that magento is a complex framework and many blocks and files are called in a single page, so it’s very hard to recognise a method which is taking too much time in loading a page, so using blackfire we can find which method is taking too much time in loading a page.
We know that there are many caching tools which is used to speedup the performance of a website but if there is something wrong with code then nothing will help you out, you will need to optimise the code. So that’s why I am explaining here about blackfire load testing with magento.
For more information about blackfire please check following link – https://blackfire.io/docs/introduction
Blackfire Installation – For this we will need to follow few simple steps-
Step 1 – If want to profile your page via browser then you will need to install a blackfire extension for chrome and for this please follow the link – https://blackfire.io/docs/integrations/chrome .
Step 2 – Now follow the simple instructions given in link https://blackfire.io/docs/up-and-running/installation#installation-instructions to install the blackfire on your magento server.
Step 3 – Now blackfire is successfully installed in your magento.
Blackfire Load Testing with Magento – Here I am profiling the magento home page with backfire.
Now click on the “Profile!” button to test load time of home page.
In the above screenshot we can see that home page is taking 520ms time and now I am calling new product block in home page to display 5 recently added products. Please check the screenshot after adding new product block to home page.
Now home page is taking 802ms in loading page, and when I checked it’s profile graph then we can see the new_grid.phtml is taking 254ms.
I checked the productCollection() method and optimised that method as much as possible, now this we can see that the home page is taking 760ms instead of 802ms, so in this way we can optimise the webpage using blackfire.
Code Before Optimisation –
$collection = Mage::getResourceModel('catalog/product_collection'); $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds()); $collection = $this->_addProductAttributesAndPrices($collection) ->addStoreFilter() ->addAttributeToSort('created_at', 'desc'); return $collection;
Code After Optimisation –
$collection = Mage::getResourceModel('catalog/product_collection'); $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds()); $collection = $this->_addProductAttributesAndPrices($collection) ->addStoreFilter() ->addAttributeToSort('created_at', 'desc') ->setPageSize(5) ->setCurPage(1); return $collection;
Also blackfires offers some built-in metrics for magento https://blackfire.io/docs/reference-guide/metrics#magento-built-in-metrics and some recommendations https://blackfire.io/docs/reference-guide/recommendations which will be helpful to improve the performance of your website.