Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 09-25-2013, 10:02 PM
schan schan is offline
 
Join Date: Sep 2013
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 3.8.7 Patch Level 3 Custom Cron Task

Hey all,

I am working on a product that involves querying the database for, say, 100 posts and does stuff with it. I set a scheduled task via Admin Panel to run this task every minute. When the task runs, it causes our forum (front-end) to be unusable until the query is done. I can see how this can be a problem, but why do the built-in vBulletin's cron tasks do not have this problem? Are these cron tasks built using special cron functions? If so, can you point me to the right direction so I can modify my script?

Thank you in advance. I'm looking forward to your responses.

- S
Reply With Quote
  #2  
Old 09-25-2013, 10:20 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

From the admin popup help page:

Quote:
Set it to * to have it run every minute (not really recommended!).
Also, to know why it may be doing that, we would need the code you are using in order to debug it.
Reply With Quote
  #3  
Old 09-26-2013, 06:15 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe your query is looping but as Ozzy47 says we need to see your code in order to help with that.
Reply With Quote
  #4  
Old 09-27-2013, 06:32 PM
schan schan is offline
 
Join Date: Sep 2013
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your responses. I was able to figure it out. The code was going through too many loops.

Thanks, all!
Reply With Quote
  #5  
Old 09-27-2013, 07:54 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for replying back, and glad you got it sorted.
Reply With Quote
  #6  
Old 11-07-2013, 01:53 AM
schan schan is offline
 
Join Date: Sep 2013
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry that I have to revive this thread. I figured it would be better to than making a new one. We host a Q/A board and want to spell correct all the posts in our database. There are approximately 3.2 million. Our cron task (query for 1000 posts + sent to our spell correct engine) takes about 30 seconds to complete one task. The problem is that when it kicks off, it renders the page unusable so the user ends up having to wait until the task is complete. There are tons of cron jobs that vBulletin also runs, but it doesn't seem to hang the page. What are some reasons why the page would become unusable? I thought the cron job was suppose to run in the background. If not, how can I make it "run in the background" like a real cron?

Thank you in advance.

-S
Reply With Quote
  #7  
Old 11-07-2013, 02:39 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As we said before, post your code so we can see what you are doing.
Reply With Quote
  #8  
Old 11-07-2013, 07:55 PM
schan schan is offline
 
Join Date: Sep 2013
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just a bit of background info: the goal of this function is correct the text that gets sent to it. The function utilizes regex patterns to determine what needs fixing and when.

I can't post the full code, but I will try to post enough so that it gives you guys enough information to have an idea of what could be going on. Do keep in mind that it takes about 30 seconds to complete correcting 1000 posts. The 30 secs may be normal, but since it's running as a cron job, it should not render the page unusable since it's running in the background...at least it should be. Just in case you guys are wondering where's the query, I've tested that the query completes about 1/10 of a second or even faster. The "stall" occurs when the page text gets sent to the fix_spelling function. Anyways, here's the code:

Code:
<?php

public function fix_spelling($text, $severity = 0, $exceptions = array()) {

    list($rgx_start, $rgx_end_replace) = 
        array('(?<=[ .,!?>\]\r\n]|^)', '(?=[ .,!?<\[\r\n]|$)');

    $rgx_end_delete = '( |(?=[.,!?\[\r\n]|$))';

    // $this->dictionary is a multi-dimensional array filled with ~4000 elements.
    // An element consists of multiple attributes, (corrected_word, error_weight and others)

    foreach($this->dictionary as $word=>$prop) {

    	// this line might be problematic due to in_array being called 4000 times
    	if(stripos($text, $word) !== FALSE && !in_array($word, $exceptions)) {

    		// some initialization based on value of $prop[corrected_word] takes
    		// place here ....finally, we call a preg-replace on a match

    		$text = preg_replace("variables that contain regex goes here (i.e. $rgx_start and so on)", "corrected_word goes here", $text, -1, $count);

    		if($count) {
    			// We want to highlight the corrected words so users know what was corrected
    			// Initialize highlight with another preg_replace goes here...syntax is similar to $text
    			$highlight = preg_replace("....");
    		}
    	}
    }

    // we want to capitalize i but there are some cases where we shouldn't, such as i.e.
    // do a preg_match for some special cases
    $rgx_list = preg_match("....");
    // call a preg_replace again on $text
    $text = preg_replace("....$rgx_list, ....");

    // if replacements occurred $count is set
    if($count)
    	$highlight = preg_replace(".....");

    // now we also want to have special corrections in case the post is a Math-based post
    if(preg_match("regex patterns for math keywords such as sin, pi, theta and so on")) {
    	// do something ..jsut a variable initialization
    }

    // fix single letters such as b, n, r, u, y => be, and, are, you, why respectively
    list($rgx1, $rgx_start, $rgx_end) = array('regex pattern1', 'regex pattern2', 'regex pattern3');

    // this foreach loop should only run 5 times...the length of the array holding the "b, n, r, u, y"
    foreach ($letters as $letter=>$fix) {
    	// There are two if statements which does two preg_replace each...the 2nd preg_replace will only happen if the 1st preg_replace found replacements (i.e. $count is set)

    }

    ....
    // There are a total of 8 more preg_replace calls total and 2 preg_matches
    .....
    return array(array($text, $highlight), $error_score);
}
Reply With Quote
  #9  
Old 11-07-2013, 09:17 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would be prudent for you to check your server logs and see if you are using a lot of memory or cpu time when this runs, it doesn't matter that it's "running in the background" you still need the resources for the task to take place.
Reply With Quote
Благодарность от:
Max Taxable
  #10  
Old 11-07-2013, 10:22 PM
schan schan is offline
 
Join Date: Sep 2013
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for the response. I'll keep that in mind while I continue to troubleshoot.

-S
Reply With Quote
Reply

Thread Tools
Display Modes

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 08:46 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04213 seconds
  • Memory Usage 2,256KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete