Lorem ipsum dolor sit amet, consectetur adipiscing elit lobortis arcu enim urna adipiscing praesent velit viverra sit semper lorem eu cursus vel hendrerit elementum morbi curabitur etiam nibh justo, lorem aliquet donec sed sit mi dignissim at ante massa mattis.
Vitae congue eu consequat ac felis placerat vestibulum lectus mauris ultrices cursus sit amet dictum sit amet justo donec enim diam porttitor lacus luctus accumsan tortor posuere praesent tristique magna sit amet purus gravida quis blandit turpis.
At risus viverra adipiscing at in tellus integer feugiat nisl pretium fusce id velit ut tortor sagittis orci a scelerisque purus semper eget at lectus urna duis convallis. porta nibh venenatis cras sed felis eget neque laoreet suspendisse interdum consectetur libero id faucibus nisl donec pretium vulputate sapien nec sagittis aliquam nunc lobortis mattis aliquam faucibus purus in.
Nisi quis eleifend quam adipiscing vitae aliquet bibendum enim facilisis gravida neque. Velit euismod in pellentesque massa placerat volutpat lacus laoreet non curabitur gravida odio aenean sed adipiscing diam donec adipiscing tristique risus. amet est placerat in egestas erat imperdiet sed euismod nisi.
“Nisi quis eleifend quam adipiscing vitae aliquet bibendum enim facilisis gravida neque velit euismod in pellentesque massa placerat”
Eget lorem dolor sed viverra ipsum nunc aliquet bibendum felis donec et odio pellentesque diam volutpat commodo sed egestas aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod eu tincidunt tortor aliquam nulla facilisi aenean sed adipiscing diam donec adipiscing ut lectus arcu bibendum at varius vel pharetra nibh venenatis cras sed felis eget dolor cosnectur drolo.
This document serves as a starting point for MySQL performance tuning. This document is a combination of research and experience. When I started this document, I utilized a great Google video [1] as a reference for the document structure and many bullet items. I would suggest watching this video. I then filled in a few blanks, and combined a few other articles into this overview.You may also want to check out this good article from MySQL on performance tuning.. Now onto the show.. BenchmarkingAs with all improvement activities, it is better to start with a known problem area that is able to be defined, or an activity where improvement will provide maximum benefit (the 80/20 rule works everywhere). Nobody can really grasp an intangible goal like "we want to achieve excellence" [4].The following are decent guidelines to start with [1]:
In addition, the following benchmarking utilities may prove to be useful [5]:
Super Smack is a benchmarking, stress testing, and load generation tool for MySQL (and PostgreSQL). Super Smack was originally written by Sasha Pachev, and then hosted and maintained by Jeremy Zawodny.
SysBench is a modular, cross-platform and multi-threaded benchmark tool for evaluating OS parameters that are important for a system running a database under intensive load.
mybench is a simple benchmarking framework for MySQL, written in Perl. It consists of a module (MyBench.pm) and an example script (bench_example) that you should customize to suit your needs.
Profiling concepts
Sources of problem
Index Guidelines
System tuning
You may also be surprised at just what an effect optimizing a MyISAM table that has dynamic rows will do.. use the 'optimize table' SQL commandParameterstable_cache
Opening tables can be expensive. For example MyISAM tables mark MYI header to mark table as currently in use. You do not want this to happen so frequently and it is typically best to size your cache so it is large enough to keep most of your tables open. Use the tuning-primer.sh (http://www.day32.com/MySQL/) script to evaluate the current value.
query_cache_size
If your application is read intensive and you do not have application level caches this can be great help. Use the tuning-primer script to evaluate the size after you enable it. A good starting point may be 8M.The query_cache_size will be aligned to the nearest 1024 byte block. The value reported may therefore be different from the value that you set.If the query cache size is greater than 0, then query_cache_type variable influences how it works. This variable can be set to the following values:
query_cache_type
* A value of 0 or OFF prevents caching or retrieval of cached results.* A value of 1 or ON allows caching except of those statements that begin with SELECT SQL_NO_CACHE.* A value of 2 or DEMAND causes caching of only those statements that begin with SELECT SQL_CACHE.
thread_cache
mysql> SHOW STATUS LIKE 'Thread%';mysq> show status like 'Connections';Threads_created details the number of threads that have been created since the MySQL server started, and Connections is the total number of client connections to the MySQL server since startup. To work out the thread cache hit ratio, we use this calculation:100 - ((Threads_created / Connections) * 100)100 - ((10 / 78298) * 100) = ~99.987 Thread cache hit ratioThe ideal situation is to get Threads_created as close as possible to thread_cache_size - no new connections having to wait for new thread allocation - staying as close to around a 99% hit ratio as you can.
mysql> show status like 'Select_full_join';
The number of joins that do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.ratio of disk tmp tables vrs in memory tmp tables (tmp_table_size)
Handler_read_rnd
mysql> show status like 'Handler_read_rnd%';
The number of requests to read a row based on a fixed position. This value is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan entire tables or you have joins that don't use keys properly.
Handler_read_rnd_next
The number of requests to read the next row in the data file. This value is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.
key_buffer_size
Very important if you use MyISAM tables. key_buffer_size is important for MyISAM temporary tables performance to avoid OS writes, see this page for more detail. Again, evaluate the value using the tuning-primer.sh script.
innodb_buffer_pool_size
This is very important variable to tune if you’re using Innodb tables. Innodb tables are much more sensitive to buffer size compared to MyISAM.
innodb_additional_mem_pool_size
This one does not really affect performance too much, at least on OS with decent memory allocators. Still you might want to have it 20MB (sometimes larger) so you can see how much memory Innodb allocates for misc needs.
innodb_log_file_size
Very important for write intensive workloads especially for large data sets. Larger sizes offer better performance but increase recovery times so be careful. I normally use values 64M-512M depending on server size.
innodb_log_buffer_size
Default for this one is kind of OK for many workloads with medium write load and shorter transactions. If you have update activity spikes however or work with blobs a lot you might want to increase it. Do not set it too high however as it would be waste of memory - it is flushed every 1 sec anyway so you do not need space for more than 1 sec worth of updates. 8MB-16MB are typically enough. Smaller installations should use smaller values.
innodb_flush_logs_at_trx_commit
Default value of 1 will mean each update transaction commit (or each statement outside of transaction) will need to flush log to the disk which is rather expensive, especially if you do not have Battery backed up cache. Many applications, especially those moved from MyISAM tables are OK with value 2 which means do not flush log to the disk but only flush it to OS cache. The log is still flushed to the disk each second so you normally would not loose more than 1-2 sec worth of updates. Value 0 is a bit faster but is a bit less secure as you can lose transactions even in case MySQL Server crashes. Value 2 only cause data loss with full OS crash.
OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns).References
1. Performance Tuning Best Practices for MySQL, Google TechTalks April 28, 2006. http://video.google.com/videoplay?docid=2524524540025172110
2. [HowTo] Optimising MYSQL, 01-20-2005, 03:59 AM. http://interworx.info/forums/showthread.php?p=2346
3. Kaiser's 7-Step Benchmarking Process. http://www.kaiserassociates.com/about/bench_7step.html
4. How do you identify a suitable activity to benchmark? http://www.quality.co.uk/benchadv.htm
5. MySQL Benchmarking. http://mysqldatabaseadministration.blogspot.com/2006/08/mysql-benchmarking-1.html