Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases
FAQ Community Calendar Today's Posts Search

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
  #42  
Old 06-17-2005, 05:33 PM
mute mute is offline
 
Join Date: Dec 2002
Location: Phoenixville, PA
Posts: 152
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does anyone know if this made its way into 3.5.0?
Reply With Quote
  #43  
Old 06-29-2005, 01:21 AM
lazee lazee is offline
 
Join Date: May 2004
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I used this one smooth and help my board alot with no problem ,but today when i notice that the thead didn't count when people view , i ran the cron job theadview in schedules and i got this error :
Database error in vBulletin 3.0.7:

Invalid SQL: INSERT INTO threadviewsaggregate SELECT threadid , COUNT(*) AS views FROM threadviews GROUP BY threadid
mysql error: Duplicate entry '40' for key 1

mysql error number: 1062

Date: Tuesday 28th of June 2005 08:09:36 PM
Script: http://xx.com/forum/admincp/cronadmi...ncron&cronid=2
Referer: http://xx.com/forum/admincp/index.php?

anyone got any idea why i got this and how to fix ,thank in advance . I used to run the threadview before and nerver got this error . before this error, i didn't restore db or install anything .
Reply With Quote
  #44  
Old 06-29-2005, 04:27 AM
kmike kmike is offline
 
Join Date: Oct 2002
Posts: 169
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should empty threadviewsaggregate table. It is cleared at the end of cron script run, but it didn't happen at some point for some reason. Theoretically, it can happen when you shutdown http server in the middle of cron job run.
Reply With Quote
  #45  
Old 07-03-2005, 07:05 PM
lazee lazee is offline
 
Join Date: May 2004
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank Kmike .it working after i empty the threadview.. . I think i did restart the apache that was cause the problem like you said .
Reply With Quote
  #46  
Old 09-23-2005, 05:48 AM
michaelbenson's Avatar
michaelbenson michaelbenson is offline
 
Join Date: Feb 2005
Location: United Kingdom
Posts: 221
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Erm, where exactly is this threadviews.php file?
I have tried looking around and i am using 3.0.9 has it since been removed?
Reply With Quote
  #47  
Old 09-23-2005, 06:53 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

includes/cron
Reply With Quote
Reply


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:54 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.04636 seconds
  • Memory Usage 2,274KB
  • Queries Executed 23 (?)
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
  • (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
  • (2)pagenav_pagelink
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (6)postbit
  • (7)postbit_onlinestatus
  • (7)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