Is performance in Magento 2 the same as or slower than Magento 1? There are lots of discussions and debates about Magento 2’s performance. All debates are around sample data and Vanilla platform comparison. In this topic Max will share optimisations techniques to have solid page load times for Magento 2.
Also visit my blog: www.maxpronko.com
%in Durban+277-882-255-28 abortion pills for sale in Durban
Real use cases of performance optimization in magento 2
1. REAL USE CASES OF PERFORMANCE OPTIMISATION
MAGENTO 2
by Max Pronko
2. ABOUT ME
➤ former Magento core member
➤ CTO at TheIrishStore and
GiftsDirect
➤ Founder of Pronko Consulting
➤ 7+ years of Magento Experience
➤ Magento 2 Blog
8. STEPS OF PERFORMANCE TUNING
➤ Assess the problem
➤ Measure performance
➤ Identify part of the system critical for performance
improvement
➤ Modify part of system to remove the bottleneck
➤ Measure the performance after modification
➤ If better, adopt it or revert
https://en.wikipedia.org/wiki/Performance_tuningwww.maxpronko.com
9. ECOMMERCE WEBSITE PROFILE
➤ Seasonal business
➤ 4k products
➤ 500 Configurable Products
➤ 2k Configurable Variations
➤ 1.5k Simple Products
➤ 500 Categories
➤ Average Order Value: $100
➤ 2-3 products per Order
www.maxpronko.com
10. BEFORE VS AFTER OPTIMISATION
Before
Category Page
Product Page
Shopping Cart
Checkout Index
0 500 1000 1500 2000
Magento 2 Application
www.maxpronko.com
11. BEFORE VS AFTER OPTIMISATION
After
Category Page
Product Page
Shopping Cart
Checkout Index
0 500 1000 1500 2000
Magento 2 Application
www.maxpronko.com
29. BLOCK CACHE
➤ Reduce number of Database queries
➤ Collection Load
➤ Template processing
➤ Eliminate Inline Translation
www.maxpronko.com
30. ABSTRACT BLOCK CLASS
public function toHtml()
{
$html = $this->_loadCache();
if ($html === false) {
$this->_beforeToHtml();
$html = $this->_toHtml();
$this->_saveCache($html);
}
$html = $this->_afterToHtml($html);
return $html;
}
www.maxpronko.com
31. ABSTRACT BLOCK CLASS
public function toHtml()
{
$html = $this->_loadCache();
if ($html === false) {
$this->_beforeToHtml();
$html = $this->_toHtml();
$this->_saveCache($html);
}
$html = $this->_afterToHtml($html);
return $html;
}
no more final :)
www.maxpronko.com
32. ABSTRACT BLOCK CLASS
protected function _loadCache()
{
if ($this->getCacheLifetime() === null || !$this->_cacheState-
>isEnabled(self::CACHE_GROUP)) {
return false;
}
$cacheKey = $this->getCacheKey();
$cacheData = $this->_cache->load($cacheKey);
if ($cacheData) {
$cacheData = str_replace(//placeholder, //value,
$cacheData
);
}
return $cacheData;
}
www.maxpronko.com
43. PRODUCT LIST
➤ Copy list.phtml and move foreach from the template
➤ Create new ProductList block class
➤ Create new Product/Item block class and item.phtml template
➤ Don’t forget about unique cacheKeyInfo
➤ Layered navigation, filter, toolbar, currency
➤ Set cache_lifetime value for both block classes
www.maxpronko.com
48. ACTIONS
➤ Don’t use getAttributesUsedInProductListing() method
➤ Decrease number of attributes loaded
➤ Decrease number of EAV Tables usage on product page
➤ Enable block cache for each related product
49. ATTRIBUTES CONFIG
namespace MagentoCatalogModel;
class Config extends MagentoEavModelConfig
{
public function getProductAttributes()
{
if (is_null($this->_productAttributes)) {
$this->_productAttributes = array_keys($this->getAttributesUsedInProductListing());
}
return $this->_productAttributes;
}
}
50. ATTRIBUTES CONFIG
namespace PronkoPerformanceModelConfig;
class Related extends MagentoCatalogModelConfig
{
const XML_PATH_PRODUCT_RELATED_ATTRIBUTES = 'catalog/related_product_attributes';
public function getProductAttributes()
{
return array_keys($this->_scopeConfig->getValue(self::XML_PATH_PRODUCT_RELATED_ATTRIBUTES));
}
}
56. X-MAGENTO-VARY
➤ Customer Logged In
➤ Customer Group
➤ Customer Segment (EE only)
➤ Store
➤ Currency
➤ Tax Rates
www.maxpronko.com
57. X-MAGENTO-VARY
X-Magento-Vary = MD5(context data)
sub vcl_hash {
if (req.http.cookie ~ "X-Magento-Vary=") {
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "1"));
}
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
}
www.maxpronko.com
58. VARNISH HASH DATA
➤ 1 Website, no customer groups, same content for guest and logged in
➤ GeoIP functionality
sub vcl_hash {
if (req.url ~ "(?|&)(utm_source|utm_medium|utm_campaign|utm_content|gclid)=") {
set req.url = regsuball(req.url, "&(utm_source|utm_medium|utm_campaign|utm_content|
gclid)=([^&]+)", "");
set req.url = regsuball(req.url, "?(utm_source|utm_medium|utm_campaign|utm_content|
gclid)=([^&]+)", "?");
set req.url = regsub(req.url, "?&", "?");
set req.url = regsub(req.url, "?$", "");
}
hash_data(req.http.X-Currency);
}
www.maxpronko.com
59. VARNISH PERFORMANCE BEST PRACTICES
➤ Warmup pages after website content update
➤ Plan content changes ahead
➤ Run cron to clean up cache, reindex and warmup
www.maxpronko.com
61. MORE PERFORMANCE OPTIMISATIONS
➤ Remove Compare Products feature
➤ Minify and merge JavaScript and CSS
➤ Enable Async Order Grid
➤ Enable Async Transactional Emails
www.maxpronko.com
62. TRACKING AND MARKETING
➤ Asynchronous script loading for everything
➤ Google Tag Manager is good for async
➤ Avoid additional collection loads for Facebook, adWords, etc.
www.maxpronko.com