Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^6: appending to html at beginning (don't use CGI.pm)

by hippo (Bishop)
on Feb 03, 2017 at 17:17 UTC ( [id://1180993]=note: print w/replies, xml ) Need Help??


in reply to Re^5: appending to html at beginning (don't use CGI)
in thread appending to html at beginning

I completely agree with this sentiment. Also, it is not the case that CGI.pm is the only pure CGI game in town. I would recommend one of the smaller modules which does not come with the baggage of HTML-generating code as a better place to start. Take your pick from: CGI::Minimal, CGI::Lite, CGI::Simple or even the old CGI::Thin. Any of these would be a gentler introduction than Plack and will be much faster to run in a traditional CGI environment (of which plenty still exist, BTW).

  • Comment on Re^6: appending to html at beginning (don't use CGI.pm)

Replies are listed 'Best First'.
Re^7: appending to html at beginning (don't use CGI.pm)
by haukex (Archbishop) on Feb 03, 2017 at 18:49 UTC

    Hi hippo,

    Also, it is not the case that CGI.pm is the only pure CGI game in town.

    That's a very good point, and I updated my node accordingly.

    ... and will be much faster to run in a traditional CGI environment

    If you mean speed-wise, you may be right, but if you mean how quickly one can get up and running, I think Plack::Handler::CGI makes that relatively easy:

    #!/usr/bin/env plackup use warnings; use strict; use Plack::Request (); my $app = sub { my $req = Plack::Request->new(shift); # access params via e.g. $req->parameters->{...} ...

    Regards,
    -- Hauke D

      If you mean speed-wise, you may be right

      I do and I am. :-)

      About a year ago a new project was starting and it was unclear at that point whether it would be better as a traditional CGI system or using some sort of persistent back-end. Having read of the joys of Plack this sounded to me like an ideal use for it - code the system with Plack and we could switch seamlessly between normal CGI and a persistent application.

      Obviously the first thing to do was to put together a prototype to prove the concept. I wrote a little "hello world" script using Plack (it may even have been lifted directly from the docs) and managed to get it running without much bother as a persistent job. Then I switched over the front end and had it running as traditional CGI. That's when I noticed the speed issue.

      We all expect a CGI script to be slower than a persistent system (that's why there's an F in FCGI after all) but this was noticeably slower. And it seemed to me to be a lot slower than many of the other CGI scripts I would normally use. And it wasn't even doing anything other than respond with "Hello World".

      So I did the natural thing and benchmarked it as a traditional CGI both with Plack and without. It turned out that using Plack slowed down the traditional CGI by about a factor of 6.

      It was decided that this was just too much of a penalty so instead of using Plack I wrote a frontend which had a very simple loading routine that could be called either from CGI or from an FCGI implementation. This added no measurable difference to the execution time of the plain CGIs and meant that we could easily switch between the two approaches as the need arose.

      TL;DR: Plack is a nice idea but while it technically can be used for traditional CGI scripts beware that the penalty is a big slowdown.

        A factor of 6 sounds like a broken benchmark. A plack wrapper is not doing so much that much that it makes sense it would be 600% slower. Though perhaps there is something wonky/unexpected in the CGI handler. Do you have your benchmark on github or someplace to share?

        Hi hippo,

        Thanks very much for the info, that's good to know! If it wasn't obvious yet, I haven't used Plack in a traditional CGI environment very much :-) I try to use persistent processes as much as I can nowadays.

        Regards,
        -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found