PDA

View Full Version : mod_loadavg



krakjoe
November 30th, 2008, 14:02
Hi fellas, a hosting service I have a hand in has been having real problems with server load lately, not always because of php but a mixture of rails, php and mono is using up far too much resources and it was causing things like mail, ssh and ftp to quit or behave strangely not to mention the trouble it caused apache.

So the other night I spent all of about 5 minutes writing mod_loadavg, which as you might expect is an apache module to detect load average and act on what it finds. The module will return a pre-defined ( by you if you want ) HTTP response code when the server is too busy ( Service Unavailable makes sense and is default ).

It's configurable, but only to a degree, you can setup how load is detected ( to a degree, has to use /proc/loadavg ) and what the limits of your machine are and what HTTP response to send back, however, these variables aren't set in httpd.conf, the reason is that you'll probably never need to change the values once you have them right, to save on disk i/o and to reduce the margin for errors ( for me ) you set them when you build the module.

This module was written for apache 2, as far as I'm aware it will not work with apache 1.3 ( if you try you're on your own ).

I know it's going to be most useful to the guys here, I wrote something similar before as a php extension, but mono, rails etc are used more and more heavily, so going to the source ( apache ) makes much more sense now ...

Consult README before you do anything ...

http://spacesocket.com/loadavg-0.1.tar.gz

Zombie
November 30th, 2008, 14:41
Wow Joe you really do help the people here at FWS ;)

Im gonna try it later ;)

hamster
November 30th, 2008, 21:41
This is freakin awesome! Thanks Joe! :)

krakjoe
December 2nd, 2008, 07:08
Build errors might have occured for ya, download same link again if they did ...

@mods, can we please raise the limit on archives and add .tar.gz/.tar.bz2/.tar to allowed extensions ??

Dan
December 4th, 2008, 00:49
Joe, this is an excellent release mate. This will really help host providers particularly a lot. Well done mate.

Regarding the allowed extensions, if you PM Peo or Jan, I am sure they will oblige. Us Mods don't have access to do that.

katiekitty
December 4th, 2008, 07:51
thx for the script
:)

krakjoe
December 5th, 2008, 05:33
Thanks fellas, I thought people here would find it useful.

It's really doing well on the server it was written for, the server has more than 400 accounts on it. It's stopping people from serving resource hungry scripts, it's killing people using or trying to use file upload services, chat scripts and all the other things that ( free ) hosting providers hate. It takes a bit of playing with, but once your set it does make all the difference.

I'm pretty pleased with it myself. It's amazing what 5 minutes of thought can do for a hosting service.

hamster
December 5th, 2008, 10:50
This will totally revolutionize lots of free hosting providers :P Gives us a chance to sit back and relax for a bit :)

krakjoe
December 6th, 2008, 04:50
It doesn't solve all problems, but it does solve a major one ...

Is anyone still using apache 1.3 ?? If so does that someone want to give me root access so I can make mod_loadavg work for them ??

I don't see any reason to use apache 1.3 anymore, doesn't WHM build 2/2.2 by default ??

krakjoe
December 7th, 2008, 06:15
So a minute ago while I was looking for scoundrals on the server. One of the sites was running "that bit torrent client", the load averages were over 30 and guess what, the server didn't crash, I didn't interfere I just watched ... apache stopped serving requests and the one minute load average immediately went to under 1, I had to wait for about 5 minutes and the server just started behaving as it should again ... I deleted the account using "that bit torrent client", but even if I hadnt, service would have been interrupted for no time at all ...