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

I am having a difficult problem with a server which is running a largish Perl script. What is happening is that most of the time everything works fine. However, sometimes (10%) when going to a new page you get half a page and then the browser sits there hanging. If you wait long enough you may or may not get the page. At first I thought it related to the script but this is not the case. The behaviour occurs even with a very simple script. Here is my test script - as you can see it is about as simple as you can get. The file it is printing is about 160kB

#!/usr/bin/perl open FILE, '/home/somedir/somefile' or die $!; $/ = ''; $file = <FILE>; print "Content-Type: text/plain\n\n"; print "Read file OK\n\n"; print $file;

Next I thought it must relate to my ADSL connection but I get vanilla HTML from this site served up lightning fast.

I have watched things with top and note the generation of the occasional zombie process when this behaviour occurs although this is not 100% consistent.

CPU load is <10%, 1.5MB of memory, low load, 1.5Mbps pipe.

I am at something of a loss as to how to proceed short of reinstalling Apache and Perl. Does anyone have suggestions? OS Red Hat 7.3, Apache 1.3.23, Perl 5.6.1. Details below.

[root@www cgi-bin]# httpd -v Server version: Apache/1.3.23 (Unix) (Red-Hat/Linux) Server built: Jun 19 2002 11:55:23 [root@www cgi-bin]#perl -V Summary of my perl5 (revision 5.0 version 6 subversion 1) configuratio +n: Platform: osname=linux, osvers=2.4.17-0.13smp, archname=i386-linux uname='linux daffy.perf.redhat.com 2.4.17-0.13smp #1 smp fri feb 1 + 10:30:48 est 2002 i686 unknown ' config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dcc=gcc - +Dcf_by=Red Hat, Inc. -Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dprefix +=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Uu +sethreads -Uuseithreads -Uuselargefiles -Dd_dosuid -Dd_semctl_semun - +Di_db -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultipl +icity=undef useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include', optimize='-O2 -march=i386 -mcpu=i686', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.2 2.96-10 +9)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=4 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl. +a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami +c' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: Built under linux Compiled at Apr 1 2002 12:23:22 @INC: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /usr/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl .

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: CGI script random hangs - seemingly Perl or Apache related
by traveler (Parson) on Dec 05, 2002 at 15:14 UTC
    YMMV, but I seem to recall fixing this once with $|=1; to shut off the buffering.

    HTH, --traveler

Re: CGI script random hangs - seemingly Perl or Apache related
by adrianh (Chancellor) on Dec 05, 2002 at 12:28 UTC

    <stab-in-the-dark>

    Is the CGI script hanging around? It sounds like the client's losing the connection. Anything in the error log? Especially things like:

    [Thu Dec 5 12:19:23 2002] [info] [client 217.33.8.36] (32)Broken pipe +: client stopped connection before send mmap completed

    Try logging successful completion of the script somewhere just to double check that it's completing okay. Also, have you tried serving what the script outputs as a plain document to see if that can reproduce the problem?

    </stab-in-the-dark>


    Update:

    Probably worth updating to Apache 1.3.27 anyway. Whole bunch of updates, some of them nasty security holes.

Re: CGI script random hangs - seemingly Perl or Apache related
by dingus (Friar) on Dec 05, 2002 at 13:18 UTC
    A couple of "identify the problem component" ideas

    One obvious test would be to install a different webserver on another port (e.g. thttpd running on port 81) and see if that also has the same problem. If it does then it looks like the issue is not with the webserver part.

    It seems unlikely to be caused by perl - but you could write a very simple shell script to do the same thing as your trivial perl script and see if it also fails.

    Another alternative would be to run one of the POE Cookbook web servers with the trivial modification so that they always deiver the page you are asking for.

    If you think this could be caused by being under load then "wget" is a very simple but effective way to hammer a server.

    Dingus


    Enter any 47-digit prime number to continue.