maritos / magento2-performance-fixes
Magento 2 性能优化。
1.0.1
2022-01-12 08:40 UTC
Requires
README
Magento 2 核心性能优化。
问题和解决方案的概念 - 简要介绍
PHP / Magento 不支持并发请求。当 Magento 同时处理多个请求时(例如,某些无头前端在页面加载时同时发送10个请求以请求数据的 graphql api),则每个请求都会收到启动缓存的信息。如果缓存存在,则一切运行良好,但如果不存在,则第一个请求开始构建缓存,每个后续请求也会这样做。
可以想象,如果某个进程速度较慢,例如耗时2秒,那么每个请求都会尝试构建缓存,直到其中一个请求完成构建过程。这导致N个请求都在做同样的事情,每个新的请求都会使进程变得更慢。最终,当我们谈论高流量网站时,这可能导致 Redis 崩溃、高和长时间的磁盘/CPU 使用率等问题。
重要提示:仅测试一个请求(没有高并发)你很可能无法实现任何速度提升。
要求
一个依赖项:cweagans/composer-patches
兼容性
此解决方案在核心中提供了3个文件更改
- #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+
安装
对于这些修复,我选择了通过供应商补丁的修复。根据 Magento 2 文档,请参阅以下链接: https://devdocs.magento.com/guides/v2.4/comp-mgr/patching/composer.html
- 第一步
使用 composer 安装包
composer require maritos/magento2-performance-fixes
- 扩展 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"
}
}
}
- composer install
在执行 composer install
之后,请确保已应用补丁。Composer 安装输出应类似于
- 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)
贡献
很高兴听到您的建议 :)
测试此解决方案
请通过以下链接在我的领英上提供反馈,说明您取得了哪些改进。我将非常感激!https://www.linkedin.com/in/mariusz-lopuch/
谢谢!