Thursday September 17, 2009
querystat - DTrace script to monitor your queries, query cache and server thread pre-emption
I was recently helping some colleagues check what was happening with their MySQL queries, and wrote a DTrace script to do it. Time to share that script.
First of all, a look at some output from the script:
mashie[bash]# ./querystat.d -p `pgrep mysqld`
Tracing started at 2009 Sep 17 16:28:35
2009 Sep 17 16:28:38 throughput 3 queries/sec
2009 Sep 17 16:28:41 throughput 4 queries/sec
2009 Sep 17 16:28:44 throughput 528 queries/sec
2009 Sep 17 16:28:47 throughput 1603 queries/sec
2009 Sep 17 16:28:50 throughput 1676 queries/sec
^C
Tracing ended at 2009 Sep 17 16:28:51
Average latency, all queries: 107 us
Latency distribution, all queries (us):
value ------------- Distribution ------------- count
16 | 0
32 |@@ 170
64 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 3728
128 |@@@@@ 533
256 | 26
512 | 18
1024 | 2
2048 | 1
4096 | 0
8192 | 1
16384 | 1
32768 | 0
Query cache statistics:
count hit: 6
count miss: 4474
avg latency miss: 107 (us)
avg latency hit: 407 (us)
Latency distribution, for query cache hit (us):
value ------------- Distribution ------------- count
64 | 0
128 |@@@@@@@@@@@@@ 2
256 |@@@@@@@ 1
512 |@@@@@@@@@@@@@@@@@@@@ 3
1024 | 0
Latency distribution, for query cache miss (us):
value ------------- Distribution ------------- count
16 | 0
32 |@@ 170
64 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 3728
128 |@@@@@ 531
256 | 25
512 | 15
1024 | 2
2048 | 1
4096 | 0
8192 | 1
16384 | 1
32768 | 0
Average latency when query WAS NOT pre-empted: 73 us
Average latency when query WAS pre-empted: 127 us
Pre-emptors:
[...]
mysql 6
Xorg 18
sched 25
firefox-bin 44
sysbench 3095
|
You can see that while the script is running (prior to pressing <Ctrl>-C), we get a throughput count every 3 seconds.
Then we get some totals, some averages, and even some distribution histograms, covering all queries, then with breakdowns on whether we used the query cache, and whether the thread executing the query was pre-empted.
This may be useful for determining things like:
Things have become easier since I first tried this, and had to use the PID provider to trace functions in the database server.
If you want to try my DTrace script, get it from here. NOTE: You will need a version of MySQL with DTrace probes for it to work.
Posted at 05:04PM Sep 17, 2009 by timc in MySQL | Comments[0]