Download the PHP package zepgram/module-multi-threading without Composer
On this page you can find all versions of the php package zepgram/module-multi-threading. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zepgram/module-multi-threading
More information about zepgram/module-multi-threading
Files in zepgram/module-multi-threading
Package module-multi-threading
Short Description This module is a powerful tool for developers who want to process large data sets in a short amount of time
License MIT
Informations about the package module-multi-threading
Multi-Threading for Magento 2
This module is a powerful tool for developers who want to process large data sets in a short amount of time. It allows you to process large collections of data in parallel using multiple child processes, improving performance and reducing processing time.
Installation
Usage
These classes allows you to process a search criteria, a collection or an array using multi-threading.
ForkedSearchResultProcessor
ForkedCollectionProcessor
ForkedArrayProcessor
This class allows you to process an array of data using multi-threading.
ParallelStoreProcessor or ParallelWebsiteProcessor
bin/magento thread:processor command
This command allows running a command indefinitely in a dedicated thread using the Process Symfony Component.
Options
timeout
: Define the process timeout in seconds (default: 300)iterations
: Define the number of iteration (default: 0)environment
: Set environment variables separate by commaprogress
: Show progress bar while executing command
How it works
The thread:processor
command creates a dedicated child process to execute existing command line.
The child process runs the command specified by the user, while the parent process
monitors the child process and can act accordingly. You can define iterations and execute the same command
multiple times with a dedicated child foreach execution.
The ForkedSearchResultProcessor
,ForkedCollectionProcessor
and ForkedArrayProcessor
classes
use a similar approach to process a search criteria or a collection. The process is divided
into several pages, and for each page, a child process is created to run the callback
function specified by the user on each item of that page.
The ParallelStoreProcessor
and ParallelWebsiteProcessor
classes are designed to make it easier
to process a list of stores or websites in parallel. To use either of these classes, you'll need to
provide a callback function that will be called for each store or website in the list. The callback
function should take one parameter, which will be a single store or website object.
Each store or website will be passed to the callback function in a separate process,
allowing faster processing times.
The number of children process cannot exceed the number of stores or websites: for example,
if you have 10 stores, the maximum number of child processes that can be created in parallel is 10.
Here is a breakdown of the parameters:
-
$collection
/$searchCriteria
/$array
: The first parameter is the data source, either aMagento\Framework\Api\SearchCriteriaInterface
for ForkedSearchResultProcessor or aMagento\Framework\Data\Collection
for ForkedCollectionProcessor, and anarray
for ForkedArrayProcessor -
$callback
: This parameter is a callable that will be executed on each item of the collection. It is a callback function that is passed the current item from the collection to be processed. This function should contain the business logic that should be executed on each item. -
$pageSize
: This parameter is used to set the number of items per page. It is used to paginate the collection so that it can be processed in smaller chunks. -
$maxChildrenProcess
: This parameter is used to set the maximum number of child processes that can be run simultaneously. This is used to control the number of threads that will be used by the multi-threading process. If set to 1, by definition you will have no parallelization, the parent process will wait the child process to finish before creating another one. $isIdempotent
: This parameter is a flag set totrue
by default and can be used forForkedSearchResultProcessor
orForkedCollectionProcessor
when your$maxChildrenProcess
is greater than one. While fetching data from database withForkedSearchResult
andForkedCollectionProcessor
you may change values queried: by modifying items on columns queried you will change the nature of the initial collection query and at the end, the OFFSET limit in the query will be invalid because the native pagination system expect the pagination to be processed by only one process. To avoid that, set$isIdempotent
tofalse
.
E.G.: In your collection query, you request all productsdisabled
, in your callback method youenable
and save them in database, then in this particular case you are modifying the column that you request in your collection, your query is not idempotent.
Memory Limit
This module allows to bypass the limitation of the memory limit, because the memory limit is reset on each child process creation. This means that even if the memory limit is set to a low value, this module can still process large amounts of data without running out of memory. However, it is important to keep in mind that this also means that the overall resource usage will be higher, so it is important to monitor the system and adjust the parameters accordingly.
Limitations
This module uses pcntl_fork()
function which is not available on Windows.
Conclusion
This module provides a useful tool for running commands or processing collections and search criteria in a multi-threaded way, making it a great solution for improving performance and reducing execution time. The module is easy to install and use, and provides options for controlling the number of child processes, timeout, and environment variables.
Disclaimer
The Multi-Threading for Magento 2 module is provided as is, without any guarantees or warranties. While this module has been tested and is believed to be functional, it is important to note that the use of multi-threading in PHP can be complex and may have unintended consequences. As such, it is the responsibility of the user of this module to thoroughly test it in a development environment before deploying it to a production environment. I decline all responsibility for any issues or damages that may occur as a result of using this module. With great power comes great responsibility, use it wisely.
All versions of module-multi-threading with dependencies
magento/module-store Version ^101
ext-pcntl Version *
ext-posix Version *