LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 05-16-2007, 09:46 AM   #1
bpmee
LQ Newbie
 
Registered: Oct 2006
Posts: 8

Rep: Reputation: 0
Server aburptly stops running High CPU usage PERL script after about 5 hours


Hi All,

I am using Fedora Core 5, Apache webserver, and ISPconfig with Multi-threaded PERL.

I have a script that uses a low (10) number of PERL threads to go through each of my websites and edit various .php pages that are designated by using grep and "foreaching" them into an array for processing.

When I run the script from shell, I see that it takes up about 105% CPU power, but the server generally continues to function and the script continues to run.

Until... about 5 hours later it abruptly stops and disappears from my "top" processes.

I don't see any PERL error displayed on my shell screen...

Also, I know that it hasn't finished going through each website since I built in a log function that outputs progress to a .txt. file. Further, I told PERL to output "SCRIPT COMPLETE" to my text file when finished, but this doesn't happen!

Is it because my server's CPU is under 105% + load (in addition to serving web requests) for 5 hours that causes the script to stop?

How can I make this "unlimited" temporarily so that the script can run and finish the tasks I need?

Here is my ulimit -a output - everything appears to be max:

Code:
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
max nice                        (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 100000
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 2000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
max rt priority                 (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 100000
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
file locks                      (-x) unlimited
Thanks for any help!
 
Old 05-17-2007, 07:01 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,007
Blog Entries: 5

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
You might insert sleep statements in between each loop. Since you didn't post the script its not clear but I've seen many a script eat processors because they don't have breathing room built into them. What happens is essentially the same resources are getting used by each run of a loop and often the prior loop hasn't completed use of the resources before the next one starts (and the next one, and the next one etc...).

So say if you had a simple shell script that did something like:

while true
do find /home/myname -print
done

Just doing the find of /home/myname might not hurt much once but you'd see the above loop would quickly spawn many find statements and over time would eat your CPU up.

If however you had something like:

while true
do find /home/myname -print
sleep 30
done

It is very unlikely you'd see much impact on your CPU at all (assuming your home directory didn't have 10,000,000 files in it).

Doing the same loop with find of / instead of /home/myname would require you to put in a longer sleep because each find run would take much longer to run.

Similarly if you're processing many files as you say you are likely doing it via a loop and probably need to put in some sleep statements to allow each run of the loop to complete before the next one kicks off.
 
Old 05-18-2007, 12:24 AM   #3
bpmee
LQ Newbie
 
Registered: Oct 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Thumbs up Thanks, and excellent reply!

Hi,

Thanks for your reply! That is very helpful.

Actually, I don't have a system that uses "sleep" or other programming to allow the processor time to breath.

I'm going to look at the script again and make sure there is time for all the PERL threads to complete before running over each other and/or other things in the script.

Great advice...!
 
Old 05-18-2007, 11:24 AM   #4
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,007
Blog Entries: 5

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
It's not so much that the "system requires sleeps" but rather that infinite (or least very long) loops essentially use pretty much the same resources for each run. Without putting in a governor like sleep you end up with multiple runs trying to process concurrently. While the system will allow for a certain amount of this there is a point of diminishing returns. The sleep statement just tells it to not do that so it frees the resources before using them in the next run from the loop.

Restated: The system is designed for multi-users and multi-processes but it works well for this because typically the users and/or processes aren't all using exactly the same resources at the same moment. In a loop however the processes typically are trying to use the same resources at nearly the same moment.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
High CPU usage ?! Why? skate Linux - Software 1 04-11-2007 05:55 AM
High Cpu usage untak Debian 21 01-23-2007 06:21 AM
cpu usage high corbintechboy VectorLinux 2 07-27-2005 08:11 AM
High CPU usage on FreeBSD 5.4 with nothing special running adz *BSD 24 06-24-2005 08:51 PM
xine high CPU usage Phathead Slackware 1 07-14-2004 01:16 AM


All times are GMT -5. The time now is 11:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration