Strange rails/db performance issue.

I've got a strange problem with rails/db performance http://www.pastie.org/409654

The problem is that some queries take more than 1sek! - and i've got no idea why. This doesnt happen on my localhost (sqlite/mysql).

The server is a fast Xenon + debian 4.0 + nginx + rails 2.3RC1.

I've got a strange problem with rails/db performancehttp://www.pastie.org/409654

Pastie says "Sorry, there is no pastie #409654 or it has expired"

Fred

Sorry :slight_smile: - http://www.pastie.org/409724

I've got a strange problem with rails/db performance http://www.pastie.org/409654

Sorry, there is no pastie #409654 or it has expired.

Wanna try again?

The problem is that some queries take more than 1sek! - and i've got no idea why. This doesnt happen on my localhost (sqlite/mysql).

Can we see the describe output of those tables? (users, projects, users_projects)? Also, how many rows in each?

Sorry, here it is :slight_smile: - http://www.pastie.org/409724

Tables are almost empty - just a few(<10) records for testing. It seems that those slow queries happen sporadically, one time it takes 3.4sec, the next time 0.0002sec. But the interesting part is that it always takes very short or very long amount of time - never in between. So because the whole database holds just a few records, and there are moments that it works as it should - i think it is a server/caching issue. I just started developing this app, and it only has primary keys on "id" column, no other indexes etc.

Based on this, I'd say there is something wrong with your database.
Or at the OS level... swapping, bad disks, something.

I'd remove rails from the equation and run a test update query
directly via mysql until you can figure it out.

Yup!, i've just created a test case of this behaviour in mysql console, so it has nothing to do with rails.

Anyway thanks for your help!

Fixed! :slight_smile: - sort of. If anybody is interested - it helped changing DB type from InnoDB to MyISAM. Somehow InnoDB transactions took very long - it might be a config problem, i'll investigate it later, but for now, i can continue developing :slight_smile:

Hard to really answer without seeing what else is going on on that server. Is it idle or is there traffic on it? Off the cuff, I’m guessing contention in the db–it’s your updates that are taking a long time. Is this MySQL or another db?

It also looks like you’re updating your users table with ‘last_updated_at’ on every request… I don’t think that’s gonna scale.

dwh

Tomim wrote: