You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Philip Mak <pm...@aaanime.net> on 2001/09/09 00:59:03 UTC

Why is my script slow?

I have a script that takes 3 seconds to execute; I'm trying to figure out
how to make it faster. Here are some facts:

1. I put $s::starttime = [gettimeofday] (that's a function from
Time::HiRes) at the beginning of Script_OnStart. Then I put statements at
various places in my script to print how much time has elapsed. It claims
that 0.02 seconds have elapsed at the end of the script, but it took me 3
seconds to load the script.

2. If I reload the script a few times, then it starts responding
instantaneously, so I'm guessing that something needs to be pre-compiled.

3. I have "use"d all the modules in startup.pl, and I also call
Apache::ASP->Loader there:

Apache::ASP->Loader($WEB, '\.(asp|inc|asa)$', Global => $GLOBAL);

Did I miss some pre-compilation step somewhere?


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Why is my script slow?

Posted by Joshua Chamas <jo...@chamas.com>.
Philip Mak wrote:
> 
> On Sat, 8 Sep 2001, Joshua Chamas wrote:
> 
> > Can you show a trace in the error_log with Debug set to -3 ?
> > Make sure Time::HiRes is installed first.  The first request
> > error_log set from an apache restart would be helpful to see.
> 
> I have attached the error log.
> 
> > It may be that upon global.asa compilation, other modules
> > get also loaded that were not use'd in startup.pl?  We'll
> > see more with your trace.
> 
> I just did a "egrep ^use *" on my Global directory; everything that my
> modules "use" is included in startup.pl.
> 

The Apache::ASP StatINC functionality is taking some time on the 
first request to register code ref, but less than a second.
This can be alleviated some by getting my latest dev copy,
which I will send you shortly, and setting StatINC while using
Apache::ASP->Loader(), so that the code registration is cached
for all processes in the parent.  This had been broken in a
few ASP releases, but fixed my my dev 2.23.

The real weight seems to be in parsing the file & includes, 
in particular I'm betting there there are lots of embedded 
XMLSubs that are getting parsed from the look of your 
log file.  There are some things ( you & me ) to do here

  1) I need your scripts, and see if I can't make the parsing faster
  2) use DynamicIncludes, there is not point for all your includes
     to get recompiled on a per script basis
  3) Use Loader() to precompile your scripts & includes, which is 
     a huge win with DynamicIncludes even when you don't precompile
     all your scripts, but make sure to load enough scripts to process
     your core templates.

I could also consider creating a file based parse cache like some
of the other environments have, I have never thought it necessary
before, but if 1-3 don't do it, then this might be necessary.

> 
> P.S. Is it right to put DBI->connect inside Script_OnStart, or should it
> go somewhere else?
> 

Yep, I do this kind of thing all the time.  I usually call it $Db
though to make it more ASPish :)

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Why is my script slow?

Posted by Philip Mak <pm...@aaanime.net>.
On Sat, 8 Sep 2001, Joshua Chamas wrote:

> Can you show a trace in the error_log with Debug set to -3 ?
> Make sure Time::HiRes is installed first.  The first request
> error_log set from an apache restart would be helpful to see.

I have attached the error log.

> It may be that upon global.asa compilation, other modules
> get also loaded that were not use'd in startup.pl?  We'll
> see more with your trace.

I just did a "egrep ^use *" on my Global directory; everything that my
modules "use" is included in startup.pl.

I noticed something: If I "PerlSetVar DynamicIncludes 1" in httpd.conf, it
makes the first invocation of my script take 1-2 seconds instead of 4
seconds.

> I am sure you have, but are you sure startup.pl is running?
> You have to PerlRequire it explicitly.

Yes, I did PerlRequire it explicitly.

PerlRequire /home/shoujoai/dev/global/startup.pl

P.S. Is it right to put DBI->connect inside Script_OnStart, or should it
go somewhere else?

Re: Why is my script slow?

Posted by Joshua Chamas <jo...@chamas.com>.
Philip Mak wrote:
> 
> I have a script that takes 3 seconds to execute; I'm trying to figure out
> how to make it faster. Here are some facts:
> 
> 1. I put $s::starttime = [gettimeofday] (that's a function from
> Time::HiRes) at the beginning of Script_OnStart. Then I put statements at
> various places in my script to print how much time has elapsed. It claims
> that 0.02 seconds have elapsed at the end of the script, but it took me 3
> seconds to load the script.
> 
> 2. If I reload the script a few times, then it starts responding
> instantaneously, so I'm guessing that something needs to be pre-compiled.
> 
> 3. I have "use"d all the modules in startup.pl, and I also call
> Apache::ASP->Loader there:
> 
> Apache::ASP->Loader($WEB, '\.(asp|inc|asa)$', Global => $GLOBAL);
> 
> Did I miss some pre-compilation step somewhere?
> 

Can you show a trace in the error_log with Debug set to -3 ?
Make sure Time::HiRes is installed first.  The first request 
error_log set from an apache restart would be helpful to see.

It may be that upon global.asa compilation, other modules
get also loaded that were not use'd in startup.pl?  We'll
see more with your trace.

I am sure you have, but are you sure startup.pl is running?
You have to PerlRequire it explicitly.

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org