Back to vBulletin 4 Articles

Delay reindexing as necessary to control server load
by Philip 22 Dec 2010

It is sometimes necessary to rebuild the search index, and it can be quite resource-intensive and time-consuming with larger boards. It takes a few hours on my forums, so I just came up with the following code to keep the server load from spinning out of cotrol. It should work under most linux distributions, as long as you have access to /proc/loadavg from PHP (if not, see notes below).

In /admincp/misc.php, find the following lines (around line 184 in the latest vB 4.1 PL1 build):

Code:
if ($vbulletin->GPC['autoredirect'] == 1)
{
Right after, add this code:
Code:
  $load = explode(' ',@file_get_contents('/proc/loadavg')); // find out load
  if ($load[1] > 8) {    // if 5-min load average is over 8...
        usleep(3000000); // in millionths of a second - adds 3 second delay 
  }

The idea is that this only adds a delay to redirects when/if server load exceeds some value (8 in this example).
The only downside I can see is checking the load average after each redirect... But it seems to work much better than the default reindexing on my server.

I hope it helps someone.


Notes:
If you do not have access to /proc/loadavg from PHP, you can try to execute `uptime` instead, or just add the "usleep ..." line to delay each redirect (even though it's a crude solution as it would slow down reindexing by a lot regardless of server load).

The uptime code variant of the above should be something like:
$load = explode(' ', `uptime`)
$load_5min = $load[count($load)-1];
if ($load_5min > 8) { .....

Similar Mods

[Linux] loadsock (retrieve server load from remote server) vBulletin 2.x Full Releases

vblts.ru supports vBulletin®, 2022-2024