Basically, this addresses a very common problem, and you can now use subprocesses to performcomputationally expensive operations without blocking or leaving the Mojolicious event loop. Thisis also a pretty complicated feature, and we'd very much appreciate it getting tested in manydifferent environments.
What about to add pool of subprocesses? Pool would allow to use subprocesses safely in controllers.
#!/usr/bin/perl
use Mojo::Base -strict;
use Mojolicious::Lite;
use Mojo::IOLoop;
any '/' => sub {
my $c = shift->render_later;
Mojo::IOLoop->subprocess(
sub {
sleep 2;
},
sub {
$c->rendered(200);
});
};
app->start;
#!/usr/bin/perl
use Mojo::Base -strict;
use Mojo::IOLoop;
use Mojo::UserAgent;
my $d = Mojo::IOLoop->delay(sub { say 'finish' });
my @uas;
for (0 .. 800) {
push @uas, my $ua = Mojo::UserAgent->new;
$ua->get('http://127.0.0.1:3000' => $d->begin);
}
$d->wait;
Client create many connections to server and on each connection server make fork...
What you're asking for is not a process pool but a process limit.
I am itching to add some features to allow communication with the
subprocess while it is running ...
and for the log messages from the sub process to
flow automatically into the masters log ...
I will create a PR and then you can shred it ... :)
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscribe@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
I'm worried about the comment from Alexey Stavrov. Does it mean that anyone who uses subprocesses exposes not only his app but also the server machine to easy DOS attacks, by allowing anyone to generate thousands of processes on the server ? Is there a way to prevent this in the current implementation ?