承接 trunglv/magento2-concurrent_indexer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

trunglv/magento2-concurrent_indexer

Composer 安装命令:

composer require trunglv/magento2-concurrent_indexer

包简介

Magento2 concurrent indexer with spatie/fork

README 文档

README

Purposes:

Magento 2 already supports multithreading for some indexer processes, but not all of them—specifically, the Product Flat Indexer. The purpose of this module is to:

1. Enable the Product Flat Indexer to run concurrently.

2. Replace the default multithreading functionality in Magento Core with the spatie/fork module. Although I haven't benchmarked it yet, I have a feeling that spatie/fork is faster and seems to be more modern and professional in terms of coding.

Installation

composer require trunglv/magento2-concurrent_indexer

Config

In etc/env.php, we should define MAGE_INDEXER_THREADS_COUNT (Magento2 Core) and a new one, BETA_CONCURRENT_INDEXER_THREADS_ENABLE.

!!!!If you want to use "spatie/fork" , you should enable BETA_CONCURRENT_INDEXER_THREADS_ENABLE

...
'MAGE_INDEXER_THREADS_COUNT' => 3,
'BETA_CONCURRENT_INDEXER_THREADS_ENABLE' => 1

How is multithreading in the Indexer implemented by Magento 2 Core?

CLASS \Magento\Catalog\Model\Indexer\Category\Product\Action
/**
     * Run reindexation
     *
     * @return void
     */
    protected function reindex(): void
    {
        $userFunctions = [];

        foreach ($this->storeManager->getStores() as $store) {
            if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
                $userFunctions[$store->getId()] = function () use ($store) {
                    $this->reindexStore($store);
                };
            }
        }

        $this->processManager->execute($userFunctions);
    }
CLASS \Magento\Indexer\Model\ProcessManager
/**
     * Execute user functions
     *
     * @param \Traversable $userFunctions
     */
    public function execute($userFunctions)
    {
        if ($this->threadsCount > 1 && $this->isCanBeParalleled() && !$this->isSetupMode() && PHP_SAPI == 'cli') {
            $this->multiThreadsExecute($userFunctions);
        } else {
            $this->simpleThreadExecute($userFunctions);
        }
    }

How is multithreading in the Indexer implemented by my module?

CLASS \Betagento\ConcurrentIndexer\Plugin\Indexer\AroundProcessManager
if ($this->config->isEnabled() && $this->config->getThreadCount() > 1 && $this->config->isCanBeParalleled() && !$this->config->isSetupMode() && PHP_SAPI == 'cli') {

    \Spatie\Fork\Fork::new()->concurrent($this->config->getThreadCount())->run(...$userFunctions);
            return;
}

@trunglv Skype : beta.trunglv@outlook.com - email : luuvantrung@gmail.com

vendor/bin/phpstan analyse app/code/Betagento/ConcurrentIndexer/ --level 9
 5/5 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: OSL-3.0
  • 更新时间: 2024-08-15