Performance fixes for magento 2 core.

Overview

magento2-performance-fixes

Performance fixes for magento 2 core.

Problem and solution's concept - briefly

PHP / Magento doesn't support concurency requests. When Magento is handling numbers of requests at the same time (e.g. some headless frontend sent 10 requests at the same time on page load to ask graphql api for data) then each request got information to start building a cache. If cache exists - everything works perfectly but if it doesn't then first request starts building the cache and each next request do the same too.

It's not hard to imagine situation that when some process is slow and takes for instance 2s then every request will try build a cache until building process has been completed by one of requests. It is leading to situation when N requests are doing the same thing and every new request make process slower and slower the process which started before. Finally when we are talking about high traffic websites it's cause redis crash / high and long disk/cpu usage etc.

IMPORTANT: Testing just one request (without high concurrency) you likly won't achive any speed improvments.

Conecept

Requirements

One dependancy: cweagans/composer-patches

Compatibility

This solution provides 3 file changes in core:

  • #1 - magento/framework/Config/Data.patch - 2.3.0+
  • #2 - magento/framework/App/ObjectManager/ConfigLoader.patch - 2.2.0+
  • #3 - magento/framework/Interception/Config/Config.patch - 2.2.0+

Instalation

For this fixes I have chosen fix by vendor's patch. According Magento 2 documentation here: https://devdocs.magento.com/guides/v2.4/comp-mgr/patching/composer.html

  1. Step one

install package by composer:

composer require maritos/magento2-performance-fixes

  1. Extend composer.json
    "extra": {
        "enable-patching": true,
        "magento-force": "override",
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/framework": {
                "performance fix #1 - vendor/magento/framework/Config/Data.php": "vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Config/Data.patch",
                "performance fix #2 - vendor/magento/framework/App/ObjectManager/ConfigLoader.patch": "vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/App/ObjectManager/ConfigLoader.patch",
                "performance fix #3 - vendor/magento/framework/Interception/Config/Config.patch": "vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Interception/Config/Config.patch"
            }
        }
    }
  1. composer install

After composer install make sure patches has been applied. Composer install output should similar to:

  - Applying patches for magento/framework
    vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Config/Data.patch (performance fix #1 - vendor/magento/framework/Config/Data.php)
    vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/App/ObjectManager/ConfigLoader.patch (performance fix #2 - vendor/magento/framework/App/ObjectManager/ConfigLoader.patch)
    vendorPatch/magento/framework/Interception/Config/Config-2.4.x.patch (performance fix #3 - vendor/magento/framework/Interception/Config/Config.patch)

Contributing

Happy to hear your suggestions :)

Testing this solution

Please give me feedback via linkedin https://www.linkedin.com/in/mariusz-lopuch/ what improvment you achived. I will really appriciate it!

Thanks!

You might also like...
🏆 Learn You PHP! - An introduction to PHP's core features: i/o, http, arrays, exceptions and so on.
🏆 Learn You PHP! - An introduction to PHP's core features: i/o, http, arrays, exceptions and so on.

Learn You PHP! The very first PHP School workshop. A revolutionary new way to learn PHP Bring your imagination to life in an open learning eco-system

PeachPie - the PHP compiler and runtime for .NET and .NET Core
PeachPie - the PHP compiler and runtime for .NET and .NET Core

PeachPie Compiler The open-source PHP compiler to .NET If you run into any inconsistencies, bugs or incompatibilities, kindly let us know and we'll do

Core - ownCloud gives you freedom and control over your own data.
Core - ownCloud gives you freedom and control over your own data.

ownCloud Core ownCloud gives you freedom and control over your own data. A personal cloud which runs on your own server. Why is this so awesome? 📁 Ac

Core functionality for Legend of the Green Dragon, a text-based RPG game.

Legend of the Green Dragon (Core) Legend of the Green Dragon is a text-based RPG originally developed by Eric Stevens and JT Traub as a remake of and

A simple but scalable FFA Practice Core featuring one Game Mode & Vasar PvP aspects.
A simple but scalable FFA Practice Core featuring one Game Mode & Vasar PvP aspects.

A simple but scalable FFA Practice Core featuring one Game Mode & Vasar PvP aspects. An example of this Plugin can be found in-game at ganja.bet:19132!

Allows installing Drupal extensions event if not compatible with installed drupal/core package

mglaman/composer-drupal-lenient Lenient with it, Drupal 10 with it. Why? The Drupal community introduced a lenient Composer facade that modified the d

OwnagePE Staff Events Core

An events plugin created for discord.gg/ownage enabling staff members to host small scale events within the respective server.

Automatische Updates für REDAXO Core und Addons

Automatische Updates für REDAXO 5 Lädt täglich automatisch neue Updates aus dem REDAXO-Installer herunter Features Prüft und installiert täglich Updat

MySQL parser for free-id/core package

MySQL parser Installation You can install the package via composer: composer require free-id/mysql Usage use FreeId\Mysql\Parser; $parser = new Parse

Comments
  • Issue with Installing under Mac OS

    Issue with Installing under Mac OS

    Hello,

    So I've got a "magento/product-community-edition": "2.4.1" project where I installed your dependency as per the instructions, but I'm getting an Exception Cannot apply patch performance fix #1 - vendor/magento/framework/Config/Data.php (vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Config/Data.patch)!. After running composer install -vvv I get the error in the image. image

    This is happening only under Mac OS machines, 2 in my team to be precise. I'm personally running Big Sur. We've deviced a solution for this problem locally, so I'm linking it here in case you'd like to test it out. The format of the files seems to be working fine with both Mac OS and our Linux based infrastructure.

    opened by kinowashere 10
  •  Could not apply patch! Skipping. The error was: Cannot apply patch

    Could not apply patch! Skipping. The error was: Cannot apply patch

    Hello, I am trying to apply patch on magento 2.4.4-p2 but I can not do it. I have this error after modify composer.json to add patches and execute composer install.

    • Installing magento/framework (103.0.4-p2): Extracting archive

      • Applying patches for magento/framework vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Config/Data.patch (vendor/magento/framework/Config/Data.php) Could not apply patch! Skipping. The error was: Cannot apply patch vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Config/Data.patch

      [Exception]
      Cannot apply patch vendor/magento/framework/Config/Data.php (vendor/maritos/magento2-performance-fixes/vendorPatch/magento/framework/Config/Data.patch)
      !

    Any solution? Thanks

    opened by IvanVizcaino 3
  • effective measurement

    effective measurement

    I have a few points

    1. It helps to prevent cache stampede but it adds an extra cost to any cache saving activity for a cache lock saing and cache lock waiting

    So it is a trade off, do we have some general guide line to decide when we should apply this? Surely it shouldn't be added for a small store but what about a busy store and a super busy store. What about a super busy installation but having 100 domains, each domain store might be not very busy then should we apply this?

    1. I see you are using a delay within 1-100 mili-seconds (quite big range). Any idea why do we do that? (a popular reference for redis lock https://github.com/ronnylt/redlock-php/blob/master/src/RedLock.php)

    I hope you can share some thoughts @maritos

    opened by onlinebizsoft 1
  • Possible additional fix

    Possible additional fix

    Hello

    When Magento is handling numbers of requests at the same time (e.g. some headless frontend sent 10 requests at the same time on page load to ask graphql api for data) then each request got information to start building a cache. If cache exists - everything works perfectly but if it doesn't then first request starts building the cache and each next request do the same too.

    I saw this exact same issue with a PWA setup and the graphql endpoint, the more custom schema we added the worse performing it got which caused this issue.

    In this PR I improved the schema stitching algorithm to fix the performance issue, we have it on several production sites without issue (known issue is that magento schema stitching functions have a buggy regex with union schema types, but that doesnt affect us). https://github.com/magento/magento2/pull/31879

    Just thought you might be interested in this.

    opened by convenient 5
Releases(v1.0.1)
  • v1.0.1(Jan 12, 2022)

    What's Changed

    • Edit path to Config.patch by @ronangr1 in https://github.com/maritos/magento2-performance-fixes/pull/1
    • Fix file not found in Mac OS by @kinowashere in https://github.com/maritos/magento2-performance-fixes/pull/3

    New Contributors

    • @ronangr1 made their first contribution in https://github.com/maritos/magento2-performance-fixes/pull/1
    • @kinowashere made their first contribution in https://github.com/maritos/magento2-performance-fixes/pull/3

    Full Changelog: https://github.com/maritos/magento2-performance-fixes/compare/v1.0.0...v1.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Mariusz Łopuch
Magento Man :rocket:
Mariusz Łopuch
Fixes WordPress 5.9 global CSS styles specificity issues

Fixes WordPress 5.9 global CSS styles specificity issues

Oliver Juhas 3 Feb 22, 2022
PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.

forceutf8 PHP Class Encoding featuring popular \ForceUTF8\Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strin

Sebastián Grignoli 1.6k Dec 22, 2022
Test essentials for writing testable code that interacts with Magento core modules

Essentials for testing Magento 2 modules Using mocking frameworks for testing Magento 2 modules is counterproductive as you replicate line by line you

EcomDev B.V. 9 Oct 6, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022
Fresns core library: Cross-platform general-purpose multiple content forms social network service software

About Fresns Fresns is a free and open source social network service software, a general-purpose community product designed for cross-platform, and su

Fresns 82 Dec 31, 2022
Core for Geometry Dash Private Server

DX Core Core version: 1.3.001 Supported version of Geometry Dash: 1.0 - 1.3 Required version of PHP: 5.4+ (tested up to 7.4) Setup Upload the files on

DeXotik 5 Oct 22, 2022