views:

142

answers:

4

Our relatively high traffic website just screeched to a halt, and we're totally stumped. We run on Django and Mysql (InnoDB), and we're trying to figure out why it's all of a sudden totally slow.

Here's what we know so far: On our mysql server, a simple query (from django shell) runs fast. On our app server, a simple query (from django shell) runs very slow.

+5  A: 

Without having any details on the query or on the tables involved in the query, it is quite difficult to answer this question.

Most likely it is because of a lot of data in the table and a missing index on the field you are querying.

This would explain why it is slow on the production box, but fast on the dev box (since there's less data).

To answer the question better, could you provide us with more details? Table structure, query, number of rows in the table, etc. ?

More assumptions: Disk I/O on the app server could be a problem, maybe the log files in MySql are not properly configured (especially with InnoDB this could lead to a problem). Maybe there's a load-heavy query running too often? Table locks when multiple users write to/read from the same tables?

As I said, without having more details, it is quite difficult to guess. But I hope, at least I could point you in the right direction.

Cassy
+1 Indexes sound like a very likely reason.
Tom Leys
A: 

Are the 'mysql server' and 'app server' on the same box and talking to the same DB instance?

Your question suggests not, so I'd look for a problem on the network - start by pinging the database server from each box and compare the results.

Once you've done that you'll need to be a little more specific about the problem - were the ping times the same, are you running the same query, etc...

Nick Holt
+1  A: 

Run EXPLAIN on the SELECT. Study this page carefully:

http://dev.mysql.com/doc/refman/5.0/en/using-explain.html

Understanding the concepts on that page are key to properly index your tables.

joedevon
+1  A: 

Thanks for the responses everyone.

Turns out it was a DNS issue (which was a regression). MySQL is really stupid in that the default is to use DNS lookups. They got really slow, which killed all the network flow between the app server and the db server. It was as simple as adding "skip-name-resolve" to our my.cnf.

finkel
Ah yes, that's a famous old one. Got stung by that few years ago.
joedevon