Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^11: appending to html at beginning (psgi kids)

by Anonymous Monk
on Mar 03, 2017 at 01:23 UTC ( [id://1183493]=note: print w/replies, xml ) Need Help??


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

And how many workers does apache have? I think thats what you're seeing

This is what I tried, can't get simpler/faster than this, cgi-bin/printenv.pl

#!perl print "Content-type: text/plain; charset=iso-8859-1\n\n"; foreach my $var (sort(keys(%ENV))) { my $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "${var}=\"${val}\"\n"; }

This one does more (loads modules) so it should be slower , dumpenv.psgi started with  plackup -l 127.6.6.6:80 dumpenv.psgi  2>2 1>1

#!/usr/bin/perl -- use CGI(); use Data::Dump qw/ dd pp /; my $app = sub { #~ die "@_"; my $q = CGI->new( $_[0] ); return [ '200', [ 'Content-Type' => 'text/html', 'Content-Length' => '2', ], [ $q->start_html, $q->Dump, $q->end_html, ], ]; };

Then see whats faster

for ( 1 .. 10 ) { cmpthese( 1000, { 'psgi' => q{ # LWP::Simple::get('http://127.0.0.1:5000/'); LWP::Simple::get('http://127.6.6.6:80/'); qw//; }, 'apache2cgi' => q{ LWP::Simple::get('http://localhost/cgi-bin/printenv.pl'); qw//; }, } ); }

I tried it a bunch of times, and psgi is faster "half" the time (ok 4/10 or 3/10)

Rate apache2cgi psgi apache2cgi 194/s -- -23% psgi 252/s 30% -- Rate apache2cgi psgi apache2cgi 261/s -- -35% psgi 400/s 53% -- Rate psgi apache2cgi psgi 296/s -- -5% apache2cgi 311/s 5% -- Rate apache2cgi psgi apache2cgi 215/s -- -32% psgi 314/s 46% -- Rate psgi apache2cgi psgi 257/s -- -14% apache2cgi 300/s 17% -- Rate psgi apache2cgi psgi 261/s -- -19% apache2cgi 323/s 24% -- Rate psgi apache2cgi psgi 255/s -- -19% apache2cgi 315/s 24% -- Rate psgi apache2cgi psgi 275/s -- -14% apache2cgi 318/s 16% -- Rate apache2cgi psgi apache2cgi 201/s -- -34% psgi 302/s 50% -- Rate psgi apache2cgi psgi 275/s -- -17% apache2cgi 332/s 21% --

So is apache "cgi" or psgi faster?

My Apache is configured with ThreadsPerChild 4 -- not sure how many actual workers that is on my machine, but I see two apache processes ... one has 1 thread the other has 6, so 6 or 7 workers?

And psgi still wins 3/10 times? How does that make apache faster?

But yeah maybe the LWP is skewing the benchmark or .... something I dont understand

Replies are listed 'Best First'.
Re^12: appending to html at beginning (psgi kids)
by hippo (Archbishop) on Mar 03, 2017 at 10:09 UTC

    Thanks, but I think you and I are doing completely different comparisons (correct me if I'm wrong).

    My intention here is to compare a very simple CGI script with precisely the same thing running with PSGI as a CGI ie. not in any sort of persistent backend. My (admittedly limited) understanding is that when you run plackup -l 127.6.6.6:80 dumpenv.psgi  2>2 1>1 you are creating a persistent plack server which is going to service the requests as opposed to what I am hoping to measure which is an on-demand set up and tear down single run of a script.

    Your post talks about ThreadsPerChild which is only a concern if there are concurrent requests. Again, I'm not bothered about that for the purposes of this test. I want to know about the single script run in isolation.

    If a persistent backend is used (whichever one is chosen) that ought to be much faster after instantiation than any standalone CGI - that's not in doubt. However, the great big selling point of the Plack middleware is AIUI that the developer can seamlessly switch between various backends including none at all and not have to worry about the protocol intricacies. I'm challenging this selling point when it comes to the none-at-all scenario where we want to run the application as non-persistent CGIs. In that situation my findings are that the use of the middleware imposes what can be a significant performance penalty.

      It's easy today to deploy persistently in multiple ways (couple flavors of FCGI, uwsgi, starman, hynotoad, twiggy) in nginx, apache, and others. I think that's where part of the misunderstandings are entering. I'm surprised to hear any developers deploy anything as on demand-compile-and-execute scripts. It's never desirable (in production at least) and the only reason it might be necessary would be a shared host or something that doesn't support the application server you need.

      Yup yup, i misread the claim

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2026-01-23 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (125 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.