Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Jan 17, 2012 6:19 pm 
Offline
Senior Member

Joined: Tue Sep 13, 2011 7:13 am
Posts: 67
I am wondering, If some process is runing on 100% and jamming server for long time, is there a way that i could automaticly shut them down if for example more than 5 minutes they occupy 100% of server.


Top
   
 Post subject:
PostPosted: Tue Jan 17, 2012 8:27 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
100% of what?

ulimit is probably the standard way to impose resource limits (see also limits.conf), although its CPU limits are cumulative: something using 100% CPU for 1 minute and something using 1% CPU for 100 minutes will "look the same" as far as limits are concerned. The memory and process limits are somewhat more useful.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
 Post subject:
PostPosted: Wed Jan 18, 2012 3:18 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
Monit can do this, but it has to be configured to manage the service. It can't just hunt down and kill off random processes.


Top
   
 Post subject:
PostPosted: Wed Jan 18, 2012 12:30 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
A process consuming 100% CPU can't jam your server, because you've got four processors, giving you an aggregate of 400% CPU.

A process that locks up and hangs at 100% is indicative of a more serious issue that you need to look into. The proper thing to do is fix or remove the offending process, rather than trying to kill it when it happens.


Top
   
 Post subject:
PostPosted: Wed Jan 18, 2012 1:23 pm 
Offline
Senior Member

Joined: Tue Sep 13, 2011 7:13 am
Posts: 67
Sorry for not being more clear on this.

I got message form linode

"Your Linode, linode-1, has exceeded the notification threshold (90) for CPU Usage by averaging 104.0% for the last 2 hours. "

then i login and check "top" and find out a process that is taking 100% of CPU and time of it is 250 minutes.

So obviously this process is "jammed" somehow and will not terminate by itself. Ok I killed it there and not it's gone.

My idea would be that after 10 minutes or so this kind of processes is killed, data of it logged to my log file and then i check later what it was. Is this correct idea how to solve it and also can it be done this way or some othe way would be better?


Top
   
 Post subject:
PostPosted: Wed Jan 18, 2012 2:03 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
What was the name of the process? Apache? PHP? MySQL?

It's relatively easy to write a shell script that runs from cron every few minutes, check the CPU usage, and email you a list of currently running processes if the CPU usage is above a certain threshold. Then you can ask around what might be causing Program X to use so much CPU.

It would be more difficult to automatically terminate the offending process without damaging whatever it was originally meant to be working on. You don't want a rogue script going off on a killing rampage and corrupting your database while doing so.


Top
   
 Post subject:
PostPosted: Wed Jan 18, 2012 2:36 pm 
Offline
Senior Member

Joined: Fri Feb 18, 2005 4:09 pm
Posts: 594
marko_roi wrote:
I killed it there and not it's gone.


If you have not done so yet, instead of "kill process" try "kill -9 process".

James


Top
   
 Post subject:
PostPosted: Wed Jan 18, 2012 4:54 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
zunzun wrote:
marko_roi wrote:
I killed it there and not it's gone.

If you have not done so yet, instead of "kill process" try "kill -9 process".

I think he was trying to write "now it's gone", not "it's not gone".


Top
   
 Post subject:
PostPosted: Mon Jan 23, 2012 1:55 pm 
Offline
Senior Member

Joined: Tue Sep 13, 2011 7:13 am
Posts: 67
Yes, I killed it :-) it was "now" What is kill -9 doing instead of plain kill?

To hybinet, Apache was name of process. I think it would be safe to assume if someting is runing more than 10 minutes that it wouldnt work and should be shutdown. I can kill process manually but i am not always by computer and ready to kill it if its making problems, and then server stops working and I have a real problem and i dont even know as i might be on vacation or just off somewhere. Would like to have some trigger for this kind of events, but ok I can take your advice if all of you think its not a way to go.


Top
   
 Post subject:
PostPosted: Tue Jan 24, 2012 3:28 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
It sends a KILL signal instead of the default TERM signal.


Top
   
 Post subject:
PostPosted: Tue Jan 24, 2012 10:51 am 
Offline
Senior Member

Joined: Fri Jan 09, 2009 5:32 pm
Posts: 634
In layman's terms

kill <proc> - sends the message "hey proc, it's time for you to shut down"
kill -9 <proc> - forces proc to stop immediately, removes all resources, etc


Top
   
 Post subject:
PostPosted: Tue Jan 24, 2012 1:01 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
If it was Apache, it was probably a PHP process gone rogue. That happens from time to time with certain combinations of PHP extensions -- the quality of the PHP codebase is very uneven.

What's MaxRequestsPerChild in your Apache configuration? Setting this to a low value (like 500) might help prevent PHP from going belly up, by forcing Apache processes to kill themselves every now and then. Of course this is a stupid band-aid solution, but you sometimes need stupid band-aid solutions if you want to use PHP. Also make sure that max_execution_time in php.ini is set to a reasonable value, like 15 seconds. This is another band-aid solution that might or might not work, but it's better than nothing. Google "<your_distribution> <version> apache cpu 100%" or something like that to see if anyone else has found a better answer.

BTW, kill -9 is merciless. Try regular kill first. Resort to kill -9 only if regular kill doesn't work.


Top
   
PostPosted: Sat Feb 25, 2012 6:16 am 
Offline
Newbie

Joined: Sat Feb 25, 2012 5:43 am
Posts: 4
marko_roi wrote:
I am wondering, If some process is runing on 100% and jamming server for long time, is there a way that i could automaticly shut them down if for example more than 5 minutes they occupy 100% of server.


No way, not unless you had the permissions set that way on purpose. Is that a possibility?


Top
   
 Post subject:
PostPosted: Sat Feb 25, 2012 6:39 am 
Offline
Senior Member
User avatar

Joined: Fri Oct 24, 2003 3:51 pm
Posts: 965
Location: Netherlands
Mmmm… spammy necropost, with the spam in the quote. Are you a bot, or just stupid?

_________________
/ Peter


Top
   
 Post subject: Busted again!
PostPosted: Sat Feb 25, 2012 11:02 am 
Offline
Newbie

Joined: Sat Feb 25, 2012 5:43 am
Posts: 4
Damn, sharp ass fangs! I thought it would be cleaner. I am new at this and I can't stand spam. So, i figured on no one reading the quotes and that being a good place to put it.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group