MyBB Community Forums

Full Version: Little tweaks for large boards
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Little performance tweaks for medium and large boards. Tested and applied on forum with:
173 000 posts (>510 daily)
17 600 threads (>50 daily)
15 000 users (>45 daily)

1. In file member.php
FIND:
PHP Code:
$query $db->simple_select(TABLE_PREFIX."posts""COUNT(pid) AS posts""visible > 0"); 
REPLACE WITH:
PHP Code:
$query $db->simple_select(TABLE_PREFIX."posts""COUNT(pid) AS posts"); 
Huge benefit in query time while viewing members profiles which can normally take seconds. After removing WHERE clause - it takes 0.0011451 sec. On my board I had about 70 posts with visible <= 0 so removing the WHERE clause is a unnoticable "error". But on some sites this can lead to bad statistics of user's posts per day.

2. In file global.php
FIND:
PHP Code:
if($rand || isset($mybb->input['force_thread_expiry'])) 
REPLACE WITH:
PHP Code:
if($rand || isset($mybb->input['force_thread_expiry'])) 
In original code there is about 2/11 chance for deleting old thread redirects ($db->delete_query(TABLE_PREFIX."threads", "deletetime != '0' AND deletetime < '".time()."'")Wink. It can be reduced to 1/11 Smile. This query is really slooooooow so one may think of even less chance.

3. In file global.php
FIND:
PHP Code:
if($rand && $rand 8
REPLACE WITH:
PHP Code:
if($rand == 9
(or something like $rand == X, where X is a number from 0 to 10).
When we have many users online we can reduce the chance for deleting old guest sessions from 3/11 to 1/11.


And others from:
http://community.mybboard.net/showthread.php?tid=16811
http://community.mybboard.net/showthread.php?tid=10368
http://community.mybboard.net/showthread.php?tid=16814


TODO: Check MySQL queries on 3 main pages:
- index.php
- showthread.php
- forumdisplay.php
to reduce number of Using temporary, Using filesort or just slow queries.
1. That will cause more bugs
2. This has been already changed in 1.4 in a different way
3. Same as #2
1. It does not cause any bugs just a inaccurate result. On large board this is negligible error and a boost of performance (eg. query takes not 6 seconds but 0.001). I do not think it should be put in mainstream MyBB - I just give a small solution for large boards.
2 & 3. Good to hear it.
A better replacement for #1 would be:

Find:
PHP Code:
    $query $db->simple_select("posts""COUNT(pid) AS posts""visible > 0");
    
$posts $db->fetch_field($query"posts"); 

Replace with:
PHP Code:
    $stats $cache->read("stats");
    
$posts $stats['numposts']; 

That way it uses the internal MyBB cache.

(I've already changed this for MyBB 1.2.4 and MyBB 1.4)
Thanks, I will try this.
koziolek Wrote:1. It does not cause any bugs just a inaccurate result. On large board this is negligible error and a boost of performance (eg. query takes not 6 seconds but 0.001). I do not think it should be put in mainstream MyBB - I just give a small solution for large boards.

That would be a bug. But yes, I also forgot to mention that #1 will use the MyBB will use the cache for that query.
Tikitiki Wrote:2. This has been already changed in 1.4 in a different way
3. Same as #2

Are these going to be put into some sort of 'mycron' system? In other words scripts that will run at the end of page execution durring certain times of the day?

I've commented out both sections of code and set them to run via server cron. I was thinking about writing a task manager for the admincp but it sounds like you're hinting that you guys have already planned to do just that. Wink
Yes, 1.4 will have a task scheduling system similar to crontabs. I finished implementing it the other day and the first things I moved were the pieces of code above in to a task.
In file forumdisplay.php:
FIND:
PHP Code:
// How many pages are there?
$query $db->simple_select(TABLE_PREFIX."threads t""COUNT(t.tid) AS threads""t.fid = '$fid' $visibleonly $datecutsql"); 
(query time: 0,07s)
REPLACE WITH:
PHP Code:
// How many pages are there?
$query $db->simple_select(TABLE_PREFIX."threads t""COUNT(*) AS threads""t.fid = '$fid' $datecutsql"); 
(query time: 0,009s)
But this may produce a bug - bad number of pages.
Uhhhhh yeh, all your doing is making bugs. Unless you've got optimizations that don't create bugs you're just making useless posts.
Pages: 1 2
Reference URL's