http://qs1969.pair.com?node_id=1181633

sduggal has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am relatively new to the world of Perl and web frameworks. I have created a Mojolicious application which runs great using daemon on my Windows Server 2008 machine. But when I tried to deploy it using IIS7.5+FastCGI using the information here:

https://translate.google.com/translate?hl=en&sl=ja&u=http://multix.jp/iis8-fastcgi-mojolicious-lite/&prev=search

the application started behaving very slow.

The application is renderd in 4-5 seconds the first time. But subsequent calls are all good, a few ms as with daemon.

I tried to debug what was causing this 5 second delay using an empty mojolicious application, and it seems the first call to start_app takes a long time to execute. Here is the Mojolicious entry point script hello_app.fcgi:

use strict; use warnings; use FCGI; use FindBin; BEGIN { unshift @INC, "$FindBin::Bin/../lib" } use Mojolicious::Commands; if ($ENV{APP_POOL_CONFIG}) { use FCGI; my $request = FCGI::Request(); while ( $request->Accept >= 0 ) { $ENV{MOJO_MODE} = 'production'; # Start command line interface for application Mojolicious::Commands->start_app('HelloApp'); }} else{Mojolicious::Commands->start_app('HelloApp', "cgi"); }

I am struggling at this. Has anyone faced a similar issue. Please point me in the right direction. Thanks

Replies are listed 'Best First'.
Re: Help: Mojolicious+FastCGI+IIS
by Corion (Patriarch) on Feb 10, 2017 at 08:08 UTC

    I'm not sure how FastCGI actually works, but I could imagine that IIS launches the Mojolicious FastCGI process only on the first page request.

    To check this theory, the performance of 4-5 seconds should be same-ish as the performance of your script running as CGI under IIS. Maybe you can also see in the process monitor whether your Perl script gets launched immediately or only after the page is first requested.

    If the startup is the issue, I would consider adding a warmup script that fetches one or more pages via Mojo::UserAgent or whatever to generate a status message and to prime the process and eventual database connections etc.

      Thanks for your reply.

      I checked that Perl script gets initiated immediately with each new request. But for the first time when start_app is called on my Mojolicious application it is taking 4-5 seconds. I have no idea as to what is taking so long when going through IIS.

      Alternately, I have started to explore, http://www.helicontech.com/zoo/, for IIS based deployment. Will let you know if I come up with anything positive.

        Hi

        Mojolicious application it is taking 4-5 seconds. I have no idea as to what is taking so long when going through IIS.

        This sounds very normal, look

        $ mojo generate lite_app [exist] /foo/foo [write] /foo/foo/myapp.pl [chmod] /foo/foo/myapp.pl 744 $ perl -le"print ~~localtime; system $^X, q[myapp.pl], q[daemon] " Sun Feb 12 21:45:01 2017 [Sun Feb 12 21:45:04 2017] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000 Terminating on signal SIGINT(2)

        Sure my machine is old my disk is slow, but 5 seconds for startup sounds rather normal

        Just adding DBI/DBD::SQLite/DBIx::Class/Template/Data::Dumper/Moose bumps it to 6 seconds easy

        $ perl -le"print ~~localtime; system $^X, q[myapp.pl], q[daemon] " Sun Feb 12 21:51:39 2017 [Sun Feb 12 21:51:45 2017] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000 Terminating on signal SIGINT(2)

        It gets a little faster if I do it in a loop but only a little

        $ perl -le"for(1..10){ print ~~localtime; system $^X, q[myapp.pl], q[d +aemon]; } " Sun Feb 12 21:53:07 2017 [Sun Feb 12 21:53:11 2017] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000 Sun Feb 12 21:53:17 2017 [Sun Feb 12 21:53:21 2017] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000 Sun Feb 12 21:53:23 2017 [Sun Feb 12 21:53:27 2017] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000 Sun Feb 12 21:53:29 2017 [Sun Feb 12 21:53:33 2017] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000

        Its all very normal

        Yes you could have some settings in IIS or ... that might contribute some speed penalty ...

        The only option to not have slowdown, is to not have apps available, until they are preloaded -- the user waits either way

Re: Help: Mojolicious+FastCGI+IIS
by Discipulus (Canon) on Feb 10, 2017 at 08:54 UTC
    Hello sduggal and welcome to the monastery and to the wonderful world of Perl!

    As you are relatively new to Perl and webframeworks i feel to suggest you to not start with IIS: I have only a limited and not so recent experience with Perl+IIS but is a dreadful path.

    If you can switch to Linux things will be much simpler to get run.

    If you have some constraint about the OS you can try Apache for windows.

    IIS7 is in my experience a very unfriendly program: CGI on IIS was always a pain and things seem getting even worst. Especially debug web applications running on IIS written in non MS favourite languages, resulted painful to me.

    That said if you must follow this path (IIS7.5+FastCGI) you have all my encouragemnts and I hope you can share here your future results. Thanks for the (even if japanese) page you linked, that is anyway interesting.

    good luck and I hope see more post about this topic here at PM.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Help: Mojolicious+FastCGI+IIS
by Anonymous Monk on Feb 10, 2017 at 07:38 UTC
    Its working as designed?
      I liked you better as the anonymous monk that link dumped at the bottom of every thread useful information opposed to this nonsense at the top

        I liked you better as the anonymous monk that link dumped at the bottom of every thread useful information opposed to this nonsense at the top

        Sure, I can pretend to be that guy , but then wouldn't you just complain about that?

        Why do you consider what I said to be nonsense?

        Is startup instantaneous for anything?

        Is startup on first request not how fastcgi is supposed to work?

        Did you check?

Re: Help: Mojolicious+FastCGI+IIS
by Anonymous Monk on Feb 10, 2017 at 18:48 UTC
    "But when I tried to deploy it using IIS7.5+FastCGI"

    See? Don't do that. Bad programmer. Bad.

    Use Vagrant with Docker or VirtualBox to deploy a real server that can handle real work like that.

      I LOL'd... thanks...