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

I have lots of text and CSV files that I need to make accessible via the web. I'm currently using the perl script below to post these files. However, the performance is terrible. I'm using a SUN v240 with Solaris 8, Apache 1.3.34 configured with SSL and MOD_PERL. However, a 300 to 500 line text file takes anywhere from 8 to 15 seconds to load (full duplex, 100 Mbps connectivity to server).

I tried the system tuning suggestions from http://everythingsolaris.org.

Any help or suggestions are appreciated.

Darrin

Example:

#!/usr/bin/perl -w # rsdnl.pl use strict; use warnings; ######################################### ###### PROGRAM DESCRIPTION ###### # This script pulls information from text # files and posts it on the web. ######################################### ## Declare Variables ## my $Source_File; my $Source_Title; my @Contents; my $content; ## Read Post Input and Set Source ## $Source_File = $ENV { 'QUERY_STRING' }; $Source_File = "Not Defined" unless $Source_File; $Source_Title = $Source_File; $Source_Title =~ s/^.*\///; ## Display Web Page ## print "Content-type: text/html\n\n"; print <<"EOF"; <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SOCOM Networks</title> <link rel="stylesheet" href="./index/Global.css" /> <link rel="stylesheet" href="./index/Socom.css" /> <link rel="stylesheet" href="./index/Pierce.css" /> </head> <body topmargin="0" leftmargin="0" bgcolor="white"> EOF ## Include Banner my $header_file = './index/_header01.txt'; open ( HEADER, $header_file ) || die "Cannot open $header_file: $!\n"; while ( <HEADER> ) { print; } close (HEADER); print <<"EOF"; <div align="center"> <br/><br/> <table border="0" cellspacing="0" cellpadding="0" width="800px"> <tr> <td class="DashPartFrame"> <table width="100%" border="0" cellpadding="0px" cellspacing="0px"> +<tr valign="top"> <!-- BEGIN COLUMN ONE --> <td style="width:100%" class="DashZoneLeft"> <!-- BEGIN TABLE: DISPLAY FILE --> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td class="DashPartFrame"> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tr> <td class="DashPartTitle"> <nobr><span>$Source_Title</span></nobr> </td> <td nowrap="" class="DashPartCommandsArea"> &nbsp; </td> </tr> </table> <div class="DashPartBody" style="width:100%;"> <!-- BEGIN INSERT PAGE --> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td style="padding:5px" class="text3"> EOF if ( -e $Source_File ) { open ( SOURCE, "$Source_File" ) || die "Cannot open $Source_File: $! +\n";; @Contents = <SOURCE>; close ( SOURCE ); print "<pre>\n"; foreach $content ( @Contents ) { print "$content<br/>"; } #foreach $content ( @Contents ) print "</pre>\n"; } else { print "<br/><h2>&nbsp;&nbsp;&nbsp;The file specified does not exist! +</h2><br>\n"; } #if ( -e $Source_File ) print <<"EOF"; </td> </tr> </table> <!-- END INSERT PAGE --> </div> </td> </tr> </table> <!-- END TABLE: DISPLAY FILE --> <table><tr><td style="height:1px"></td></tr></table> </td> <!-- END COLUMN ONE --> </tr> </table> <div> </body> </html> EOF exit 0;

Edited by planetscape - added readmore tags

Replies are listed 'Best First'.
Re: Poor Performance
by reasonablekeith (Deacon) on Mar 22, 2006 at 11:42 UTC
    You need to simplify it to eliminate all the different elements. On the face of it, there's nothing there that should take 10 seconds to return. I'd start by just paring it down to a script which just returned a valid http response. If that's okay, start printing out your css references, then the full formatted page, then load the file. etc...

    Good luck :)

    Update:

    One could argue that you should have done this in the first place. On more than one occasion I've been typing up a question intended for SOPW, trying to create a simple example of what's going wrong. The example ends up being so simple that I solve it myself.

    Perlmonks becomes a surrogate for that colleague who you explain stuff to, just so you can figure it out for yourself.

    ---
    my name's not Keith, and I'm not reasonable.
      I second this approach. Run the script and just output a header and a simple "Hello world" message, then add the bit pulling your header from the file, then add a bit opening and displaying a small, one-line file, then run your current implementation. Those data points will help you zero in on where the performance problem is.

      If you get some information from this approach, you could post back with details.

      Question: Any reason you're not using CGI.pm to print your HTML header?

Re: Poor Performance
by zer (Deacon) on Mar 22, 2006 at 06:34 UTC
    it runs fast for me. How big is the header01 file? That is the only error i come accross. Is this being accessed localy or through the internet? your net connection may have something to do with the lag.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Poor Performance
by xdg (Monsignor) on Mar 22, 2006 at 06:38 UTC

    You're doing a lot of stuff line by line when you read files, but that shouldn't really matter for 300 lines (unless the lines are really long, I suppose.)

    However, you're also pulling in and displaying the header file, plus telling the browser to pull in three separate CSS files. How big are all those files?

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.