PDA

View Full Version : Disabling search during heavy loads


MPDev
05-09-2005, 10:00 PM
From 3pm-6pm every day I get a very high level of traffic that sends my server load into the 40s (unless I use the server load limit, which then gives alot of people th busy message). With about 750 or so people online, one of the issues appears to be use of the SEARCH feature which locks a table and starts a backup of requests. So, I added some additional code to search.php:

// server too busy?
$toobusy = false;
if (@file_exists('/proc/loadavg') AND $filestuff = @file_get_contents('/proc/loadavg'))
{
$loadavg = explode(' ', $filestuff);
if (trim($loadavg[0]) > 20)
{
$toobusy = true;
}
}

if ( !$vboptions['enablesearches'] || $toobusy )
{
eval(print_standard_error('error_searchdisabled')) ;
}

which will disable the search feature whenever my server load gets above 20. This is seperate from the load limit in the admin and doesn't stop people from using the site, just search. (I changed the searchdisbaled phrase to include a polite message taht search was unavailable during high levels of activity).

Thought someone else might find this useful (you can change the 20 varibale to suit your needs).

PS: I finally configured my server with both Apache and thttpd running and once DNS is updated, I'm going to offload my images onto the thttpd setup to see how that helps with overall loads.

Polo
05-10-2005, 06:15 PM
Nice, thanks for sharing, I konw I will use it one day when my website becomes big ;)

FightRice.com
05-10-2005, 06:35 PM
Hopefully my site becomes big enough i can use this

Nordinho
05-10-2005, 11:03 PM
thanks, very usefull for peaktimes!!

Remi
05-10-2005, 11:12 PM
Great, Can you kindly add a field on the setting section to control the load from there, just like the "NIX Server Load Limit" option.

Thanks

MPDev
05-11-2005, 01:40 AM
After running for a few days this appears to be having a positive effect on keeping my load in check - and those pesky "server too busy" messages are a thing of the past.

I also offloaded the images onto another domain which I am running thttpd on (on the same server as apache); this appears to be having a dramatic effect during peak times where 700+ users are online - my server load is half what it was before offloading and using this mod and my page generation times have been cut in half.

greenhybrid
05-11-2005, 02:24 AM
Where in search.php does this go?

MPDev
05-11-2005, 12:34 PM
Look for the code that is not in bold and add it to that part.

David Bott
05-25-2005, 01:59 PM
Thank you kindly. I had this for ver 2 and it worked great! This should be part of VB all together. ;)