Search code examples
perlcgiwebsocketmojolicious

Perl Mojolicious - How to make it handle multiple connections at once?


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.


Solution

  • 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