MySQL status and variables
Execute the following command on the database instance and provide the output:
mysql -u $wfdb_user -p -e "show variables" > /tmp/mysql_valiables.tsvVariables Description table_cachekey_buffer_size
If
Opened_tablesis high, then thetable_cachevariable is probably too low.table_cache 64 Open_tables 64 Opened_tables 544468This is the first serious problem. The
table_cacheis the number of open tables for all threads. Being multi-threaded, MySQL can be running many queries on the table at a time, and each of these will open a table. Therefore, even though you have only a few tables, you will need many moreopen_tables.The
Opened_tablesvalue is high and shows the number of cache misses. Getting thetable_cachesize correct is one of the two best things you can do to improve performance.If
Key_readsis big, then yourkey_buffer_sizevariable is probably too small. The cache hit rate can be calculated based on theKey_reads/Key_read_requestsratio.key_buffer_size 16M Key_read_requests 2973620399 Key_reads 8490571(cache hit rate = 0.0028)The key_buffer_size affects the size of the index buffers and the speed of the index handling, particularly reading. The MySQL manual (and other sources) say that the
Key_reads/Key_read_requestratio should normally be < 0.01. This is the other most important thing to get correct. Here, the value seems to be correct (< 0.01).Also, check
key_write_requestsandkey_writes. Thekey_writes/key_writes_requestshould normally be < 1 (near 0.5 seems to be fine).Here is a very interesting web pointer : table_cache and key_buffer_size.
max_connectionstable_cachewait_timeoutthread_cache_size
Generally, you have a lot of MySQL processes that are sleeping because
wait_timeoutis not set low. So, make sure that thewait_timeoutis set to a very low value, for instance, 15 seconds. That means MySQL would close any connection that was idle for more than 15 seconds.The problem is you also have to increment your
So, the solution is to usemax_connection(for instance, to 300) to be sure there is not a lot of idle clients holding connections and blocking out new clients from connecting and getting real work done. Thepbmis that the box has to create new threads (MySQL is a multi-threaded server) at a very high rate. That can sucks up a measurable amount of CPU time.Thread_cache. When a client disconnects, the client's threads are put in the cache if there aren't more thanthread_cache_sizethreads from before. All new threads are first taken from the cache, and only when the cache is empty, a new thread is created. This variable can be increased to improve performance if you have a lot of new connections. (Normally this doesn't give a notable performance improvement if you have a good thread implementation.) By examining the difference between theConnectionsandThreads_created, you can see how efficient the current thread cache is for you.If
Threads_createdis high, you may want to increase thethread_cache_sizevariable. The cache hit rate can be calculated withThreads_created/Connections.thread_cache_size 0 Threads_created 150022 Connections 150023.This is the second problem that should be fixed. A cache size of zero is the default for
my-medium.cnf, but the recommended size inmy-large.cnfis 8.You may try this formula :
table_cache=opened table/max_used_connection.key_buffer_sizequery_cache_sizetmp_table_size
If
Created_tmp_disk_tablesis high, you may want to increase thetmp_table_sizevariable to get the temporary tables memory-based instead of disk based.tmp_table_size 32M Created_tmp_disk_tables 3227 Created_tmp_tables 159832 Created_tmp_files 4444Created_tmp_disk_tablesstands for the number of implicit temporary tables on the disk created while executing statements, andCreated_tmp_tablesis memory-based. Obviously, it is bad if you have to go to the disk instead of memory. About 2% of temp tables go to the disk, which doesn't seem too bad, but increasing thetmp_table_sizeprobably couldn't hurt either.If
Handler_read_rndis high, you probably have a lot of queries that require MySQL to scan whole tables or you have joins that don't use keys properly.Handler_read_rnd 27712353 Handler_read_rnd_next 283536234.These values are high, which you could probably stand to improve the indexes and queries.
If you change
tmp_table_size, don't forget to carry about themax_heap_table_sizevalue, too.Execute the following command on the database instance and provide the output:
mysql -u $wfdb_user -p -e "show engine innodb status" > /tmp/innodb_status.tsv