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

Posted on 2007-10-10
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

    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

    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

    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

    In that case, you should definitely look into using mod_perl or a Perl templating system like Mason (which drives if you are concerned about speed and/or efficiency.
    LVL 17

    Accepted Solution

    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

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now