Simple Machines Community Forum

SMF Support => Server Performance and Configuration => Topic started by: Ben_S on March 14, 2006, 04:33:04 PM

Title: Disabling resource intensive features based on server load
Post by: Ben_S on March 14, 2006, 04:33:04 PM
SMF 1.1 introduces a new feature.

This new feature can be used to disable certain other features that can be hard on the server depending upon the server load.

Note, it is not recommended that you use these options if you are on a shared server as other users load will affect your board and you may find it being disabled when it doesn’t need to be.

There is no admin interface for this feature to prevent people enabling the feature and locking themselves out of their forum.  You will need to enable it with phpMyAdmin (What is phpMyAdmin? (http://www.simplemachines.org/community/index.php?topic=21919.0)).  This way you can just go back to phpMyAdmin and undo the changes.

To enable it, run the following query (you may with to adjust the values before hand)

Code: [Select]
REPLACE INTO smf_settings
   (variable, value)
VALUES ('loadavg_enable', '1'),
   ('loadavg_forum', '40.0'),
   ('loadavg_auto_opt', '1.0'),
   ('loadavg_search', '2.5'),
   ('loadavg_allunread', '2.0'),
   ('loadavg_unreadreplies', '3.5'),
   ('loadavg_show_posts', '2.0');

This will disable the forum completely if the server load is above 40, automatic database table optimization with a load above 1, search with a load above 2.5, users “show all unread posts” at 2, users “show all unread replies” at 3.5 and the profile > show users posts at a load of 2.

If you need to tweak any of the settings, you can just do a REPLACE INTO, e.g. to turn the feature off, you can run

Code: [Select]
REPLACE INTO smf_settings
   (variable, value)
VALUES ('loadavg_enable', '0');
Title: Re: Disabling resource intensive Features based on server load
Post by: vbgamer45 on March 14, 2006, 04:35:16 PM
Sweeet!! Cant' wait till SMF 1.1. This is going to rock!
Title: Re: Disabling resource intensive features based on server load
Post by: ediww on September 09, 2006, 08:14:18 AM
hi there, are the dots in the values required at all?
Title: Re: Disabling resource intensive features based on server load
Post by: vbgamer45 on September 09, 2006, 09:17:08 AM
The dot's aren't required mainly there if you want to get to an exact limit
Title: Re: Disabling resource intensive features based on server load
Post by: qtime on February 25, 2007, 05:50:54 PM
Is it possible to set different values according certain membergroups?
Title: Re: Disabling resource intensive features based on server load
Post by: Ben_S on February 25, 2007, 07:50:59 PM
No
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on October 11, 2007, 06:56:44 AM
Code: [Select]
REPLACE INTO smf_settings
   (variable, value)
VALUES ('loadavg_enable', '1'),
   ('loadavg_forum', '40.0'),
   ('loadavg_auto_opt', '1.0'),
   ('loadavg_search', '2.5'),
   ('loadavg_allunread', '2.0'),
   ('loadavg_unreadreplies', '3.5'),
   ('loadavg_show_posts', '2.0');

This will disable the forum completely if the server load is above 40, automatic database table optimization with a load above 1, search with a load above 2.5, users “show all unread posts” at 2, users “show all unread replies” at 3.5 and the profile > show users posts at a load of 2.

Discussion around this feature (which I was completely unaware of) has come up again in the MODs forum again and I would just like to ask:

1. The feature "Disable Forum" means that forum goes to Maintenance Mode?

2. Does anyone know the "best" tweaking values for each option? I'm not familiar with server load values, so I really don't know if values should be tweaked according to server-type, to forum size, to forum bandwidth, or if any other parameter should be taken into account.
Title: Re: Disabling resource intensive features based on server load
Post by: Ben_S on October 11, 2007, 07:38:02 AM
1. Not Maintenance Mode, it uses a fatal error message (as far as I remember) to show the server load is currently too high, all access will be denied including admins.

2. There are no best values, they are entirely dependent upon the server you are on, if you are not on a dedicated server, I'd suggest you don't even bother with this feature since 90% of the time, the load will not be caused by your forum.
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on October 11, 2007, 09:55:39 AM
Tkx ;).

I just wondered if I should get worried with that.
Our forum, which consumes about 50 Gb bandwidth / month, had 1Gb disk space to use - 250 Mb for MySQL database and 410 Mb free space - and it crashed twice because of not enough disk space to execute those "temporary" MySQL table operations... but now it was upgraded to 5Gb and everything is smooth now.

But it's surely too small yet to cause any server load... ;D
Title: Re: Disabling resource intensive features based on server load
Post by: Col on October 13, 2007, 10:11:38 PM
Hi Ben,

I understand that this should not be used in shared server environment, but what if the server has mod_perl2 installed? This enables resources to be assigned to individual accounts - might it be possible to use the individually assigned resource levels so that peoples' forums aren't being disabled because of a high total server load?
Title: Re: Disabling resource intensive features based on server load
Post by: 青山 素子 on October 14, 2007, 06:00:35 PM
mod_perl doesn't have anything to do with resource assignment, it is merely a way to run perl scripts inside the Apache process instead of as a CGI.
Title: Re: Disabling resource intensive features based on server load
Post by: se7o.com on November 07, 2009, 03:32:22 PM
it show this error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'loadavg_forum', '7.0'' at line 1
Title: Re: Disabling resource intensive features based on server load
Post by: Kill Em All on February 07, 2010, 09:59:32 PM
se7o.com, this post is quite old, MySQL probably had revisions and the code has probably changed, that is why it probably wont work.
Title: Re: Disabling resource intensive features based on server load
Post by: Something like that on February 08, 2010, 10:28:05 AM
se7o.com, this post is quite old, MySQL probably had revisions and the code has probably changed, that is why it probably wont work.

That's standard SQL that's been around for decades. It's possible that he copied and pasted incorrectly.
Title: Re: Disabling resource intensive features based on server load
Post by: Ricky. on December 31, 2010, 02:22:43 AM
I know this post is quite old but its very helpful as it saves your forum if there is sudden spike or something. However, is there way to customize message it shows and also to not to lock down forum for Admin?
Title: Re: Disabling resource intensive features based on server load
Post by: Aleksi "Lex" Kilpinen on December 31, 2010, 02:27:33 AM
You can probably customize the message somehow, can't remember how this worked on 1.1 - but you can not make it so that it would care about your membergroup.
Title: Re: Disabling resource intensive features based on server load
Post by: Ricky. on December 31, 2010, 09:42:47 AM
Ok, which part or what files deal with this settings.. .. that way I can look into myself !
Title: Re: Disabling resource intensive features based on server load
Post by: Dzonny on January 01, 2011, 01:00:44 PM
This is really work?
It would be very helpflu to have somthing like this in admin panel.
Quote
This will disable the forum completely if the server load is above 40, automatic database table optimization with a load above 1, search with a load above 2.5, users “show all unread posts” at 2, users “show all unread replies” at 3.5 and the profile > show users posts at a load of 2.
by "server load above 40", u mean if server ram memmory is above 40% or what? :D
Title: Re: Disabling resource intensive features based on server load
Post by: qtime on January 01, 2011, 01:06:39 PM
This is really work?
It would be very helpflu to have somthing like this in admin panel.
Quote
This will disable the forum completely if the server load is above 40, automatic database table optimization with a load above 1, search with a load above 2.5, users “show all unread posts” at 2, users “show all unread replies” at 3.5 and the profile > show users posts at a load of 2.
by "server load above 40", u mean if server ram memmory is above 40% or what? :D
please check this http://www.lifeaftercoffee.com/2006/03/13/unix-load-averages-explained/ to find out.
Title: Re: Disabling resource intensive features based on server load
Post by: Dzonny on January 01, 2011, 01:12:49 PM
Right, thank you, just read that, and get it :) I didnt know about that, couse i just moved from share to vps server.
So, anyone is using this on public forum? Is it working? Can it work with 1.1.12 version? :)
Title: Re: Disabling resource intensive features based on server load
Post by: qtime on January 01, 2011, 01:16:26 PM
yes it's working at 1.1.2

don't be afraid if your serverload is 10 and your forum is fast.
Title: Re: Disabling resource intensive features based on server load
Post by: Dzonny on January 01, 2011, 01:37:17 PM
yes it's working at 1.1.2
U mean 1.1.12?  :D

don't be afraid if your serverload is 10 and your forum is fast.
Serverload is currently below 1.5 for each 5, 10 and 15min. As i can get, it is fine, right?
Title: Re: Disabling resource intensive features based on server load
Post by: qtime on January 01, 2011, 01:42:58 PM
yes working at 1.1.2 and serverload is very nice.
To protect overloading of the server, you could setup search to 5 for example. If the server is higher loaded, it will avoid searching and serverload could drop.
Title: Re: Disabling resource intensive features based on server load
Post by: 青山 素子 on January 01, 2011, 01:48:17 PM
This is really work?
It would be very helpflu to have somthing like this in admin panel.

Bad idea. Most users would be somewhat clueless on the settings and could easily enter them in low enough that they would effectively shut down their forum. The only way to recover would be to edit the settings directly in the database. Someone who didn't know enough to use the settings correctly would likely not know how to make the necessary database edits to fix the damage.
Title: Re: Disabling resource intensive features based on server load
Post by: Dzonny on January 01, 2011, 01:51:08 PM
Hm right, but i just have my own forum on vps, and dont plan any clients there for now.
Title: Re: Disabling resource intensive features based on server load
Post by: Aleksi "Lex" Kilpinen on January 01, 2011, 02:15:50 PM
Actually, 2.0 has this built into the Admin CP, as part of the server settings... ::)
Title: Re: Disabling resource intensive features based on server load
Post by: 青山 素子 on January 01, 2011, 04:11:52 PM
Actually, 2.0 has this built into the Admin CP, as part of the server settings... ::)

Indeed it does (Configuration -> Server Settings -> Load Balancing), albeit with a red warning. I recall a push to get many of the "hidden" settings added to the UI.
Title: Re: Disabling resource intensive features based on server load
Post by: Dzonny on January 01, 2011, 06:33:57 PM
Hm, ok, is it the same system as posted here in the first post?
Im using 1.1.12, and i will try it to see if its working.
Title: Re: Disabling resource intensive features based on server load
Post by: 青山 素子 on January 01, 2011, 09:57:51 PM
Hm, ok, is it the same system as postet here in forst post?
Im using 1.1.12, and i will try it to see if its working.

Yes. Be careful, you can make your forum unusable.
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on July 18, 2011, 11:42:40 AM
Sorry to push this old thread up, but I want to use this to disable the feature that allows guests to browse the forum abobe a certain load. Would it be possible to do it and if so what is the parameter/function?
Title: Re: Disabling resource intensive features based on server load
Post by: 青山 素子 on July 18, 2011, 11:56:44 AM
As far as I know, that is not currently an option. The load options allow one to disable certain high-load-causing features, but browsing is not one.
Title: Re: Disabling resource intensive features based on server load
Post by: emanuele on July 18, 2011, 05:45:58 PM
In 2.0 the threasholds are:
Threshold to disabling automatic database optimization
Threshold to disabling search
Threshold to disabling all unread topics
Threshold to disabling unread replies
Threshold to disabling showing user posts
Threshold to disabling the forum completely
Details: Load Balancing (http://wiki.simplemachines.org/smf/Server_Settings#Load_Balancing).

The last one seems what Paracelsus is looking for, but it affects all the users, not only guests.
Title: Re: Disabling resource intensive features based on server load
Post by: 青山 素子 on July 18, 2011, 06:10:06 PM
Threshold to disabling the forum completely
Details: Load Balancing (http://wiki.simplemachines.org/smf/Server_Settings#Load_Balancing).

The last one seems what Paracelsus is looking for, but it affects all the users, not only guests.

Exactly. That one shouldn't be used as a default. It effectively does the same thing as setting maintenance mode to 2, which makes the forum inaccessible to everyone, even admins.

Potentially, the system could be extended to allow this, but I'm not sure how big a benefit would be provided since you'd still have to allow logins, which would increase load anyway.
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on July 19, 2011, 01:48:52 AM
Well, since we are dedicated to a sports, mainly football (soccer) club, the loads tend to peak in specific periods, ie, during the club's football matches. In our experience, disabling browsing to guests in these couple of hours allows the forum to become much more responsive and faster than without this option.
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on July 19, 2011, 02:37:25 AM
The only function I can find on smf_settings.php that might do the trick is this one: allow_guestAccess, but Subs-Auth has the KickGuest function also.

Could this actually work?
Code: [Select]
REPLACE INTO smf_settings
   (variable, value)
VALUES ('loadavg_enable', '1'),
   ('loadavg_allow_guestAccess', '40.0');

Subs-Auth.php has this piece of code:
Code: [Select]
// Kick out a guest when guest access is off...
function KickGuest()
{
global $txt, $context;

loadLanguage('Login');
loadTemplate('Login');

$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];

$context['sub_template'] = 'kick_guest';
$context['page_title'] = $txt[34];
}

Would it make sense to be like this:
Code: [Select]
REPLACE INTO smf_settings
   (variable, value)
VALUES ('loadavg_enable', '1'),
   ('loadavg_KickGuest', '40.0');
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on July 19, 2011, 03:12:53 AM
Ok, maybe the above isn't such a good solution after all...

What about this one: install this MOD - High Server Load Warning (http://custom.simplemachines.org/mods/index.php?mod=2699) and then on index.template.php replace this:

Code: [Select]
$load = sys_getloadavg();
if ($load[0] > $modSettings['amount_server_load_check'] && !empty($modSettings['enable_server_load_check'])) {
    echo '<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/hslw.js"></script>

<div id="topbar">
<table width="100%">
<tr>
<td width="99%">
', $txt['text_server_load_check'], '&nbsp;&nbsp;&nbsp; </td><td width="1%"><a onclick="closebar(); return false"><img style="float: left" src="', $settings['images_url'], '/icons/hslw-close.gif" border="0"></a>

</td>
</tr>
</table>
</div>';
}

with something like this:
Code: [Select]
$load = sys_getloadavg();
if ($load[0] > $modSettings['amount_server_load_check'] && !empty($modSettings['enable_server_load_check']))
{
require_once($sourcedir . '/Subs-Auth.php');
return 'KickGuest';
}

 ???
Title: Re: Disabling resource intensive features based on server load
Post by: Paracelsus on July 28, 2011, 05:46:21 AM
So, in the end, it was even easier and simpler. This worked for me:

Put somewhere in Index.php between the if's this piece (I've put after the line "// Is the forum in maintenance mode?"):
Code: [Select]
$load = sys_getloadavg();
in Index.php turn this:
Code: [Select]
// If guest access is off, a guest can only do one of the very few following actions.
elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'register', 'register2', 'reminder', 'activate', 'smstats', 'help', 'verificationcode'))))
{
require_once($sourcedir . '/Subs-Auth.php');
return 'KickGuest';
}

into this (the load 15 is just an example that can be adjusted to whatever value people want to):
Code: [Select]
// If guest access is off, a guest can only do one of the very few following actions.
elseif ((empty($modSettings['allow_guestAccess']) || ($load[0] > 15)) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'register', 'register2', 'reminder', 'activate', 'smstats', 'help', 'verificationcode'))))
{
require_once($sourcedir . '/Subs-Auth.php');
return 'KickGuest';
}
Title: Re: Disabling resource intensive features based on server load
Post by: humbleworld on January 28, 2013, 11:07:50 PM
Can I use this option for our VPS? Memory is 1.2 GB. Bandwidth is 3,500GB. Space is 60GB.
Title: Re: Disabling resource intensive features based on server load
Post by: Arantor on January 28, 2013, 11:13:08 PM
...it's built into SMF since 1.1 and even has the Load Balancing page in the admin panel since 2.0 RC2...