Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases

Reply
 
Thread Tools
Restrict search when the server load is high Details »»
Restrict search when the server load is high
Version: 1.00, by UK Jimbo UK Jimbo is offline
Developer Last Online: Mar 2013 Show Printable Version Email this Page

Version: 3.0.6 Rating:
Released: 02-15-2005 Last Update: Never Installs: 5
 
No support by the author.

From experience searches on large forums can slow the server down a lot.

Here's a dead simple hack that lets you disable searches when the load average reaches a defined level. Moderators are exempt from the search ban.

There's are just two changes to be made:

in search.php find:
PHP Code:
if (!$vboptions['enablesearches'])
{
        eval(
print_standard_error('error_searchdisabled'));

add below it:
PHP Code:
// automatically block search requests when the server is busy
$search_load_trigger=5;
if ( (!(
$permissions['adminpermissions'] & ISMODERATOR)) AND PHP_OS == 'Linux' AND @file_exists('/proc/loadavg') AND $filestuff = @file_get_contents('/proc/loadavg'))
{
        
$loadavg explode(' '$filestuff);
        if (
trim($loadavg[0]) > $search_load_trigger)
        {
                eval(
print_standard_error('error_searchdisabled'));
        }

The trigger level is based on the current (1 minute) load average. It can be changed by editing the $search_load_trigger variable.

You may also wish to change the searchdisabled phrase to something like:

Quote:
Searching has been disabled. This is most likely automatic and due to high server load. Please try again later.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 04-07-2005, 08:03 AM
hollyboy's Avatar
hollyboy hollyboy is offline
 
Join Date: Mar 2004
Posts: 318
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by UK Jimbo
$search_load_trigger=5;

at the top.

Where 5 is a one minute load average of 5.
I set it to 1 just to check if the hack worked and when my server load was at 1 the search still could be used. I'm on a linux server
Reply With Quote
  #13  
Old 04-07-2005, 09:01 AM
UK Jimbo's Avatar
UK Jimbo UK Jimbo is offline
 
Join Date: Sep 2002
Posts: 249
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by hollyboy
I set it to 1 just to check if the hack worked and when my server load was at 1 the search still could be used. I'm on a linux server
Admin users won't be search limited. Are you sure that you're weren't testing as an admin user?
Reply With Quote
  #14  
Old 04-07-2005, 09:04 AM
hollyboy's Avatar
hollyboy hollyboy is offline
 
Join Date: Mar 2004
Posts: 318
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by UK Jimbo
Admin users won't be search limited. Are you sure that you're weren't testing as an admin user?
as guest
Reply With Quote
  #15  
Old 04-07-2005, 09:08 AM
UK Jimbo's Avatar
UK Jimbo UK Jimbo is offline
 
Join Date: Sep 2002
Posts: 249
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by hollyboy
as guest
Sounds like something's broken then

Does the file /proc/loadavg exist? Is it readable?
Reply With Quote
  #16  
Old 04-07-2005, 09:11 AM
hollyboy's Avatar
hollyboy hollyboy is offline
 
Join Date: Mar 2004
Posts: 318
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by UK Jimbo
Sounds like something's broken then

Does the file /proc/loadavg exist? Is it readable?
where is this file?
Reply With Quote
  #17  
Old 04-07-2005, 09:17 AM
UK Jimbo's Avatar
UK Jimbo UK Jimbo is offline
 
Join Date: Sep 2002
Posts: 249
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by hollyboy
where is this file?
at /proc/loadavg (!)

Try creating a simple PHP file with the following code in:

PHP Code:
<?php

if( file_exists('/proc/loadavg') ) {
    echo(
"loadavg exists");
} else {
    echo(
"can't find file");
}

?>
Now run this file and post up the output
Reply With Quote
  #18  
Old 04-07-2005, 09:22 AM
hollyboy's Avatar
hollyboy hollyboy is offline
 
Join Date: Mar 2004
Posts: 318
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by UK Jimbo
<?php

if( file_exists('/proc/loadavg') ) {
echo("loadavg exists");
} else {
echo("can't find file");
}

?>
http://www.interfans.org/forum/prop.php
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:32 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08744 seconds
  • Memory Usage 2,284KB
  • Queries Executed 24 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_php
  • (8)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete