Improve and Fix Slow Magento 2 Performance Top issues

Adobe released top 10 Performance Best Practices which are silly. In this post we will review it and try to understand can we improve performance following this advice. And also we will provide community-driven advice

Adobe has this top performance issues in the list:

  1. A SYNC ORDER PROCESSING IS NOT ENABLED
  2. A SYNC EMAIL NOTIFICATION IS NOT ENABLED
  3. DEFERRED STOCK UPDATES IS NOT ENABLED
  4. MYSQL/READ REPLICA CONNECTION IS NOT ENABLED
  5. OPCACHE SIZE NOT SET CORRECTLY
  6. CSS UNIFICATION IS NOT ENABLED
  7. CSS MINIFICATION IS NOT ENABLED
  8. JS MINIFICATION IS NOT ENABLED
  9. MAGENTO ECE-TOOLS VERSION IS OUTDATED
  10. UNUSED MAGENTO BANNER

What adobe Wrote:

Adobe’s Customer Engineering team has researched and identified the top 10 common issues that impact Magento Commerce sites. These 10 issues constitute approximately 30% of all issues identified through our Site-Wide Analysis Tool. Through this whitepaper we identify these common issues, explain the potential impact they could have, and recommend best practices to address them. Whether you are starting a new project or managing an existing implementation, Adobe recommends reviewing these issues and incorporating the practices to provide the optimal SITE PERFORMANCE and visitor experience.

Is there a more useless phrase than “Magento 2 best practices” or Magento Certified Developer?

Magento 2 Issues:
Async Order Processing is Not Enabled

However, This optimization really doesn’t impact the performance of the catalog pages and increases debug complexity and development time in several times. It can help you if you are having more than 1 orders per second or 60 orders per minute — 360 orders per hour — 8640 orders per day. For the 99% of the Magento customers, it is not an issue at all.

Async Email Notification is Not Enabled:

Stores > Settings > Configuration > Sales > Sales Emails > General Settings > Asynchronous Sending

Image for post
Image for post

Asynchronous sendingGlobalDetermines if sales emails are sent asynchronously. It is recommended that you enable Asynchronous sending.

Options:
Disable — (Default) Sales emails are sent when triggered by an event.
Enable — (Recommended) Sales emails are sent at predetermined, regular intervals.

This issue the same as previous doesn’t affect the real user catalog browsing experience. It only affects order placement performance and can’t be treated as a top issue.

Deferred Stock Updates is not Enabled

This recommendation the same as the previous 2 doesn’t improve customers' experience and catalog pages performance. It improves only broken by default order placement Magento functionality for high orders volumes per second

Redis Replica Connection is not Enabled

During times of high traffic times, if this feature is disabled, a large number of queries could overwhelm the Primary node of the MySQL database. This could lead to performance degradation or even site outage.

Magento has some issues here. They started With MySQL replica however describes why Redis replica is needed. Both of them are not needed.

By enabling Redis Replica Connections, Magento can spread the load to multiple nodes asynchronously by load balancing SELECT queries across them.

Warning:
• Redis Replica Connection is NOT compatible with Scaled (Split) Architecture and should not be enabled for these environments. Enabling Redis Replica Reads on Scaled (Split) Architecture will generate errors of Redis Connections not being able to connect.
• Redis Replica are still active but will not be used for Redis reads
• Adobe recommends using Magento v2.3.5 and later for Scaled (Split) Architecture and implementing the new Redis Back End Config and implement L2 Caching for Redis.

This is also not the issue because it treating only the symptoms not the issue of Redis bad performance. Magento Core and Extensions Abuses Redis A lot if you are having high traffic you should use DEDICATED Redis on the fastest possible CPU with Multi-threaded enable or you can try to use multithreaded KeyDB. Also, AWS C,R,M6g instance has 30–60% better Redis performance.

Image for post
Image for post
Graviton 2 Redis Performance

Source: https://medium.com/@egorshytikov/redis-php-node-js-aws-graviton-2-c6g-m6g-processor-performance-vs-c5-m5-a1-instances-813b3f023b3f

If you are having good infrastructure nit the broken Magento Cloud which is a replica of the Platform.sh you shouldn't have any issues with Redis until you will have 1000 requests for non-chaced pages.

Why 1000? Because Redis Can easily handle 160K requests per second. Single Magento 2 page generates ~ 100 Redis calls. If you are having more than 100 than you need to fix code, not Redis.

Why Magento Cloud Cloud Redis is garbage?

Because it splits Server power with another service PHP, MYSQL, Crons, Elastic Search, etc. and just replica will not help. You need a dedicated high-performance Redis server.

What about Magento Mysql Replica?

Image for post
Image for post

Magento has approximately 60 — 100 MySQL requests per page. Then you can handle 1000 uncached pages per the smallest AWS EC2 instance if you don’t have fixed Magento 2 Core and 3-d party modules. After 1000 you can use Aurora Db to have up to 15 read replicas. Magento Cloudread replica is silly it isn’t dedicated because it shares infrastructure the same as Redis. However, if you are having issues with the code Red replica will not help. And this is a little bit of math why. Bad implementation of the Magento has 3000 SQL requests per page. 90% of the Magento 2 store implementations are bad and slow. You are lucky if you are in that 10%. However, it is not the developer's issue it is the broken Magento 2 Core issue. Magento 2 is a failure from the release 2.0.

60 000 Req per inst/ 3000 req per page = 20 pages per Mysql instance per sec you can have. By adding a single replica you will not improve performance because you will have 1 read instance and on Master Write-only you need 2 read replicas. After adding 2 read instances Total (3 instances) you can generate 40 pages per second and so on. Pretty weird, isn't it? So only by fixing Magento Core and 3-d party code, using modern technologies, and by offloading features to the Magento-less microservices, you can be really happy

OP Cache Size not set correctly

What 2048MG for opcache code? It shows what the garbage Magento 2 is. Any other solutions work with 128MB (default). However, this recommendation is silly even if you give 100500MB for the chance it will not cache because it has a max file limit.

OPCache stores cached scripts in an HashTable, a data structure with very fast lookup time (on average), so cached scripts can be retrieved quickly. max_accelerated_files represent the maximum number of keys that can be stored in this HashTable. You could think about it as the max number of keys in an associative array. The memory allocated for this is part of the shared memory that OPCache can use, that you can configure it with the opcache.memory_consumption option. When OPCache tries to cache more scripts than the available number of keys, it triggers a restart and clean the current cache.

So let’s just say you configured opcache.max_accelerated_files to 223 and a request to your /home route parse and cache into OPCache 200 scripts. As long as your next requests will need only those 200 scripts OPCache is fine. But if one of the following requests parse 24 new scripts, OPCache triggers a restart to make room for caching those. Since you don't want that to happen you should monitor OPCache and choose an appropriate number.

Keep in mind that one file can be cached more than once with different keys if required with a relative path like require include.php or require ../../include.php. The cleanest solution to avoid this is to use a proper autoload.

You should also set opcache.max_accelerated_files to 100 000 000 max value. The default is 4000. Alos, opcache check timestamp should be disabled on the production server and CLI opcache should be enabled.

By default settings, when PHP file is executed Opcache checks the last time it was modified on disk. Then it compares this time with the last time it cached the compilation of that script. When the file was modified after being cached, the compile cache for the script will be regenerated.

This validation is not necessary for the production server when you know the files never change. To disable timestamp validation add the following configuration

opcache.validate_timestamps=0

CSS Unification is Not Enabled

Magento 2 has the worst frontend page load performance in the entire universe and this advice is not relevant because HTTP/2 protocol came out allowing parallel requests (imagine multiple cashiers instead of one). With multiple cashiers, requests were served quicker as separate smaller requests rather than combined. HTTP/2 gave such massive performance increases, you would expect almost immediate adoption.

Image for post
Image for post

People think that because their server sent out fewer requests, it means their server did less work…but that is false thinking. Your server sends out the same amount of code no matter what. If anything, your server may work harder because you merged. Merging CSS also has a few annoying issues…instead of letting your page render immediately, it now has to wait for your entire CSS to load.

For me…most CSS should be loaded as fast as possible and most JS should be as delayed as possible (UNLESS, there is critical JS like being used for slider above the fold).

“Magento 2 single page loads 7+Mb of Javascript and has a huge DOM. Images are not deferred and the main thread being kept busy for almost half a minute(cause all that JS needs evaluating) and you’re in Heaven. Probably the worst, most amateurish platform for delivering applications. Has to be the most costly disaster that blighted the world of Software in the last 30 years.”

Magento Community Software Engineer

Image for post
Image for post

CSS assets minification is not enabled

JS Minification is Not Enabled

Minification doesn’t improve performance much. You can’t even measure those improvements. Minification removes maintainability. It usually saves about 4–8kb of savings on site size. You can get more savings by compressing a single jpg or removing unused Magento Enterprise functionality.

Magento ECE-Tools Version is Outdated

This Advice is useless because the best practices for Magento is not to use Platform.SH doing business as Magento Commerce Cloud.

Magento Cloud host has several virtual cores (vCPU) per server (2 threads per 1 physical CPU — Intel’s Hyperthreading technology) with everything running on it. PHP, MySQL, Galera Cluster, Redis, ElasticSearch, Java, HaProxy, Nginx, ZooKeeper, heavy Magento Crons, RenitMQ, Docker, NewRelic, BlackFire, GlusterFS Network File Server, other stuff and all these infrastructure elements run twice x2(production and staging share the same instance). And all these processes load several physical cores producing performance issues and Redis splitting will not help. You need real horizontal auto-scaling or serverless with 3 tire architecture to handle a huge amount of traffic.

Image for post
Image for post

Source: https://medium.com/@egorshytikov/magento-adobe-commerce-cloud-performance-for-anovaculenary-com-18149d89c9d8

Also, the Magento cloud doesn’t have proper infrastructure monitoring tools. To provide some tools to Merchants Magento Cloud uses New Relic however it produces 50–200% performance overhead and it is better not to use Old Relic on production.

Unused Magento Banner Functionality

This is true not only for Banners. It is applied to everything in Magento 2. Magento 2 framework has broken architecture — Many Ajax, Slow backend, legacy code, harmful AOD plugins, legacy ORM, Zend Framework 1. The best practice is not to use Magento Enterprise/Commerce because it has more code(Staging) and bad performance and more bugs. Magento 2/1(Open Mage) Open Source is the only right choice. Also, you should avoid using MSI (Multi-Source Inventory) and other bundled with Magento 2 core modules.

Magento Commerce vs Magento 2 Open Source performance:

Image for post
Image for post

To be continued…

Send me it to yegorshytikov@gmail.com

Written by

Magento/APP Cloud Architect. Melting metal server infrastructure into cloud solutions.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store