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

Reply
 
Thread Tools
Improve performance on thread view updating Details »»
Improve performance on thread view updating
Version: 1.00, by dwh dwh is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Version: 3.0.7 Rating:
Released: 03-16-2005 Last Update: Never Installs: 16
 
No support by the author.

Per Doc Erwin:
http://www.vbulletin.com/forum/showp...8&postcount=18
I'm releasing this here.

I have a suggestion to improve performance although it is for mysql 4.04 and up (I assume at some point a future version of vb will require it).

Requirements: MySQL 4.04

If you have a large forum, run mysql 4.04 and up and want to try this, please report back on your results.

The way updating threads views works right now, (even though putting it in cron improved things,) you are still going through many queries to the thread table, potentially locking it up while updating views.The current code from threadviews.php is:

PHP Code:
PHP Code:
$threads $DB_site->query("SELECT threadid , COUNT(*) AS views FROM " TABLE_PREFIX "threadviews GROUP BY threadid");
 
while (
$thread $DB_site->fetch_array($threads))
{
$DB_site->query(
"UPDATE " TABLE_PREFIX "thread
SET views = views + " 
intval($thread['views']) . "
WHERE threadid = " 
intval($thread['threadid'])
);



With 4.04 you can do a multitable update.
FIRST, create the table ONCE ONLY
PHP Code:
PHP Code:
CREATE TABLE `threadviewsaggregate` (
`
threadidint(10NOT NULL default '0',
`
viewsint(10NOT NULL default '0',
PRIMARY KEY (`threadid`)
TYPE=MyISAM
and in the threadviews.php code change it to

PHP Code:
PHP Code:
$DB_site->query("INSERT INTO ".TABLE_PREFIX ."threadviewsaggregate SELECT threadid , COUNT(*) AS views FROM " TABLE_PREFIX "threadviews GROUP BY threadid");
$DB_site->query("DELETE FROM " TABLE_PREFIX "threadviews"); 
 
$DB_site->query(
"UPDATE " TABLE_PREFIX "thread,"TABLE_PREFIX ."threadviewsaggregate 
SET "
TABLE_PREFIX ."thread.views = "TABLE_PREFIX ."thread.views + ".TABLE_PREFIX."threadviewsaggregate.views
WHERE "
TABLE_PREFIX ."thread.threadid = "TABLE_PREFIX ."threadviewsaggregate.threadid"); 
 
$DB_site->query("DELETE FROM "TABLE_PREFIX ."threadviewsaggregate"); 

That will reduce the number of queries by however many threads get updated in the cron interval. Additionally, you might be able to skip creating the extra table using subqueries. I haven't gotten around to writing that code yet. If someone wants to add that,mention it in this thread and I'll update the code.

Show Your Support

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

Comments
  #32  
Old 05-08-2005, 09:03 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To run a query in your ACP, you must add your userid to the canrunquery variable in your config.php
Reply With Quote
  #33  
Old 05-08-2005, 01:31 PM
dsboyce8624 dsboyce8624 is offline
 
Join Date: May 2005
Location: New Jersey
Posts: 413
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And this is the correct code?

Quote:
Originally Posted by tp214
nevermind!

this is the correct code...

Code:
error_reporting(E_ALL & ~E_NOTICE); 

if (!is_object($DB_site)) 
{ 
        exit; 
} 

$DB_site->query("INSERT INTO ". TABLE_PREFIX ."threadviewsaggregate SELECT threadid , COUNT(*) AS views FROM " . TABLE_PREFIX . "threadviews GROUP BY threadid"); 
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "threadviews"); 

$DB_site->query( 
        "UPDATE " . TABLE_PREFIX . "thread,". TABLE_PREFIX ."threadviewsaggregate 
        SET ". TABLE_PREFIX ."thread.views = ". TABLE_PREFIX ."thread.views + ".TABLE_PREFIX."threadviewsaggregate.views 
        WHERE ". TABLE_PREFIX ."thread.threadid = ". TABLE_PREFIX ."threadviewsaggregate.threadid"); 
$DB_site->query("DELETE FROM ". TABLE_PREFIX ."threadviewsaggregate"); 

log_cron_action('Thread Views Updated', $nextitem);
Reply With Quote
  #34  
Old 05-08-2005, 01:39 PM
dsboyce8624 dsboyce8624 is offline
 
Join Date: May 2005
Location: New Jersey
Posts: 413
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, I put that code in and turned on logging. It says it ran fine.

Thanks for the help.
Reply With Quote
  #35  
Old 05-21-2005, 04:02 PM
GlitterKill GlitterKill is offline
 
Join Date: Jul 2002
Location: Nashville
Posts: 139
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by detalhe
Installed this and got this error after sometime:

PHP Code:
Database error in vBulletin 3.0.6:
 
Invalid SQLINSERTINTOthreadviewsaggregate SELECT threadid COUNT(*)ASviewsFROM threadviews GROUP BY threadid
mysql error
You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERTINTOthreadviewsaggregate SELECT threadid , COUNT(*)ASviews
 
mysql error number: 1064 
Will uninstall :disappointed:
I have used the most recent posted code that is supposed to be good but I get this type of error every hour:

Database error in vBulletin 3.0.6:

Invalid SQL: INSERTINTOthreadviewsaggregate SELECT threadid , COUNT(*)ASviewsFROM threadviews GROUP BY threadid mysql error: 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 'INSERTINTOthreadviewsaggregate SELECT threadid , COUNT(*)ASview

mysql error number: 1064

Date: Saturday 21st of May 2005 10:56:17 AM
Script: http://forums.pimprig.com/cron.php?&rand=634959
Referer: http://gallery.pimprig.com/showphoto...o=2553&cat=501
Username: Unregistered
IP Address: 86.133.1.23
Reply With Quote
  #36  
Old 05-23-2005, 09:14 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Insert spaces where needed. The code in this thread is somehow missing some spaces.

Edit: Edited the original code now with spaces inserted.
Reply With Quote
  #37  
Old 05-23-2005, 10:25 AM
kmike kmike is offline
 
Join Date: Oct 2002
Posts: 169
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Took long enough...
But not all occurences are updated:
Code:
query("SELECTthreadid ,
Reply With Quote
  #38  
Old 05-23-2005, 11:11 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kmike
Took long enough...
There was no reason at all for that remark, especially since the corrections are already posted in this thread (and it is not a 50 page thread).

Quote:
Originally Posted by kmike
But not all occurences are updated:
Thanks fixed.
Reply With Quote
  #39  
Old 05-23-2005, 12:57 PM
kmike kmike is offline
 
Join Date: Oct 2002
Posts: 169
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I thought you're author of this hack but I see my mistake now.
Reply With Quote
  #40  
Old 05-25-2005, 07:03 PM
David Bott David Bott is offline
 
Join Date: Dec 2001
Posts: 215
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Installed on AVS Forum.
Reply With Quote
  #41  
Old 06-17-2005, 05:26 PM
WotC_Mel WotC_Mel is offline
 
Join Date: Apr 2003
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I see this has been installed successfully a few places. Anyone willing to comment on performance improvements they've notice?

-Mel
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 02:54 PM.


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.07244 seconds
  • Memory Usage 2,320KB
  • Queries Executed 25 (?)
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
  • (2)bbcode_code
  • (4)bbcode_php
  • (4)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
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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
  • 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