I setup a quick Mojolicious server like this:
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
sleep 5; #sleep here, I'm testing multiple connections at once
$self->render_text('Hello World!');
};
app->start;
I then start it with: perl Mojolicious.pl daemon --listen=https://127.0.0.1:3000
Problem is, if I run this command concurrently:
time curl https://127.0.0.1:3000/ -k
It seems to only use 1 thread for requests, because if I make multiple requests at once, they can take much longer than 5 seconds. It's as if they are all queued up.
Am I missing something here? I'm wanting to use Mojolicous, but only if it can handle more than one client at a time.
mojo daemon
is a standalone HTTP server meant for development use, not production, and it only runs a single thread. For production you would want to either use the fastcgi
option and a FastCGI-supporting webserver, or install a nice PSGI-compatible server like Starman or Starlet or Plack::Handler::FCGI or Fastpass and then do
plackup -s Starman --port 3000 Mojolicious.pl
I recommend Reading The Fine Manual of Mojolicious. The Guides are very important. Specifically the sections regarding Hypnotoad - the built-in pre-forking webserver.
use AnyEvent;
use Mojolicious::Lite;
my @stack = ();
get '/' => sub {
my $self = shift;
$self->render_later;
push @stack, AnyEvent->timer ( after => 5, cb => sub {
$self->render_text('Hello World!');
});
};
app->start;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With