Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Improving PERL Performance

by Anonymous Monk
on Jun 26, 2005 at 14:10 UTC ( [id://470027]=perlquestion: print w/replies, xml ) Need Help??

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

When running mod-perl on Apache, does it improve performance if a perl script is divided into several parts?

For example, which scenario will have better performance?

In both scenarios, users executing the scripts need to perform either function A or B but not both simultaneously. Yet, both functions share much common perl code.

Scenario 1: scriptAB.pl completes function A and function B. scriptAB.pl gets 100 hits per minute.

Scenario 2: scriptA.pl does function A, and gets 50 hits per minute. scriptB.pl does function B, and gets 50 hits per minute.

Does it improve performance if scriptAB.pl is broken into scriptA.pl and scriptB.pl and a third file is used for common subroutines? Or, is that a waste of time since the server gets 100 hits per minute anyways?

THANKS FOR ANY HELP!

Replies are listed 'Best First'.
Re: Improving PERL Performance
by jhourcle (Prior) on Jun 26, 2005 at 14:33 UTC

    Under normal CGI situations or FastCGI, what you suggest could be a real benefit.

    Under mod_perl, however, because everything is kept in memory, it won't be as significant, as everything is loaded into memory and shared across scripts.

    Will there be any difference? I don't know. Your best bet, in times like this, is to do a realistic benchmark of your exact system, and see if there's a difference, if it's that important to you.

Re: Improving PERL Performance
by dws (Chancellor) on Jun 26, 2005 at 15:46 UTC

    Under mod_perl, the perl code gets loaded once, and lives for the lifetime of the Apache handler process. (Apache forks off several children for handling requests). That is, the time it takes to load modules is a one-time hit.

    I seriously doubt that you're going to find a measurable difference by splitting common code into a .pl (or .pm) that both scripts load, unless you're doing something that kills the handler process. When the handler dies, Apache/mod_perl has to set up a new one from scratch.

    Still, benchmarking is the way to prove this. Even if there's not any difference, it's a good skill to have within reach.

Re: Improving PERL Performance
by cbrandtbuffalo (Deacon) on Jun 26, 2005 at 14:37 UTC
    The best advice has already been given: test the scenarios rather than guess. Even the most experienced coder can fall victim to bad guesses when it comes to optimization.

    However, since you asked, I'll offer a bit of a guess anyway. First establish that you have a performance problem. If you don't yet know if you even have a problem, you are prematurely optimizing; and premature optimization is the root of all evil. If you don't truly have a problem, let your design decisions be guided by some other important factors like maintenance of the code, future growth, re-use, etc.

    My guess is that under mod_perl, the performance difference under all of your scenarios is likely to be statistically insignificant. Other issues like network activity, SSL, possible database access, etc. will have a much bigger performance impact than similar code divided up different ways.

Re: Improving PERL Performance
by tcf03 (Deacon) on Jun 26, 2005 at 14:32 UTC
    benchmark would help you out here.

    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson
Re: Improving PERL Performance
by Anonymous Monk on Jun 26, 2005 at 14:57 UTC
    Thanks so much! Great Forum - time for me to join up!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found