InnoDB Performance Monitoring with innotop

Man­u­ally extract­ing rel­e­vant infor­ma­tion from repeated incan­ta­tions of SHOW ENGINE INNODB STATUS while try­ing to fig­ure out what Inn­oDB is doing is not only error prone, it’s just plain hard to do. And since MySQL doesn’t expose the data you really want in an INFORMATION_SCHEMA table (yet?), the option is use an exter­nal pro­gram to help: innotop.

As luck would have it, in 2006 Baron Schwartz announced his inno­top: the most advanced MySQL and Inn­oDB mon­i­tor. And in the time since then it has def­i­nitely evolved into a suit­able replace­ment for the 10-year-old mytop.

Install and Use

Edit: Updated ver­sion 1.7.x located at http://code.google.com/p/innotop/updates/list

You can down­load the lat­est ver­sion of inno­top from Source­forge. As of this writ­ing, the lat­est ver­sion if 1.6. Once you’ve grabbed it, instal­la­tion is like any CPAN mod­ule (since inno­top is writ­ten in Perl).

$ tar -zxf innotop-1.6.0.tar.gz
$ cd innotop-1.6.0
$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for innotop
$ sudo make install
cp InnoDBParser.pm blib/lib/InnoDBParser.pm
cp innotop blib/script/innotop
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/innotop
Manifying blib/man1/innotop.1p
Manifying blib/man3/InnoDBParser.3pm
Installing /usr/local/share/perl/5.10.0/InnoDBParser.pm
Installing /usr/local/man/man1/innotop.1p
Installing /usr/local/man/man3/InnoDBParser.3pm
Installing /usr/local/bin/innotop
Writing /usr/local/lib/perl/5.10.0/auto/innotop/.packlist
Appending installation info to /usr/local/lib/perl/5.10.0/perllocal.pod

There is also a Debian pack­age avail­able from Source­forge that should work on Debian and Ubuntu.

The Basics

Once inno­top is installed, you can sim­ply run innotop. The first time you run it, you’ll be prompted to cre­ate a new data­base con­nec­tion and name it. With inno­top you can have any num­ber of saved named data­base con­nec­tions that you can then refer to by name to quickly con­nect to a server with­out re-specifying the host­name, user­name, pass­word, and so on.

If you have a MySQL server run­ning on the same host where you’re test­ing inno­top, you might call the first con­nec­tion “localhost”.

Enter a name: localhost

Next you’re prompted to enter a “DSN string” which is what Perl DBI uses to rep­re­sent the data­base con­nec­tion parameters.

Typical DSN strings look like
   DBI:mysql:;host=hostname;port=port
The db and port are optional and can usually be omitted.
If you specify 'mysql_read_default_group=mysql' many options can be read
from your mysql options files (~/.my.cnf, /etc/my.cnf).

Enter a DSN string: DBI:mysql:;host=localhost

Then you’re prompted for an optional table name that inno­top can use for dead­lock detec­tion infor­ma­tion, along with a user­name and password:

Optional: enter a table (must not exist) to use when resetting InnoDB deadlock information: blahtable
Do you want to specify a username for localhost?: y
Do you want to specify a password for localhost?: y
Enter username for localhost: root
Enter password for 'root' on localhost: *****
Save password in plain text in the config file?: y

With all that infor­ma­tion, inno­top will save a con­fig­u­ra­tion file as ~/.innotop/innotop.ini con­nect to the server and start show­ing some high-level sta­tis­tics that may look some­thing like this:

________________________________ InnoDB Row Operations ________________________________
CXN   Ins         Upd        Read        Del        Ins/Sec  Upd/Sec  Read/Sec  Del/Sec
root  1717192746  141503339  1935029792  146254835   166.42    97.45    257.37     0.00

______________________ Row Operation Misc _______________________
CXN   Queries Queued  Queries Inside  Rd Views  Main Thread State
root               0               0         1  flushing log

_____________________________________ InnoDB Semaphores ______________________________________
CXN   Waits    Spins      Rounds     RW Waits  RW Spins  Sh Waits  Sh Spins  Signals   ResCnt
root  2475263  104367748  344363574   1572553   3573154   3082885   5833069  11083664  7957967

_______________________________ InnoDB Wait Array _______________________________
CXN  Thread  Time  File  Line  Type  Readers  Lck Var  Waiters  Waiting?  Ending?

If so, your inno­top instal­la­tion is work­ing correctly.

Mon­i­tor­ing Modes

Like mytop, inno­top can be switched into a vari­ety of mon­i­tor­ing modes based on what you want to focus on. By default, you’ll see mode “R” or Inn­oDB Row Oper­a­tions. As its name implies, this mode sum­ma­rizes row-level sta­tis­tics such as rows inserted or deleted per sec­ond. You can press “?” to see a list of all the mon­i­tor­ing modes and the sin­gle let­ter key­stroke used to switch to each of them.

Here are some of the other use­ful modes:

B: Inn­oDB Buffers

This view presents buffer pool infor­ma­tion, page sta­tis­tics, insert buffer infor­ma­tion, and met­rics for adap­tive hash indexes. I often check this mode to see what the buffer pool hit rate is as well as how many page reads and writes per sec­ond the server is doing.

C: Com­mand Summary

The com­mand sum­mary shows the break­down of which com­mands MySQL has been han­dling. They’re listed from most fre­quent to least fre­quent and the dis­play shows total counts for each as well as a per­cent­age. Two sets of each num­bers are pre­sented. The first looks at num­bers since the server was started while the sec­ond only shows num­bers from the last polling cycle.

D: Inn­oDB Deadlocks

If you’re see­ing dead­locks with some reg­u­lar­ity, this dis­play pulls together the nec­es­sary infor­ma­tion to diag­nose what’s hap­pen­ing, includ­ing user­name, host­name, query, time, vic­tim, and so on.

F: Inn­oDB For­eign Key Errors

While I’ve never needed it, the for­eign key mode will present for­eign key prob­lems in a use­ful format.

I: Inn­oDB File I/O

The File I/O mode is very use­ful when look­ing at some per­for­mance prob­lems. You can see at a glance how many I/O threads have pend­ing I/O requests as well as the total num­ber of reads and writes (over­all and per sec­ond) as well as the num­ber of bytes read and writ­ten. Finally, the I/O mode sum­ma­rizes the Inn­oDB log file check­point sta­tis­tics and over­all I/O as well.

L: Locks

When you sus­pect that you’re run­ning into lock con­tention, the Locks view will help you see which clients/queries are involved and how often it is happening.

M: Master/Slave Repli­ca­tion Status

This view presents a sum­mary of the slav­ing infor­ma­tion for both the SQL and IO threads on a slave. You can see the binary log file being used, repli­ca­tion lag, log file size, and so on.

Q: Query List

The Query List view shows the queries that MySQL is pro­cess­ing. And like in mytop, you can select a spe­cific query to view the full query and run it through the EXPLAIN command.

R: Inn­oDB Row Oper­a­tions and Semaphores

As noted ear­lier, this view pro­vides sta­tis­tics about rows cre­ated, updated, deleted, read as well as Inn­oDB sem­a­phores (inter­nal lock­ing) and the Wait Array.

T: Inn­oDB Transactions

Finally, the Trans­ac­tions mode shows the trans­ac­tion state of all the threads (at least those con­nected to a client) run­ning inside of MySQL. You can see who owns the trans­ac­tion, which host they are con­nected from, the trans­ac­tion sta­tus, run­ning time, and the query that’s cur­rently being run inside the transaction.

That’s Not All

Believe it or not, inno­top can do more than that. Spend a bit of time read­ing the biult-in help (hit the “?” key in any of the modes) and read the inno­top man­ual page. You’ll find that inno­top can talk to mul­ti­ple servers and main­tain lists of server groups, since we often deploy MySQL in multi-machine clus­ters. In other words, inno­top doesn’t assume that you’re only going to watch a sin­gle server like mytop did.

The more I use inno­top, the less inclined I am to con­tinue main­tain­ing and updat­ing mytop, even though I use it almost daily at work. If you’ve been an mytop user and depend on Inn­oDB, I highly rec­om­mend giv­ing inno­top a try.

Jeremy Zawodny is a soft­ware engi­neer at Craigslist where he works on MySQL, Search, and var­i­ous back-end infra­struc­ture. He’s also the co-author of “High Per­for­mance MySQL” and blogs at http://jeremy.zawodny.com/blog/

Tags: , , , ,

1 Response to "InnoDB Performance Monitoring with innotop"

Leave a Comment

*

Get Adobe Flash player