Closed jigarius closed 2 years ago
I think I found a good read on another issue. I'll try out that solution and reopen this ticket if need be.
If all you do in the task is running another child process, I'd recommend you to take a look at https://github.com/amphp/process instead of using amphp/parallel.
@kelunik thanks a tonne for the suggestion. I read the docs of the amphp/process
and it seems it can meet most of my requirements.
The only answer I can't find at the moment is whether with that library it'll be possible to control the number of processes that run at a time? I want my users to be able to choose the maximum number of child processes that run at a time - a number between 1 and 16. Will that be possible with that library? From what I've read so far, it seems that might be something that I'll have to implement on my own 🤔
Thanks again for the help.
Yes, there are multiple ways to do that. Which version do you plan to use (fiber / PHP 8.1 based AMPHP v3 or v2)? What's the source of your processes? Do you have everything in memory upfront or pull the tasks from somewhere?
php >= 7.4
but if need be, I can make it php >= 8.0
.drall
.drall @@site foo:bar
. Then drall
runs:
drush @site1 foo:bar
drush @site2 foo:bar
drush @siteN foo:bar
@site
value.
@site
are known to the app.......F.....F....W.....
, where F
is failure.Yesternight I tried amphp/process
and it seems to be able to run 50 commands with success.
The only thing I can't figure out is if I can control how many commands run in parallel, e.g. maximum 8 commands run in parallel at a time and the other commands wait till one of those 8 finishes.
If I can figure that out, I'll implement my feature using amphp/process
. Any help will be appreciated. With that info, I will be able to submit a code example to this repo to help others facing similar issues.
@jigarius Here's an example:
#!/usr/bin/env php
<?php
require \dirname(__DIR__).'/vendor/autoload.php';
use Amp\Loop;
use Amp\Process\Process;
use Amp\Sync\LocalSemaphore;
use function Amp\Iterator\fromIterable;
Loop::run(function () {
$values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
yield Amp\Sync\ConcurrentIterator\each(fromIterable($values), new LocalSemaphore(3), function () {
$process = new Process('sleep 1');
yield $process->start();
yield $process->join();
});
});
Thanks a lot! This seems to solve my issue.
Context
DefaultPool
with 8 max workers.The worker crashed
.Questions
References