MyBB Community Forums

Full Version: shutdown_query question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In inc/class_session.php

		// If the last visit was over 900 seconds (session time out) ago then update lastvisit.
		$time = TIME_NOW;
		if($time - $mybb->user['lastactive'] > 900)
		{
			$db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastvisit='{$mybb->user['lastactive']}', lastactive='$time' {$lastip_add} WHERE uid='{$mybb->user['uid']}'");
			$mybb->user['lastvisit'] = $mybb->user['lastactive'];
			require_once MYBB_ROOT."inc/functions_user.php";
			update_pm_count('', 2);
		}
		else
		{
			$timespent = TIME_NOW - $mybb->user['lastactive'];
			$db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastactive='$time', timeonline=timeonline+$timespent {$lastip_add} WHERE uid='{$mybb->user['uid']}'");
		}

What's the advantage of using shutdown_query instead of update_query? Also in my database processes this section locks an aweful lot. Any tips on optimizing this? I have hundreds of users online at once and it appears that every click this is run. I might just delete it entirely and remove the online time feature of mybb. It would be nice however to either optimize this or maybe in 1.6x have a toggle to turn it off.

More adjustments imho have to be made for large forums. My HF database is 1.8gb and server is a dedicated mysql but I have problems daily. Looking at the processes while problems occur it seems it's two things. One is the above mentioned and the other is userfields join. I actually went into class_sessions.php and showthread.php removed the join. I don't use profile fields at all on that site so it won't be missed.

Thank for any input.
This didn't get a single response. Any chance I can get someone knowledgable to make a comment that would help?
In almost 4 pages of support mine was the only one without a response.

Any chance of one?
This might be an odd question, but is PHP's shutdown facility turned on in the ACP?

I guess the else part of the statement could be removed, and the code added to the shutdown query that's run if the user's lastvisit is over 15 minutes ago. Time Spent isn't essential, it's just nice that it's accurate.

Another way, perhaps, is to do this:

else
{
	if(($time - $mybb->user['lastactive']) > 600)
	{
		$timespent = TIME_NOW - $mybb->user['lastactive'];
		$db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastactive='$time', timeonline=timeonline+$timespent {$lastip_add} WHERE uid='{$mybb->user['uid']}'");
	}
}

That way the shutdown is only run once every 10 minutes, per user, if they stay online for that long. You could even increase the time between queries.
Yes it is on. I don't understand exactly what that setting does. I also don't understand what that setting would have in relationship to this query.
(2010-01-06, 09:55 AM)labrocca Wrote: [ -> ]I also don't understand what that setting would have in relationship to this query.

It's to ensure that the lastactive field in the database is always updated, regardless if the page finishes loading or not.
(2010-01-02, 10:29 PM)labrocca Wrote: [ -> ]What's the advantage of using shutdown_query instead of update_query? Also in my database processes this section locks an aweful lot. Any tips on optimizing this? I have hundreds of users online at once and it appears that every click this is run. I might just delete it entirely and remove the online time feature of mybb. It would be nice however to either optimize this or maybe in 1.6x have a toggle to turn it off.

More adjustments imho have to be made for large forums. My HF database is 1.8gb and server is a dedicated mysql but I have problems daily. Looking at the processes while problems occur it seems it's two things. One is the above mentioned and the other is userfields join. I actually went into class_sessions.php and showthread.php removed the join. I don't use profile fields at all on that site so it won't be missed.

Thank for any input.
This didn't get a single response. Any chance I can get someone knowledgable to make a comment that would help?

Dang!

You're absolutely right Labrocca Wink
Last time (1.4.9), My forum can handle easily over 600 members online at a time (trigger 15 minutes).
Even with all your optimized (great) mods. The maximum SQL connection within a day only 30-40 (by tuning My.CNF)

But now? As you said, many Locked Table happen. And connections increase 100 more..
Still under my investigation.
I have more 1.2Gigs database.

Labrocca, please share what you did Smile
I get up to 250 simultaneous max connections with my dedicated MySQL server. So far removing the profile_fields has helped but not enough. Large sites are going to need some help here with optmizations and documentation.

btw..hit 2 million posts today.
Quote:I get up to 250 simultaneous max connections

Oops.. 250 simultaneous?
I could'nt handle more than 100 Wink
Maybe, I will increase banner price to buy more memory :LOL:
shutdown_query basically allows us to run a query at the end of of execution, rather than right then and there.

The reason you'd be having locks is not because of this query, but because a slow mysql response to the user's row being loaded every-every-every single page request on the front end. The only reason you think this query is the problem is because it's a write query, which takes longer on any MyISAM db.

You're problems can probably be solved by either analyzing any queries that might be locking up the users table for longer than usual periods of time and adjusting them or adding more appropriate indexes. If that doesn't work then your server simply might be not powerful enough for the activity your getting and you might need to start using MyBB's round-about master/slave replication technology to spread the load on the databases.

The last thing to do is add more memory and allocate all of it. The reason your servers crash is because they are running out of memory when the tables get locked and the requests get backed up in apache. The more memory you add the higher the chance that MySQL can recover increases.
Memory doesn't appear to be the problem unless I haven't allocated enough in my.cnf. I'll hit you up IM this week and give you some access. Maybe you can help me take a deeper look into this.