You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Brice D Ruth <br...@webprojkt.com> on 2001/10/16 18:06:58 UTC

cgi to mod_perl question

  I have a perl script that was running fine under IIS/5.0 with 
ActivePerl 6xx - I'll put the salient parts here:

use IO::Socket;
use CGI;

$in = new CGI;

$server = IO::Socket::INET->new( PeerAddr=> "...",PeerPort=> 
...,Proto=>"tcp",Type=> SOCK_STREAM) or die "Error message ... $@";

$server->autoflush(1);

... (information is gotten from $server via <$server>)
... (information is sent to $server via 'print $server ...')

... (server's response is read via <$server> and printed to browser via 
'print')

close ($server);

That's it - a very simple Perl script that basically takes information 
from the GET or POST strings, sends it to a server process and reads its 
response, printing it out to the browser.

I've now moved the script to Apache 1.3.20 w/ mod_perl 1.25 (I think its 
1.25, but it may be 1.26 - the server's not running at the moment, else 
I'd find out for sure).  It *seems* that the script can run once, but 
that the next time it is accessed, it cannot connect to the $server 
anylonger, it dies with a 'connection timed out' message ... What 
'gotcha' is causing this?

Any help on this would be greatly appreciated!!

Sincerely,
Brice D Ruth

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/



Re: cgi to mod_perl question

Posted by ___cliff rayman___ <cl...@genwax.com>.
Brice D Ruth wrote:

> Brice D Ruth wrote:
>
>> Perrin Harkins wrote:
>>
>> >>  It *seems* that the script can run once, but
>> >>  that the next time it is accessed, it cannot connect to the $server
>> >>  anylonger, it dies with a 'connection timed out' message ... What
>> >>  'gotcha' is causing this?
>> >>
>> > It sounds like this problem:
>> > http://mathforum.org/epigone/modperl/joidwendsmeld/3B30E553.AD3A7DB8@chamas.
>> > com
>> >
>> > In the message, Joshua suggests a workaround of running mod_perl
>> > single-threaded (which shouldn't make any difference, since mod_perl on
>> > Win32 is already single-threaded).
>> >
>> > - Perrin
>> >
>> >
>> It certainly seems that this is part of the problem.  Making mod_perl single-threaded fixed my problem *partially* - now at least I can renew the socket connection on subsequent requests.  But, the connection still isn't being taken down properly ... when the page finishes being served, and after 'close( $server );' has been called, the socket on the server side (what the mod_perl script is connecting to) show 'TIME_WAIT' - the server runs five threads to accept connections, once all of them have been connected to once, I can no longer connect to them - what's going on?  Why is the connection not being dismantled properly??
>
have you tried  to do shutdown($server) in order to dismantle the connection??


--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Re: cgi to mod_perl question

Posted by Brice D Ruth <br...@webprojkt.com>.
  Perrin Harkins wrote:

>>By making 'ThreadsPerChild 1' - the entire server runs as a single
>>thread, mod_perl and any other requests (e.g. images) that come in -
>>this is why the server slows to a snails pace.  I've set up two
>>instances now, one to handle all incoming requests, the other to serve
>>as a backend proxy pass-thru for mod_perl requests.  It seems to be
>>working out fairly well.
>>
>
>Ah, that makes sense.  Good idea.  People have reported that even with its
>limitations on NT, mod_perl is still a lot faster than CGI or ASP with
>PerlScript.
>
>- Perrin
>
I won't take credit for the idea ... it was passed along from some other 
posts I read.  I'm glad that the 'workaround' is actually working 
acceptably well.  I'd like to actually figure out how to load-balance 
the proxy pass-thru to five instances of Apache running in 
single-threaded mode w/ mod_perl ... since the server that the Perl 
scripts are connecting to can handle five simultaneous connections and 
I'd like to take advantage of that ... that's my next project :)

-Brice

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/



Re: cgi to mod_perl question

Posted by Perrin Harkins <pe...@elem.com>.
> By making 'ThreadsPerChild 1' - the entire server runs as a single
> thread, mod_perl and any other requests (e.g. images) that come in -
> this is why the server slows to a snails pace.  I've set up two
> instances now, one to handle all incoming requests, the other to serve
> as a backend proxy pass-thru for mod_perl requests.  It seems to be
> working out fairly well.

Ah, that makes sense.  Good idea.  People have reported that even with its
limitations on NT, mod_perl is still a lot faster than CGI or ASP with
PerlScript.

- Perrin


Re: cgi to mod_perl question

Posted by Brice D Ruth <br...@webprojkt.com>.
  Perrin Harkins wrote:

>>Unfortunately, I've now noticed that my server is unbearably slow -
>>setting 'ThreadsPerChild 1' in my httpd.conf made my server slow to a
>>snails pace (and it really is a pretty quick server on a T1 line
>>dedicated to it, pretty much).
>>
>
>That's odd.  On Win32, mod_perl runs as a single blocking thread.  I
>wouldn't expect changing that setting to affect anything.  Are you sure
>you were running your script under Apache::Registry?  (Maybe someone who
>actually uses Win32 could supply some help here?)
>
By making 'ThreadsPerChild 1' - the entire server runs as a single 
thread, mod_perl and any other requests (e.g. images) that come in - 
this is why the server slows to a snails pace.  I've set up two 
instances now, one to handle all incoming requests, the other to serve 
as a backend proxy pass-thru for mod_perl requests.  It seems to be 
working out fairly well.

>>Have I missed something here?  Certainly
>>this isn't the only way mod_perl can run if it needs to make
>>IO::Socket::INET connections???
>>
>
>I do my mod_perl development on Linux, so I'm just repeating what others
>have posted before.  I've never heard of an actual solution for this
>problem, just the workaround.
>
I wonder if this is something that has been addressed in Apache 
2.x/mod_perl 2.x ... it'd be nice if it were.

>>Please help me out here - I'm truly just a Linux/*BSD guy trying to
>>
>get
>
>>a poor Win2K box w/ Apache to run the Perl scripts right ...
>>
>
>You would certainly get better performance on Linux or BSD.  If you have
>to use Win32 and need better performance, you may have to look at other
>options like ActiveState's PerlEx.
>
Yes, I wish it were a Linux/BSD box ... but it isn't and at the moment 
its not my place to say anything about it.  As for ActiveState's PerlEx 
- I dunno, doesn't seem like a good solution to me :)

Thanks for the info, guys.

-Brice

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/



Re: cgi to mod_perl question

Posted by Perrin Harkins <pe...@elem.com>.
> Unfortunately, I've now noticed that my server is unbearably slow -
> setting 'ThreadsPerChild 1' in my httpd.conf made my server slow to a
> snails pace (and it really is a pretty quick server on a T1 line
> dedicated to it, pretty much).

That's odd.  On Win32, mod_perl runs as a single blocking thread.  I
wouldn't expect changing that setting to affect anything.  Are you sure
you were running your script under Apache::Registry?  (Maybe someone who
actually uses Win32 could supply some help here?)

> Have I missed something here?  Certainly
> this isn't the only way mod_perl can run if it needs to make
> IO::Socket::INET connections???

I do my mod_perl development on Linux, so I'm just repeating what others
have posted before.  I've never heard of an actual solution for this
problem, just the workaround.

> Please help me out here - I'm truly just a Linux/*BSD guy trying to
get
> a poor Win2K box w/ Apache to run the Perl scripts right ...

You would certainly get better performance on Linux or BSD.  If you have
to use Win32 and need better performance, you may have to look at other
options like ActiveState's PerlEx.

- Perrin


Re: cgi to mod_perl question

Posted by clayton <dr...@smartt.com>.
Brice D Ruth wrote:

> Brice D Ruth wrote:
>
>> Perrin Harkins wrote:
>>
>>>>It *seems* that the script can run once, but
>>>>that the next time it is accessed, it cannot connect to the $server
>>>>anylonger, it dies with a 'connection timed out' message ... What
>>>>'gotcha' is causing this?
>>>>
>>>
>>>It sounds like this problem:
>>>http://mathforum.org/epigone/modperl/joidwendsmeld/3B30E553.AD3A7DB8@chamas.
>>>com
>>>
>>>In the message, Joshua suggests a workaround of running mod_perl
>>>single-threaded (which shouldn't make any difference, since mod_perl on
>>>Win32 is already single-threaded).
>>>
>>>- Perrin
>>>
>> It certainly seems that this is part of the problem.  Making mod_perl 
>> single-threaded fixed my problem *partially* - now at least I can 
>> renew the socket connection on subsequent requests.  But, the 
>> connection still isn't being taken down properly ... when the page 
>> finishes being served, and after 'close( $server );' has been called, 
>> the socket on the server side (what the mod_perl script is connecting 
>> to) show 'TIME_WAIT' - the server runs five threads to accept 
>> connections, once all of them have been connected to once, I can no 
>> longer connect to them - what's going on?  Why is the connection not 
>> being dismantled properly??
>>
>> Sincerely (and frustrated),
>> Brice Ruth
>>
> Unfortunately, I've now noticed that my server is unbearably slow - 
> setting 'ThreadsPerChild 1' in my httpd.conf <http://httpd.conf> made 
> my server slow to a snails pace (and it really is a pretty quick 
> server on a T1 line dedicated to it, pretty much).  Have I missed 
> something here?  Certainly this isn't the only way mod_perl can run if 
> it needs to make IO::Socket::INET connections???
>
> Please help me out here - I'm truly just a Linux/*BSD guy trying to 
> get a poor Win2K box w/ Apache to run the Perl scripts right ...



hey,

have you tried just installing
Randy Kobes's allinwonder for win32?

always works for me under windows

ftp://theoryx5.uwinnipeg.ca/pub/other/

from the readme of 0.7:

This is a self-extracting archive of binary versions of
Perl-5.6.1, mod_perl-1.25, and Apache_1.3.20, built
for Windows under VC++ 6 (SP3). 

....



>
> -Brice
>
>-- 
>WebProjkt, Inc.
>VP, Director of Internet Technology
>http://www.webprojkt.com/
>
>




Re: cgi to mod_perl question

Posted by Brice D Ruth <br...@webprojkt.com>.
  Brice D Ruth wrote:

> Perrin Harkins wrote:
>
>>>It *seems* that the script can run once, but
>>>that the next time it is accessed, it cannot connect to the $server
>>>anylonger, it dies with a 'connection timed out' message ... What
>>>'gotcha' is causing this?
>>>
>>
>>It sounds like this problem:
>>http://mathforum.org/epigone/modperl/joidwendsmeld/3B30E553.AD3A7DB8@chamas.
>>com
>>
>>In the message, Joshua suggests a workaround of running mod_perl
>>single-threaded (which shouldn't make any difference, since mod_perl on
>>Win32 is already single-threaded).
>>
>>- Perrin
>>
> It certainly seems that this is part of the problem.  Making mod_perl 
> single-threaded fixed my problem *partially* - now at least I can 
> renew the socket connection on subsequent requests.  But, the 
> connection still isn't being taken down properly ... when the page 
> finishes being served, and after 'close( $server );' has been called, 
> the socket on the server side (what the mod_perl script is connecting 
> to) show 'TIME_WAIT' - the server runs five threads to accept 
> connections, once all of them have been connected to once, I can no 
> longer connect to them - what's going on?  Why is the connection not 
> being dismantled properly??
>
> Sincerely (and frustrated),
> Brice Ruth
>
Unfortunately, I've now noticed that my server is unbearably slow - 
setting 'ThreadsPerChild 1' in my httpd.conf made my server slow to a 
snails pace (and it really is a pretty quick server on a T1 line 
dedicated to it, pretty much).  Have I missed something here?  Certainly 
this isn't the only way mod_perl can run if it needs to make 
IO::Socket::INET connections???

Please help me out here - I'm truly just a Linux/*BSD guy trying to get 
a poor Win2K box w/ Apache to run the Perl scripts right ...

-Brice

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/



Re: cgi to mod_perl question

Posted by Brice D Ruth <br...@webprojkt.com>.
  Perrin Harkins wrote:

>>It *seems* that the script can run once, but
>>that the next time it is accessed, it cannot connect to the $server
>>anylonger, it dies with a 'connection timed out' message ... What
>>'gotcha' is causing this?
>>
>
>It sounds like this problem:
>http://mathforum.org/epigone/modperl/joidwendsmeld/3B30E553.AD3A7DB8@chamas.
>com
>
>In the message, Joshua suggests a workaround of running mod_perl
>single-threaded (which shouldn't make any difference, since mod_perl on
>Win32 is already single-threaded).
>
>- Perrin
>
It certainly seems that this is part of the problem.  Making mod_perl 
single-threaded fixed my problem *partially* - now at least I can renew 
the socket connection on subsequent requests.  But, the connection still 
isn't being taken down properly ... when the page finishes being served, 
and after 'close( $server );' has been called, the socket on the server 
side (what the mod_perl script is connecting to) show 'TIME_WAIT' - the 
server runs five threads to accept connections, once all of them have 
been connected to once, I can no longer connect to them - what's going 
on?  Why is the connection not being dismantled properly??

Sincerely (and frustrated),
Brice Ruth

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/



Re: cgi to mod_perl question

Posted by Perrin Harkins <pe...@elem.com>.
> It *seems* that the script can run once, but
> that the next time it is accessed, it cannot connect to the $server
> anylonger, it dies with a 'connection timed out' message ... What
> 'gotcha' is causing this?

It sounds like this problem:
http://mathforum.org/epigone/modperl/joidwendsmeld/3B30E553.AD3A7DB8@chamas.
com

In the message, Joshua suggests a workaround of running mod_perl
single-threaded (which shouldn't make any difference, since mod_perl on
Win32 is already single-threaded).

- Perrin


OT: Re: cgi to mod_perl question

Posted by ___cliff rayman___ <cl...@genwax.com>.
hi brice,
because this particular question is one of basic perl,
and not mod_perl.  this just alerts all mod_perl readers
that they can safely skip this particular question/answer
and not miss any relevant mod_perl content.

u sound upset - no reason to be - u got the answer u were
looking for.
cliff

Brice D Ruth wrote:

> Why OT?  I have a script that works under IIS/5 using CGI Perl that doesn't work under Apache with mod_perl - I'd say that's on-topic for this list!
>
> -Brice
>
> ___cliff rayman___ wrote:
>
>> Brice D Ruth wrote:
>>
>>
>> >   What is the difference between doing the following:
>> >
>> > close( $server );
>> >
>> functional interface.  flush and close the file handle for this instance
>> of the program.
>>
>>
>> > #
>> > $server->close();
>> >
>> object interface - same as above.
>>
>>
>> > #
>> > $server->shutdown();
>> >
>> object interface.  cause the connection to close at the tcp/ip level.
>> any other application instance also using this socket will no longer
>> be able to read/write from it.
>>
>>
>> --
>> ___cliff rayman___cliff@genwax.com___http://www.genwax.com/
>>
>>
>>
> --
> WebProjkt, Inc.
> VP, Director of Internet Technology
> http://www.webprojkt.com/
>
>

--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Re: cgi to mod_perl question

Posted by Brice D Ruth <br...@webprojkt.com>.
  Why OT?  I have a script that works under IIS/5 using CGI Perl that 
doesn't work under Apache with mod_perl - I'd say that's on-topic for 
this list!

-Brice

___cliff rayman___ wrote:

>Brice D Ruth wrote:
>
>>  What is the difference between doing the following:
>>
>>close( $server );
>>
>
>functional interface.  flush and close the file handle for this instance
>of the program.
>
>>#
>>$server->close();
>>
>
>object interface - same as above.
>
>>#
>>$server->shutdown();
>>
>
>object interface.  cause the connection to close at the tcp/ip level.
>any other application instance also using this socket will no longer
>be able to read/write from it.
>
>
>--
>___cliff rayman___cliff@genwax.com___http://www.genwax.com/
>
>

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/



OT: Re: cgi to mod_perl question

Posted by ___cliff rayman___ <cl...@genwax.com>.
Brice D Ruth wrote:

>   What is the difference between doing the following:
>
> close( $server );

functional interface.  flush and close the file handle for this instance
of the program.

>
> #
> $server->close();

object interface - same as above.

>
> #
> $server->shutdown();

object interface.  cause the connection to close at the tcp/ip level.
any other application instance also using this socket will no longer
be able to read/write from it.


--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Re: cgi to mod_perl question

Posted by Brice D Ruth <br...@webprojkt.com>.
  What is the difference between doing the following:

close( $server );
#
$server->close();
#
$server->shutdown();

??

Sincerely,
Brice Ruth

Brice D Ruth wrote:

>  I have a perl script that was running fine under IIS/5.0 with 
> ActivePerl 6xx - I'll put the salient parts here:
>
> use IO::Socket;
> use CGI;
>
> $in = new CGI;
>
> $server = IO::Socket::INET->new( PeerAddr=> "...",PeerPort=> 
> ...,Proto=>"tcp",Type=> SOCK_STREAM) or die "Error message ... $@";
>
> $server->autoflush(1);
>
> ... (information is gotten from $server via <$server>)
> ... (information is sent to $server via 'print $server ...')
>
> ... (server's response is read via <$server> and printed to browser 
> via 'print')
>
> close ($server);
>
> That's it - a very simple Perl script that basically takes information 
> from the GET or POST strings, sends it to a server process and reads 
> its response, printing it out to the browser.
>
> I've now moved the script to Apache 1.3.20 w/ mod_perl 1.25 (I think 
> its 1.25, but it may be 1.26 - the server's not running at the moment, 
> else I'd find out for sure).  It *seems* that the script can run once, 
> but that the next time it is accessed, it cannot connect to the 
> $server anylonger, it dies with a 'connection timed out' message ... 
> What 'gotcha' is causing this?
>
> Any help on this would be greatly appreciated!!
>
> Sincerely,
> Brice D Ruth
>

-- 
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/