Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
Who's Online
6 registered (Daryl Fawcett, packlite, Rick, Ruben Rocha, Thelockman, 1 invisible), 29 Guests and 23 Spiders online.
Key: Admin, Global Mod, Mod
Featured Member
Registered: 01/30/08
Posts: 32
Top Posters (30 Days)
Ruben Rocha 102
Rick 85
Mark S 72
Gizmo 50
Thelockman 50
driv 35
ntdoc 30
Sirdude 30
packlite 26
AllenAyres 26
Latest Photos
bear test
Beach Barbie-Q
Sunset
Accept the challenge!
Trees
Page 1 of 2 1 2 >
Topic Options
Rate This Topic
#217274 - 09/24/08 12:26 PM simple sql query causing 100% cpu usage for minutes
bakerzdosen Offline
stranger

Registered: 09/18/08
Posts: 14
Loc: Utah
I realize that this is somewhat of a mysql question, but here it goes:

Our whole board is basically frozen at random times because (it seems like it anyway) of this simple ubb query:

select COUNT(t1.POST_ID) as posts, sum(t1.POST_IS_TOPIC) as topics from ubbt_POSTS as t1

Here's the history: Everything's running fine. Suddenly, the board seems frozen and everyone is getting http timeouts. So, I log in and find that mysqld (5.0.22) is at roughly 100% CPU usage. I look at the processlist and the above query is the only thing running in the processlist except my "show processlist" query. The PID does change, but only after 15-20 seconds or so. If I run the query on its own, it takes 1.41 to 1.46 seconds every time under normal circumstances.

Restarting mysqld clears the problem, and everything is running as expected... for a while. Then the problem returns. It does seem to clear itself after 15-20 minutes, but I think that's just because everyone gives up trying to access anything.

I thought it was twiceler, but it wasn't as it's blocked now.

I tried running optimize table on ubbt_POSTS, but that didn't fix it.

There are no cron jobs, and this is 5.0.22, so there are no scheduled tasks from within the db itself.

What am I missing?
_________________________
bmwsporttouring.com

Top
#217276 - 09/24/08 01:10 PM Re: simple sql query causing 100% cpu usage for minutes [Re: bakerzdosen]
Rick Administrator Online   content

*****

Registered: 06/04/06
Posts: 7998
Loc: Aberdeen, WA
This looks like you have the option to show total # of unread topics/posts. You can find this under Display Options. Both of these can cause a pretty high load on the SQL server especially if you have quite a few users that have a lot of unread posts.

It has to go through each forum, checking their last visit, and tallying the number of posts that have been posted since then. What happens is some users just visit a couple forums, while never visiting some of the other ones, so the number that needs to be counted continues to grow.

You can encourage your users to frequently "Mark all as read" to help, but you may just need to turn the feature off.
_________________________
UBB.threads™ Developer
My Personal Website · StogieSmokers.com

Top
#217279 - 09/24/08 02:30 PM Re: simple sql query causing 100% cpu usage for minutes [Re: Rick]
bakerzdosen Offline
stranger

Registered: 09/18/08
Posts: 14
Loc: Utah
Well, I guess we'll know within an hour or two if that's the right direction to be heading. I just turned it off - for now.

Thanks for the pointer.
_________________________
bmwsporttouring.com

Top
#217285 - 09/24/08 03:22 PM Re: simple sql query causing 100% cpu usage for minutes [Re: bakerzdosen]
bakerzdosen Offline
stranger

Registered: 09/18/08
Posts: 14
Loc: Utah
Nope. Same problem even with that option turned off.

As much as I trust Linux (IMHO, better than anything to come out of Redmond, yet not quite Solaris yet), 143 days uptime has me wondering if a reboot might be in order...

When I get to a reboot, I'm just out of ideas...

Could there be other tables I need to "optimize?" I'm still a little light on the lingo with mysql, but could there be a corrupt index or could there be any other problem that's index related? I'm just not used to only seeing one connection to a db bring down an entire app like this.

If I'm reading this correctly, ubb makes only one connection to the db, and then runs all of it's queries through that single connection. Right? Otherwise, somehow, some of the queries/connections are not being reported by "show processlist;"
_________________________
bmwsporttouring.com

Top
#217299 - 09/25/08 12:12 AM Re: simple sql query causing 100% cpu usage for minutes [Re: bakerzdosen]
Rick Administrator Online   content

*****

Registered: 06/04/06
Posts: 7998
Loc: Aberdeen, WA
Are you still seeing this query as the slowdown cause?

select COUNT(t1.POST_ID) as posts, sum(t1.POST_IS_TOPIC) as topics from ubbt_POSTS as t1

That is only run when the options to show total unread topics/posts is turned on.
_________________________
UBB.threads™ Developer
My Personal Website · StogieSmokers.com

Top
#217300 - 09/25/08 12:13 AM Re: simple sql query causing 100% cpu usage for minutes [Re: Rick]
Rick Administrator Online   content

*****

Registered: 06/04/06
Posts: 7998
Loc: Aberdeen, WA
Yes, basically, when a user requests a page a database connection is made. Every query for the generated page is done using that connection, and when the page is served, the connection is closed.
_________________________
UBB.threads™ Developer
My Personal Website · StogieSmokers.com

Top
#217312 - 09/25/08 11:42 AM Re: simple sql query causing 100% cpu usage for minutes [Re: Rick]
bakerzdosen Offline
stranger

Registered: 09/18/08
Posts: 14
Loc: Utah
Yup - still having problems. I turned the option off (CP -> Display options -> Primary -> Forum Display options -> Show total # of unread replies in topics? ) and yet was still having the site basically unaccessible 6-7 hours later. It was obvious that the option was unchecked because the unread posts were not listed as they were before.

I'm REALLY ashamed to admit to this hack, but here's where we are now: I'm headed out for the weekend and won't be able to babysit until Sunday night. So, I've got mysqld restarting every half-hour. Things are better now, but users still reported some slowness last night.

I rebooted the server, but that didn't have any effect.

I really can't tell you that that query is definitely the cause of the problem, but I can say that it was running during the slowdowns. However, that could just be that that was the slowest of the processes and the only one I was able to "catch" by running "show processlist;".

As a side note, the number of locks (table_locks_immediate) sky rockets during our periods of slowness. Right now (period of moderate to high activity for us) I saw a peak right around 25k locks, but that number dropped to 1100 shortly after the automatic restart and has been climbing since. That number shoots up to around (well, just under) 1 million when the system's hammered. I have no idea if that's relevant, but

Right this moment, we have literally 2-3 times the number of users showing up in "who's online" than we had last night during a slowdown, so I don't think the server's getting overloaded by any means.

Thanks for the info about connections. I'm not reading things wrong then...

Frankly, I'm baffled. We did just to a major upgrade/migration back in June to ubb7. However, we hadn't seen problems until last week, so I don't know if that's relevant either.
_________________________
bmwsporttouring.com

Top
#217319 - 09/25/08 04:56 PM Re: simple sql query causing 100% cpu usage for minutes [Re: bakerzdosen]
Gizmo Moderator Offline

***

Registered: 06/04/06
Posts: 12089
Loc: Portland, OR; USA
Dumb question; are you by chance using persistant connections in your ubb config to connect to the mysql db? If so, I'd highly advise turning them off...
_________________________
UGN Security, Elite Web Gamers & VNC Web Design Owner
Longtime UBB Supporter, UBB7 Beta Tester & Resident Post-A-Holic

Top
#217338 - 09/26/08 09:25 AM Re: simple sql query causing 100% cpu usage for minutes [Re: Gizmo]
Rick Administrator Online   content

*****

Registered: 06/04/06
Posts: 7998
Loc: Aberdeen, WA
Just took a peek at your forum, even registered so I could get a good look at the size of your forum.

It's not all that large, so even having the total # of unread topics/posts turned on should be that bad at all. I was thinking maybe the search could be doing it as sometimes it can lock while doing a large search over all posts, however on the size of your forum, that shouldn't be an issue either.

Are you logging slow queries in your mysql configuration?
_________________________
UBB.threads™ Developer
My Personal Website · StogieSmokers.com

Top
#217437 - 09/29/08 11:26 PM Re: simple sql query causing 100% cpu usage for minutes [Re: Rick]
bakerzdosen Offline
stranger

Registered: 09/18/08
Posts: 14
Loc: Utah
Originally Posted By: Gizmo
Dumb question; are you by chance using persistant connections in your ubb config to connect to the mysql db? If so, I'd highly advise turning them off...
Nope. I just checked. We're not. Thanks for the heads up though.
Originally Posted By: Rick
Just took a peek at your forum, even registered so I could get a good look at the size of your forum.
Thanks. I love this internet thing. I'm betting it might just catch on one day...
Originally Posted By: Rick
It's not all that large, so even having the total # of unread topics/posts turned on should be that bad at all. I was thinking maybe the search could be doing it as sometimes it can lock while doing a large search over all posts, however on the size of your forum, that shouldn't be an issue either.
Yeah, and that's the thing. I'm pretty new to all of this (baptism by fire I suppose), but I've used ubb in LOTS of other settings and it's never been an issue with much bigger sites. I've just never known what they've had running on the back end. I deal with pretty big iron for my day job, so a 2x2.8GHz P4 w/ 1.5GB RAM config seems awfully slow to me at first glance.

Originally Posted By: Rick
Are you logging slow queries in your mysql configuration?
I'm going to have to get back to you on that one.

Now, with all that said, I'm not sure we'll ever know exactly what was the problem. The guy at our ISP ran a bunch of OS updates - including moving us to mysql 5.0.45 and running myisamchk (which was probably the same as optimize table).

So far so good. It very well may have been completely unrelated to ubb.
_________________________
bmwsporttouring.com

Top
Page 1 of 2 1 2 >


Shout Box

Today's Birthdays
theregit
Recent Topics
7.4.1 show/hide category bug
by Seattlebrian
01/09/09 11:56 AM
7.4.2 Discussion
by Rick
01/09/09 10:21 AM
UBBCentral now running 7.4.2
by Rick
01/09/09 10:21 AM
New members don't get access and are not displayed in the config panel
by Yomar
01/08/09 03:32 AM
How to Change Link Color / Underline in styles?
by ECNet
01/07/09 10:00 PM
Forum Stats
4298 Members
33 Forums
30692 Topics
156031 Posts

Max Online: 978 @ 06/24/07 08:19 PM