Can a perl program that takes a long time to run tie up Apache?

Posted on 2007-10-10
Medium Priority
Last Modified: 2013-12-25
I think this question might be a bit naive, but that's why I come here to learn ...

I'm planning a Web site using Apache and perl on Linux, to run on a server that handles other sites as well.  Most of the pages of all my sites are delivered through html constructed on the fly in perl programs.  The new site will contain a perl cron job that runs with some frequency.  My basic question is whether access to the sites that the server operates will be degraded if the cron job runs a perl program that takes, for example, 10 minutes to run.

I can see that if the perl cron job is computing pi to a bazillion digits, it can cause access to the server's sites to stop, but I don't think the cron job wouldn't be tying up the processor: it might be using LWP to download pages from other Web sites, or accessing a Web service to send text messages.  So most of the time, the perl cron program would be waiting for responses from other servers, and would not by any means completely occupy the processor.

So, even though it might take the program 5 or 10 minutes to run, Apache will keep delivering other pages and generally doing it's job, right?

Then, what if I'm using mod_perl?  Would that be a disadvantage?  Maybe because other instances of perl wouldn't run?

See, there may be a fundamental piece of information I lack here, but I trust someone can set me straight.  Thanks.
Question by:StevenMiles
LVL 39

Assisted Solution

Adam314 earned 160 total points
ID: 20051746
The computer will have to split up it's time amongst all programs that need the time.  If your perl program started from the cron doesn't need much time, it will hardly affect apache.  As you've said, most of what it is doing will be waiting - if this is the case, you should be fine.  To be even more safe, you can lower the priority of your perl cron program.  
See the setpriority function in perl:
Or the man page for renice:

As for mod_perl, this will allow apache to run your perl generated web pages more efficiently.  It will have nothing to do with the perl program started through the cron.  
LVL 48

Expert Comment

ID: 20052153
Agree with Adam.

However, one thing that isn't clear is the nature of your pages.  You say you have a Perl cronjob generating the pages, but you also say "constructed on the fly in perl programs", which seems to imply CGI or SSI.

Could you please expand a little more on this as mod_perl only makes sense to use if you actually use Perl/CGI scripts.

Author Comment

ID: 20052320
Hi, Adam and Tintin,
Very helpful so far.  Tintin, the html pages are indeed constructed on the fly with CGI.  The cron job(s) are not run in response to requests from web browsers.  Rather, they handle various housekeeping tasks on a schedule.  The cron jobs don't send html anywhere.  Did I explain that okay?
LVL 48

Assisted Solution

Tintin earned 160 total points
ID: 20052505
In that case, you should definitely look into using mod_perl or a Perl templating system like Mason (which drives amazon.com) if you are concerned about speed and/or efficiency.
LVL 17

Accepted Solution

mjcoyne earned 180 total points
ID: 20054107
I have a single server (Fedora 7) that acts as a webserver (Apache) for multiple sites.  The server also fields SSH requests, acts as an email server (Postfix), and runs many cron scripts -- one cron job even regenerates an entire website based on updated user stats using Perl scripts and HTML::Template, and outputs graphs of each user's stats (using GD::Graph) for a 30 day history every three hours.  Other cron jobs are for routine system maintainence, tailing logs for security breech attempts, and for a complete system backup (using rsync) every hour.  Several of the sites are database driven (MySQL).

This server's hardware is modest -- ABIT NF7-S (NVIDIA nForce2 SPP + MCP-T chipset) motherboard , AMD Athlon XP 2500+ (Barton core) processor, 1 GB PC-3500 DDR RAM -- yet I never notice a slowdown, and get no complaints from users.  Granted, it's not an extremely high traffic site, but I've had no problems...

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question