Perf Tuning Short
Upcoming SlideShare
Loading in...5
×
 

Perf Tuning Short

on

  • 4,846 views

a slightly shorter and easier to follow presentation on MySQL performance tuning

a slightly shorter and easier to follow presentation on MySQL performance tuning

Statistics

Views

Total Views
4,846
Views on SlideShare
4,839
Embed Views
7

Actions

Likes
22
Downloads
444
Comments
1

1 Embed 7

http://www.slideshare.net 7

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Queries Systems - soft skill - like design <br /> * Slow query log * OS - is such a thing as over optimizing <br /> - time (long_query_time) * FileSystem <br /> - not use indexes * Network <br /> * EXPLAIN * Storage <br /> * Indexes strategies <br /> * Database design
  • Queries Systems - soft skill - like design <br /> * Slow query log * OS - is such a thing as over optimizing <br /> - time (long_query_time) * FileSystem <br /> - not use indexes * Network <br /> * EXPLAIN * Storage <br /> * Indexes strategies <br /> * Database design
  • Queries Systems - soft skill - like design <br /> * Slow query log * OS - is such a thing as over optimizing <br /> - time (long_query_time) * FileSystem <br /> - not use indexes * Network <br /> * EXPLAIN * Storage <br /> * Indexes strategies <br /> * Database design
  • Queries Systems - soft skill - like design <br /> * Slow query log * OS - is such a thing as over optimizing <br /> - time (long_query_time) * FileSystem <br /> - not use indexes * Network <br /> * EXPLAIN * Storage <br /> * Indexes strategies <br /> * Database design
  • Queries Systems - soft skill - like design <br /> * Slow query log * OS - is such a thing as over optimizing <br /> - time (long_query_time) * FileSystem <br /> - not use indexes * Network <br /> * EXPLAIN * Storage <br /> * Indexes strategies <br /> * Database design
  • Global - Once - key buffer, InnoDB buffer pool size <br /> As needed - table and thread cache
  • Global - Once - key buffer, InnoDB buffer pool size <br /> As needed - table and thread cache
  • Global - Once - key buffer, InnoDB buffer pool size <br /> As needed - table and thread cache
  • Global - Once - key buffer, InnoDB buffer pool size <br /> As needed - table and thread cache
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • * Where do I look for information <br /> - Variables - LOTS of information.
  • example of finding the delta
  • example of finding the delta
  • example of finding the delta
  • example of finding the delta
  • example of finding the delta
  • example of finding the delta
  • Innodb_buffer_pool_wait_free <br /> <br /> Normally, writes to the InnoDB buffer pool happen in the background. However, if it is necessary to read or create a page and no clean pages are available, it is also necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size has been set properly, this value should be small. Added in MySQL 5.0.2.
  • Innodb_buffer_pool_wait_free <br /> <br /> Normally, writes to the InnoDB buffer pool happen in the background. However, if it is necessary to read or create a page and no clean pages are available, it is also necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size has been set properly, this value should be small. Added in MySQL 5.0.2.
  • Innodb_buffer_pool_wait_free <br /> <br /> Normally, writes to the InnoDB buffer pool happen in the background. However, if it is necessary to read or create a page and no clean pages are available, it is also necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size has been set properly, this value should be small. Added in MySQL 5.0.2.
  • Innodb_buffer_pool_wait_free <br /> <br /> Normally, writes to the InnoDB buffer pool happen in the background. However, if it is necessary to read or create a page and no clean pages are available, it is also necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size has been set properly, this value should be small. Added in MySQL 5.0.2.
  • Innodb_buffer_pool_wait_free <br /> <br /> Normally, writes to the InnoDB buffer pool happen in the background. However, if it is necessary to read or create a page and no clean pages are available, it is also necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size has been set properly, this value should be small. Added in MySQL 5.0.2.
  • Innodb_buffer_pool_wait_free <br /> <br /> Normally, writes to the InnoDB buffer pool happen in the background. However, if it is necessary to read or create a page and no clean pages are available, it is also necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size has been set properly, this value should be small. Added in MySQL 5.0.2.
  • * Ask if people understand how the query cache works and if someone is not familiar with it - give a basic explanation. <br /> <br /> * Fragmentation - as Qcache_free_blocks approaches Qcache_total_blocks/2 the more severely fragmented the query cache is. <br /> <br /> Manual page fragmentation blurb - http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html <br /> <br /> &#x201C; When a query is to be cached, its result (the data sent to the client) is stored in the query cache during result retrieval. Therefore the data usually is not handled in one big chunk. The query cache allocates blocks for storing this data on demand, so when one block is filled, a new block is allocated. Because memory allocation operation is costly (timewise), the query cache allocates blocks with a minimum size given by the query_cache_min_res_unit system variable. When a query is executed, the last result block is trimmed to the actual data size so that unused memory is freed. Depending on the types of queries your server executes, you might find it helpful to tune the value of query_cache_min_res_unit: <br /> <br /> * The default value of query_cache_min_res_unit is 4KB. This should be adequate for most cases. <br /> * If you have a lot of queries with small results, the default block size may lead to memory fragmentation, as indicated by a large number of free blocks. Fragmentation can force the query cache to prune (delete) queries from the cache due to lack of memory. In this case, you should decrease the value of query_cache_min_res_unit. The number of free blocks and queries removed due to pruning are given by the values of the Qcache_free_blocks and Qcache_lowmem_prunes status variables. <br /> * If most of your queries have large results (check the Qcache_total_blocks and Qcache_queries_in_cache status variables), you can increase performance by increasing query_cache_min_res_unit. However, be careful to not make it too large (see the previous item).&#x201D;
  • * Ask if people understand how the query cache works and if someone is not familiar with it - give a basic explanation. <br /> <br /> * Fragmentation - as Qcache_free_blocks approaches Qcache_total_blocks/2 the more severely fragmented the query cache is. <br /> <br /> Manual page fragmentation blurb - http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html <br /> <br /> &#x201C; When a query is to be cached, its result (the data sent to the client) is stored in the query cache during result retrieval. Therefore the data usually is not handled in one big chunk. The query cache allocates blocks for storing this data on demand, so when one block is filled, a new block is allocated. Because memory allocation operation is costly (timewise), the query cache allocates blocks with a minimum size given by the query_cache_min_res_unit system variable. When a query is executed, the last result block is trimmed to the actual data size so that unused memory is freed. Depending on the types of queries your server executes, you might find it helpful to tune the value of query_cache_min_res_unit: <br /> <br /> * The default value of query_cache_min_res_unit is 4KB. This should be adequate for most cases. <br /> * If you have a lot of queries with small results, the default block size may lead to memory fragmentation, as indicated by a large number of free blocks. Fragmentation can force the query cache to prune (delete) queries from the cache due to lack of memory. In this case, you should decrease the value of query_cache_min_res_unit. The number of free blocks and queries removed due to pruning are given by the values of the Qcache_free_blocks and Qcache_lowmem_prunes status variables. <br /> * If most of your queries have large results (check the Qcache_total_blocks and Qcache_queries_in_cache status variables), you can increase performance by increasing query_cache_min_res_unit. However, be careful to not make it too large (see the previous item).&#x201D;
  • * Ask if people understand how the query cache works and if someone is not familiar with it - give a basic explanation. <br /> <br /> * Fragmentation - as Qcache_free_blocks approaches Qcache_total_blocks/2 the more severely fragmented the query cache is. <br /> <br /> Manual page fragmentation blurb - http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html <br /> <br /> &#x201C; When a query is to be cached, its result (the data sent to the client) is stored in the query cache during result retrieval. Therefore the data usually is not handled in one big chunk. The query cache allocates blocks for storing this data on demand, so when one block is filled, a new block is allocated. Because memory allocation operation is costly (timewise), the query cache allocates blocks with a minimum size given by the query_cache_min_res_unit system variable. When a query is executed, the last result block is trimmed to the actual data size so that unused memory is freed. Depending on the types of queries your server executes, you might find it helpful to tune the value of query_cache_min_res_unit: <br /> <br /> * The default value of query_cache_min_res_unit is 4KB. This should be adequate for most cases. <br /> * If you have a lot of queries with small results, the default block size may lead to memory fragmentation, as indicated by a large number of free blocks. Fragmentation can force the query cache to prune (delete) queries from the cache due to lack of memory. In this case, you should decrease the value of query_cache_min_res_unit. The number of free blocks and queries removed due to pruning are given by the values of the Qcache_free_blocks and Qcache_lowmem_prunes status variables. <br /> * If most of your queries have large results (check the Qcache_total_blocks and Qcache_queries_in_cache status variables), you can increase performance by increasing query_cache_min_res_unit. However, be careful to not make it too large (see the previous item).&#x201D;
  • * Ask if people understand how the query cache works and if someone is not familiar with it - give a basic explanation. <br /> <br /> * Fragmentation - as Qcache_free_blocks approaches Qcache_total_blocks/2 the more severely fragmented the query cache is. <br /> <br /> Manual page fragmentation blurb - http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html <br /> <br /> &#x201C; When a query is to be cached, its result (the data sent to the client) is stored in the query cache during result retrieval. Therefore the data usually is not handled in one big chunk. The query cache allocates blocks for storing this data on demand, so when one block is filled, a new block is allocated. Because memory allocation operation is costly (timewise), the query cache allocates blocks with a minimum size given by the query_cache_min_res_unit system variable. When a query is executed, the last result block is trimmed to the actual data size so that unused memory is freed. Depending on the types of queries your server executes, you might find it helpful to tune the value of query_cache_min_res_unit: <br /> <br /> * The default value of query_cache_min_res_unit is 4KB. This should be adequate for most cases. <br /> * If you have a lot of queries with small results, the default block size may lead to memory fragmentation, as indicated by a large number of free blocks. Fragmentation can force the query cache to prune (delete) queries from the cache due to lack of memory. In this case, you should decrease the value of query_cache_min_res_unit. The number of free blocks and queries removed due to pruning are given by the values of the Qcache_free_blocks and Qcache_lowmem_prunes status variables. <br /> * If most of your queries have large results (check the Qcache_total_blocks and Qcache_queries_in_cache status variables), you can increase performance by increasing query_cache_min_res_unit. However, be careful to not make it too large (see the previous item).&#x201D;
  • * Ask if people understand how the query cache works and if someone is not familiar with it - give a basic explanation. <br /> <br /> * Fragmentation - as Qcache_free_blocks approaches Qcache_total_blocks/2 the more severely fragmented the query cache is. <br /> <br /> Manual page fragmentation blurb - http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html <br /> <br /> &#x201C; When a query is to be cached, its result (the data sent to the client) is stored in the query cache during result retrieval. Therefore the data usually is not handled in one big chunk. The query cache allocates blocks for storing this data on demand, so when one block is filled, a new block is allocated. Because memory allocation operation is costly (timewise), the query cache allocates blocks with a minimum size given by the query_cache_min_res_unit system variable. When a query is executed, the last result block is trimmed to the actual data size so that unused memory is freed. Depending on the types of queries your server executes, you might find it helpful to tune the value of query_cache_min_res_unit: <br /> <br /> * The default value of query_cache_min_res_unit is 4KB. This should be adequate for most cases. <br /> * If you have a lot of queries with small results, the default block size may lead to memory fragmentation, as indicated by a large number of free blocks. Fragmentation can force the query cache to prune (delete) queries from the cache due to lack of memory. In this case, you should decrease the value of query_cache_min_res_unit. The number of free blocks and queries removed due to pruning are given by the values of the Qcache_free_blocks and Qcache_lowmem_prunes status variables. <br /> * If most of your queries have large results (check the Qcache_total_blocks and Qcache_queries_in_cache status variables), you can increase performance by increasing query_cache_min_res_unit. However, be careful to not make it too large (see the previous item).&#x201D;
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.
  • * If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.

Perf Tuning Short Perf Tuning Short Presentation Transcript

  • MySQL Performance Tuning 101 Ligaya Turmelle MySQL Support Engineer ligaya@mysql.com 1
  • MySQL world's most popular open source database software a key part of LAMP (Linux, Apache, MySQL, PHP / Perl / Python) Site: http://www.mysql.com/ Download: http://dev.mysql.com/downloads/ Online Manual: http://dev.mysql.com/doc/ refman/5.1/en/index.html 2
  • Before you start 3
  • Before you start Single greatest gain can be received by optimizing the queries. 3
  • Before you start Single greatest gain can be received by optimizing the queries. Optimize the underlying system 3
  • Before you start Single greatest gain can be received by optimizing the queries. Optimize the underlying system Understand there are no hard/fast/exact answers for values. 3
  • Before you start Single greatest gain can be received by optimizing the queries. Optimize the underlying system Understand there are no hard/fast/exact answers for values. Change one value at a time and benchmark to look for improvement 3
  • Before you start Single greatest gain can be received by optimizing the queries. Optimize the underlying system Understand there are no hard/fast/exact answers for values. Change one value at a time and benchmark to look for improvement Better to under allocate then over allocate values 3
  • How we use memory 4
  • How we use memory 2 Ways - Global and per Connection 4
  • How we use memory 2 Ways - Global and per Connection Global - Most allocated once when the server starts - can be large 4
  • How we use memory 2 Ways - Global and per Connection Global - Most allocated once when the server starts - can be large Per Connection - for each connection as needed - should be small 4
  • How we use memory 2 Ways - Global and per Connection Global - Most allocated once when the server starts - can be large Per Connection - for each connection as needed - should be small Global memory + (max_connections * session buffers) 4
  • Information 5
  • Information Current Settings 5
  • Information Current Settings mysql> SHOW GLOBAL VARIABLES; 5
  • Information Current Settings mysql> SHOW GLOBAL VARIABLES; Shows the majority of the settings +----------------------------------------------------------------------------------------------------------------------------+ |Variable_name | Value +-----------------------------------------------------------------------------------------------+ | auto_increment_increment | 1 | auto_increment_offset | 1 | automatic_sp_privileges | ON | back_log | 50 | basedir | /Users/ligaya/mysql_installs/mysql-enterprise-gpl-5.0.50sp1-osx10.5-x86/ | binlog_cache_size | 32768 | bulk_insert_buffer_size | 8388608 | character_set_client | latin1 5
  • Information Current Settings mysql> SHOW GLOBAL VARIABLES; Shows the majority of the settings +----------------------------------------------------------------------------------------------------------------------------+ |Variable_name | Value +-----------------------------------------------------------------------------------------------+ | auto_increment_increment | 1 | auto_increment_offset | 1 | automatic_sp_privileges | ON | back_log | 50 | basedir | /Users/ligaya/mysql_installs/mysql-enterprise-gpl-5.0.50sp1-osx10.5-x86/ | binlog_cache_size | 32768 | bulk_insert_buffer_size | 8388608 | character_set_client | latin1 my.cnf/my.ini 5
  • Other Information 6
  • Other Information How much RAM on the machine? 6
  • Other Information How much RAM on the machine? Is the machine dedicated to MySQL? 6
  • Other Information How much RAM on the machine? Is the machine dedicated to MySQL? 64 bit processor? 6
  • Other Information How much RAM on the machine? Is the machine dedicated to MySQL? 64 bit processor? 64 bit MySQL server binary? 6
  • Server Status 7
  • Server Status mysql> SHOW GLOBAL STATUS; 7
  • Server Status mysql> SHOW GLOBAL STATUS; has various counters 7
  • Server Status mysql> SHOW GLOBAL STATUS; has various counters gives you a feel of what the server is actually doing - not what you *think* it is doing 7
  • Server Status mysql> SHOW GLOBAL STATUS; has various counters gives you a feel of what the server is actually doing - not what you *think* it is doing issue command twice with time between to get the changes of values over time 7
  • Example Status +-----------------------------------+-------------+ | Variable_name | Value | +-----------------------------------+-------------+ | Aborted_clients | 6618 | | Aborted_connects | 3957 | | Binlog_cache_disk_use | 0 | | Binlog_cache_use | 0 | | Bytes_received | 1320510015 | | Bytes_sent | 2978960756 | | Com_admin_commands | 32124 | .... | Threads_cached | 0 | | Threads_connected | 1 | | Threads_created | 316771 | | Threads_running | 1 | | Uptime | 1722523 | | Uptime_since_flush_status | 1722523 | +-----------------------------------+-------------+ 8
  • Finding the delta 9
  • Finding the delta Uptime - part of status information and is given in seconds 9
  • Finding the delta Uptime - part of status information and is given in seconds Ex: 1086122 seconds = ~19.9 days = 478.5 hrs 9
  • Finding the delta Uptime - part of status information and is given in seconds Ex: 1086122 seconds = ~19.9 days = 478.5 hrs helps you calculate the values in a given time frame (high load, average load). 9
  • Finding the delta Uptime - part of status information and is given in seconds Ex: 1086122 seconds = ~19.9 days = 478.5 hrs helps you calculate the values in a given time frame (high load, average load). Ex: (bytes received[2] – bytes received[1])/ (Uptime[2] – Uptime[1]) 9
  • Finding the delta Uptime - part of status information and is given in seconds Ex: 1086122 seconds = ~19.9 days = 478.5 hrs helps you calculate the values in a given time frame (high load, average load). Ex: (bytes received[2] – bytes received[1])/ (Uptime[2] – Uptime[1]) (1320582719 - 1320510015 )/(1722729 - 1722523) = 9
  • Finding the delta Uptime - part of status information and is given in seconds Ex: 1086122 seconds = ~19.9 days = 478.5 hrs helps you calculate the values in a given time frame (high load, average load). Ex: (bytes received[2] – bytes received[1])/ (Uptime[2] – Uptime[1]) (1320582719 - 1320510015 )/(1722729 - 1722523) = 72704 bytes/ 206 sec = 352.9 bytes/sec 9
  • What is the server doing? 10
  • What is the server doing? Com_XXXX 10
  • What is the server doing? Com_XXXX Counter of the number of times XXXX has been executed 10
  • What is the server doing? Com_XXXX Counter of the number of times XXXX has been executed One status variable for each statement | Com_delete | 78813 | | Com_insert | 100357 | | Com_replace | 3130 | | Com_select | 984292 | | Com_show_tables | 459 | | Com_show_triggers | 898 | | Com_create_table | 1349 | | Com_update | 285105 | 10
  • What is the server doing? Com_XXXX Counter of the number of times XXXX has been executed One status variable for each statement | Com_delete | 78813 | | Com_insert | 100357 | | Com_replace | 3130 | | Com_select | 984292 | | Com_show_tables | 459 | | Com_show_triggers | 898 | | Com_create_table | 1349 | | Com_update | 285105 | Used with Uptime to find insert/sec or delete/sec 10
  • What is the server doing (con’t)? 11
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) 11
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_blocks_unused: 11
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_blocks_unused: number of unused blocks 11
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_blocks_unused: number of unused blocks key_buffer_size - Key_blocks_unused = amount in use 11
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_blocks_unused: number of unused blocks key_buffer_size - Key_blocks_unused = amount in use Key_blocks_used: 11
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_blocks_unused: number of unused blocks key_buffer_size - Key_blocks_unused = amount in use Key_blocks_used: a high-water mark that indicates the maximum number of blocks that have ever been in use at one time. 11
  • What is the server doing (con’t)? 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit Key_reads: 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit Key_reads: number of physical reads of a key block from disk. 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit Key_reads: number of physical reads of a key block from disk. a cache miss 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit Key_reads: number of physical reads of a key block from disk. a cache miss If large, key_buffer_size is probably too small. 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit Key_reads: number of physical reads of a key block from disk. a cache miss If large, key_buffer_size is probably too small. cache miss rate = Key_reads/ Key_read_requests. 12
  • What is the server doing (con’t)? Information on your key buffer (MyISAM) Key_read_requests: number of requests to read a key block from the cache. a cache hit Key_reads: number of physical reads of a key block from disk. a cache miss If large, key_buffer_size is probably too small. cache miss rate = Key_reads/ Key_read_requests. Key buffer efficiency: 1 – cache miss rate 12
  • key_buffer_size 13
  • key_buffer_size Global variable 13
  • key_buffer_size Global variable the buffer used for MyISAM *index blocks*. 13
  • key_buffer_size Global variable the buffer used for MyISAM *index blocks*. Index blocks are buffered and shared by all threads. 13
  • key_buffer_size Global variable the buffer used for MyISAM *index blocks*. Index blocks are buffered and shared by all threads. The maximum allowable setting 4GB on 32-bit platforms. after 5.0.52 on 64-bit systems - 4GB+ 13
  • key_buffer_size Global variable the buffer used for MyISAM *index blocks*. Index blocks are buffered and shared by all threads. The maximum allowable setting 4GB on 32-bit platforms. after 5.0.52 on 64-bit systems - 4GB+ dedicated machine -25% of total memory is quite common. 13
  • key_buffer_size Global variable the buffer used for MyISAM *index blocks*. Index blocks are buffered and shared by all threads. The maximum allowable setting 4GB on 32-bit platforms. after 5.0.52 on 64-bit systems - 4GB+ dedicated machine -25% of total memory is quite common. uses the OS file cache to cache the files 13
  • key_buffer_size Global variable the buffer used for MyISAM *index blocks*. Index blocks are buffered and shared by all threads. The maximum allowable setting 4GB on 32-bit platforms. after 5.0.52 on 64-bit systems - 4GB+ dedicated machine -25% of total memory is quite common. uses the OS file cache to cache the files too high == paging === bad 13
  • What is the server doing (con’t)? 14
  • What is the server doing (con’t)? Table_locks_immediate: # of table locks granted immediately to MyISAM tables. 14
  • What is the server doing (con’t)? Table_locks_immediate: # of table locks granted immediately to MyISAM tables. Table_locks_waited: # of times we had to wait to get a table lock for MyISAM tables 14
  • What is the server doing (con’t)? Table_locks_immediate: # of table locks granted immediately to MyISAM tables. Table_locks_waited: # of times we had to wait to get a table lock for MyISAM tables If the value is high - you may want to consider changing storage engines. 14
  • What is the server doing (con’t)? 15
  • What is the server doing (con’t)? Innodb_* 15
  • What is the server doing (con’t)? Innodb_* Has various information about the InnoDB tablespace 15
  • What is the server doing (con’t)? Innodb_* Has various information about the InnoDB tablespace Innodb_buffer_pool_pages_data: number of pages containing data (dirty or clean). 15
  • What is the server doing (con’t)? Innodb_* Has various information about the InnoDB tablespace Innodb_buffer_pool_pages_data: number of pages containing data (dirty or clean). Innodb_buffer_pool_pages_free: number of free pages. 15
  • What is the server doing (con’t)? Innodb_* Has various information about the InnoDB tablespace Innodb_buffer_pool_pages_data: number of pages containing data (dirty or clean). Innodb_buffer_pool_pages_free: number of free pages. Innodb_buffer_pool_pages_total: The total size of the buffer pool, in pages. 15
  • What is the server doing (con’t)? Innodb_* Has various information about the InnoDB tablespace Innodb_buffer_pool_pages_data: number of pages containing data (dirty or clean). Innodb_buffer_pool_pages_free: number of free pages. Innodb_buffer_pool_pages_total: The total size of the buffer pool, in pages. Innodb_buffer_pool_wait_free: counts instances of waiting for pages to be flushed. Should be small value. 15
  • innodb_buffer_pool_size 16
  • innodb_buffer_pool_size Global variable 16
  • innodb_buffer_pool_size Global variable size in bytes 16
  • innodb_buffer_pool_size Global variable size in bytes used to cache data and indexes of tables. (Clustered indexes - remember) 16
  • innodb_buffer_pool_size Global variable size in bytes used to cache data and indexes of tables. (Clustered indexes - remember) The larger you set this value, the less disk I/O is needed to access data in tables. 16
  • innodb_buffer_pool_size Global variable size in bytes used to cache data and indexes of tables. (Clustered indexes - remember) The larger you set this value, the less disk I/O is needed to access data in tables. On a dedicated database server - up to 80% of the machine physical memory size. 16
  • innodb_buffer_pool_size Global variable size in bytes used to cache data and indexes of tables. (Clustered indexes - remember) The larger you set this value, the less disk I/O is needed to access data in tables. On a dedicated database server - up to 80% of the machine physical memory size. Buffers everything itself. 16
  • innodb_buffer_pool_size Global variable size in bytes used to cache data and indexes of tables. (Clustered indexes - remember) The larger you set this value, the less disk I/O is needed to access data in tables. On a dedicated database server - up to 80% of the machine physical memory size. Buffers everything itself. do not set it too large - might cause paging in the operating system. 16
  • innodb_log_file_size 17
  • innodb_log_file_size Global variable 17
  • innodb_log_file_size Global variable size in bytes of *each* log file in a log group. 17
  • innodb_log_file_size Global variable size in bytes of *each* log file in a log group. Balancing act larger the value, the less checkpoint flush activity - less disk I/O larger the log files - longer the crash recovery time 17
  • innodb_log_file_size Global variable size in bytes of *each* log file in a log group. Balancing act larger the value, the less checkpoint flush activity - less disk I/O larger the log files - longer the crash recovery time Sensible values range: 1MB to 1/N-th of the size of the buffer pool N is the number of log files in the group (innodb_log_files_in_group - usually 2). 17
  • innodb_log_file_size Global variable size in bytes of *each* log file in a log group. Balancing act larger the value, the less checkpoint flush activity - less disk I/O larger the log files - longer the crash recovery time Sensible values range: 1MB to 1/N-th of the size of the buffer pool N is the number of log files in the group (innodb_log_files_in_group - usually 2). combined size of log files must be less than 4GB 17
  • What is the server doing (con’t)? 18
  • What is the server doing (con’t)? Query Cache Information 18
  • What is the server doing (con’t)? Query Cache Information Qcache_total_blocks: total number of blocks in the query cache. 18
  • What is the server doing (con’t)? Query Cache Information Qcache_total_blocks: total number of blocks in the query cache. Qcache_free_blocks: number of free memory blocks. Can indicate a problem with fragmentation. 18
  • What is the server doing (con’t)? Query Cache Information Qcache_total_blocks: total number of blocks in the query cache. Qcache_free_blocks: number of free memory blocks. Can indicate a problem with fragmentation. Qcache_hits: number of query cache hits. 18
  • What is the server doing (con’t)? Query Cache Information Qcache_total_blocks: total number of blocks in the query cache. Qcache_free_blocks: number of free memory blocks. Can indicate a problem with fragmentation. Qcache_hits: number of query cache hits. Qcache_inserts: number of queries added to the query cache. 18
  • What is the server doing (con’t) Query Cache (con’t) Qcache_not_cached: number of non-cached queries (not cacheable, or not cached due to the query_cache_type setting). Qcache_queries_in_cache: number of queries registered in the query cache. Qcache_lowmem_prunes: number of queries that were deleted from the query cache because of low memory. 19
  • What is the server doing (con’t)? 20
  • What is the server doing (con’t)? Turning the Query cache counters into information 20
  • What is the server doing (con’t)? Turning the Query cache counters into information One quick and easy way to determine if you benefit from using the query cache – Query Cache Hit Rate QC Hit Rate = Qcache_hits/(Qcache_hits +Com_select) 20
  • What is the server doing (con’t)? Turning the Query cache counters into information One quick and easy way to determine if you benefit from using the query cache – Query Cache Hit Rate QC Hit Rate = Qcache_hits/(Qcache_hits +Com_select) Also check to see how often you are invalidating the queries in the cache. Qcache_inserts vs Com_select Want Qcache_inserts << Com_select - bigger the difference, the better 20
  • What is the server doing (con’t)? Turning the Query cache counters into information One quick and easy way to determine if you benefit from using the query cache – Query Cache Hit Rate QC Hit Rate = Qcache_hits/(Qcache_hits +Com_select) Also check to see how often you are invalidating the queries in the cache. Qcache_inserts vs Com_select Want Qcache_inserts << Com_select - bigger the difference, the better Note: keep in mind warming up the cache 20
  • query_cache_size 21
  • query_cache_size Global variable 21
  • query_cache_size Global variable The amount of memory allocated for caching query results. 21
  • query_cache_size Global variable The amount of memory allocated for caching query results. default value is 0, which disables the query cache. 21
  • query_cache_size Global variable The amount of memory allocated for caching query results. default value is 0, which disables the query cache. allowable values are multiples of 1024; other values are rounded down to the nearest multiple. 21
  • query_cache_type 22
  • query_cache_type Global variable but can be set at the session level 22
  • query_cache_type Global variable but can be set at the session level 3 options 22
  • query_cache_type Global variable but can be set at the session level 3 options 0 (Off) - Don't cache results in or retrieve results from the query cache. 22
  • query_cache_type Global variable but can be set at the session level 3 options 0 (Off) - Don't cache results in or retrieve results from the query cache. 1 (On) - Cache all cacheable query results except - SELECT SQL_NO_CACHE. Default 22
  • query_cache_type Global variable but can be set at the session level 3 options 0 (Off) - Don't cache results in or retrieve results from the query cache. 1 (On) - Cache all cacheable query results except - SELECT SQL_NO_CACHE. Default 2 (Demand) - Cache results only for cacheable queries that begin with SELECT SQL_CACHE 22
  • query_cache_type Global variable but can be set at the session level 3 options 0 (Off) - Don't cache results in or retrieve results from the query cache. 1 (On) - Cache all cacheable query results except - SELECT SQL_NO_CACHE. Default 2 (Demand) - Cache results only for cacheable queries that begin with SELECT SQL_CACHE Note that the query_cache_size of memory is allocated even if query_cache_type is set to 0. 22
  • What is the server doing (con’t)? 23
  • What is the server doing (con’t)? Threads 23
  • What is the server doing (con’t)? Threads Threads_cached: # of threads in the thread cache. 23
  • What is the server doing (con’t)? Threads Threads_cached: # of threads in the thread cache. Threads_connected: # of currently open connections. 23
  • What is the server doing (con’t)? Threads Threads_cached: # of threads in the thread cache. Threads_connected: # of currently open connections. Threads_created: # of threads created to handle connections. 23
  • What is the server doing (con’t)? Threads Threads_cached: # of threads in the thread cache. Threads_connected: # of currently open connections. Threads_created: # of threads created to handle connections. If Threads_created is “big”, you may want to increase the thread_cache_size value. 23
  • What is the server doing (con’t)? Threads Threads_cached: # of threads in the thread cache. Threads_connected: # of currently open connections. Threads_created: # of threads created to handle connections. If Threads_created is “big”, you may want to increase the thread_cache_size value. thread cache miss rate = Threads_created/ Connections. 23
  • thread_cache_size 24
  • thread_cache_size Global variable but it grows as needed. 24
  • thread_cache_size Global variable but it grows as needed. threads to be cached for reuse. 24
  • thread_cache_size Global variable but it grows as needed. threads to be cached for reuse. When a client disconnects, client's threads are put in the cache until it is full. 24
  • thread_cache_size Global variable but it grows as needed. threads to be cached for reuse. When a client disconnects, client's threads are put in the cache until it is full. Requests for threads are satisfied by reusing threads taken from the cache. Only when the cache is empty is a new thread created. 24
  • thread_cache_size Global variable but it grows as needed. threads to be cached for reuse. When a client disconnects, client's threads are put in the cache until it is full. Requests for threads are satisfied by reusing threads taken from the cache. Only when the cache is empty is a new thread created. increase to improve performance if you have a lot of new connections. 24
  • thread_cache_size Global variable but it grows as needed. threads to be cached for reuse. When a client disconnects, client's threads are put in the cache until it is full. Requests for threads are satisfied by reusing threads taken from the cache. Only when the cache is empty is a new thread created. increase to improve performance if you have a lot of new connections. May not provide a notable performance improvement if you have a good thread implementation. 24
  • thread_cache_size Global variable but it grows as needed. threads to be cached for reuse. When a client disconnects, client's threads are put in the cache until it is full. Requests for threads are satisfied by reusing threads taken from the cache. Only when the cache is empty is a new thread created. increase to improve performance if you have a lot of new connections. May not provide a notable performance improvement if you have a good thread implementation. (100-((Threads_created / Connections)*100) = thread cache efficiency 24
  • What is the server doing (con’t)? 25
  • What is the server doing (con’t)? General Information counters of importance 25
  • What is the server doing (con’t)? General Information counters of importance Connections: # of connection attempts (successful or not) 25
  • What is the server doing (con’t)? General Information counters of importance Connections: # of connection attempts (successful or not) Queries: # of statements executed including statements executed within stored programs. added 5.0.76. 25
  • What is the server doing (con’t)? General Information counters of importance Connections: # of connection attempts (successful or not) Queries: # of statements executed including statements executed within stored programs. added 5.0.76. Questions: # of statements sent to the server by clients and executed by the server. As of 5.0.72 25
  • What is the server doing (con’t)? General Information counters of importance Connections: # of connection attempts (successful or not) Queries: # of statements executed including statements executed within stored programs. added 5.0.76. Questions: # of statements sent to the server by clients and executed by the server. As of 5.0.72 Slow_queries: # of queries that have taken more than long_query_time seconds. 25
  • What is the server doing (con’t)? General Information counters of importance Connections: # of connection attempts (successful or not) Queries: # of statements executed including statements executed within stored programs. added 5.0.76. Questions: # of statements sent to the server by clients and executed by the server. As of 5.0.72 Slow_queries: # of queries that have taken more than long_query_time seconds. Sort_merge_passes: # of merge passes that the sort algorithm has had to do. If large, consider increasing the value of the sort_buffer_size system variable. 25
  • Another Global Variable for Tweeking 26
  • Another Global Variable for Tweeking table_cache: 26
  • Another Global Variable for Tweeking table_cache: The number of open tables for all threads. 26
  • Another Global Variable for Tweeking table_cache: The number of open tables for all threads. Increasing this value increases the number of file descriptors that mysqld requires. 26
  • Another Global Variable for Tweeking table_cache: The number of open tables for all threads. Increasing this value increases the number of file descriptors that mysqld requires. If Opened_tables is constantly increasing and you don't do FLUSH TABLES often - then you should increase the value of the table_cache variable. 26
  • Another Global Variable for Tweeking table_cache: The number of open tables for all threads. Increasing this value increases the number of file descriptors that mysqld requires. If Opened_tables is constantly increasing and you don't do FLUSH TABLES often - then you should increase the value of the table_cache variable. Global variable that expands as needed 26
  • Per connection variables available for tweeking 27
  • Per connection variables available for tweeking max_heap_table_size: 27
  • Per connection variables available for tweeking max_heap_table_size: sets the maximum size to which MEMORY tables are allowed to grow. 27
  • Per connection variables available for tweeking max_heap_table_size: sets the maximum size to which MEMORY tables are allowed to grow. Dynamic variable - can be set per session 27
  • Per connection variables available for tweeking max_heap_table_size: sets the maximum size to which MEMORY tables are allowed to grow. Dynamic variable - can be set per session tmp_table_size: 27
  • Per connection variables available for tweeking max_heap_table_size: sets the maximum size to which MEMORY tables are allowed to grow. Dynamic variable - can be set per session tmp_table_size: Dynamic variable - can be set per session 27
  • Per connection variables available for tweeking max_heap_table_size: sets the maximum size to which MEMORY tables are allowed to grow. Dynamic variable - can be set per session tmp_table_size: Dynamic variable - can be set per session maximum size of internal in-memory temporary tables. actual limit is determined as the smaller of max_heap_table_size and tmp_table_size. 27
  • Per connection variables available for tweeking max_heap_table_size: sets the maximum size to which MEMORY tables are allowed to grow. Dynamic variable - can be set per session tmp_table_size: Dynamic variable - can be set per session maximum size of internal in-memory temporary tables. actual limit is determined as the smaller of max_heap_table_size and tmp_table_size. If in-memory temporary table exceeds the limit - MySQL automatically converts it to an on-disk MyISAM table. 27
  • Per connection variables available for tweeking 28
  • Per connection variables available for tweeking read_buffer_size: 28
  • Per connection variables available for tweeking read_buffer_size: Dynamic variable - can be set per session 28
  • Per connection variables available for tweeking read_buffer_size: Dynamic variable - can be set per session Each thread that does a sequential scan - allocates a buffer of this size (in bytes) for each *table* it scans. 28
  • Per connection variables available for tweeking read_buffer_size: Dynamic variable - can be set per session Each thread that does a sequential scan - allocates a buffer of this size (in bytes) for each *table* it scans. If you do many sequential scans, you might want to increase this value. 28
  • Per connection variables available for tweeking read_buffer_size: Dynamic variable - can be set per session Each thread that does a sequential scan - allocates a buffer of this size (in bytes) for each *table* it scans. If you do many sequential scans, you might want to increase this value. value of this variable should be a multiple of 4KB. 28
  • Per connection variables available for tweeking read_buffer_size: Dynamic variable - can be set per session Each thread that does a sequential scan - allocates a buffer of this size (in bytes) for each *table* it scans. If you do many sequential scans, you might want to increase this value. value of this variable should be a multiple of 4KB. maximum allowable setting is 2GB do not normally recommend having it higher then 8M. 28
  • Per connection variables available for tweeking 29
  • Per connection variables available for tweeking read_rnd_buffer_size: 29
  • Per connection variables available for tweeking read_rnd_buffer_size: Dynamic variable - can be set per session 29
  • Per connection variables available for tweeking read_rnd_buffer_size: Dynamic variable - can be set per session for reading rows in sorted order following a key-sorting operation. designed to avoid disk seeks. 29
  • Per connection variables available for tweeking read_rnd_buffer_size: Dynamic variable - can be set per session for reading rows in sorted order following a key-sorting operation. designed to avoid disk seeks. a large value can improve ORDER BY performance. 29
  • Per connection variables available for tweeking read_rnd_buffer_size: Dynamic variable - can be set per session for reading rows in sorted order following a key-sorting operation. designed to avoid disk seeks. a large value can improve ORDER BY performance. maximum allowable setting is 2GB do not normally recommend having it higher then 8M. 29
  • Per connection variables available for tweeking 30
  • Per connection variables available for tweeking sort_buffer_size: 30
  • Per connection variables available for tweeking sort_buffer_size: Dynamic variable - can be set per session 30
  • Per connection variables available for tweeking sort_buffer_size: Dynamic variable - can be set per session Each thread that needs to do a sort allocates a buffer of this size. 30
  • Per connection variables available for tweeking sort_buffer_size: Dynamic variable - can be set per session Each thread that needs to do a sort allocates a buffer of this size. Increase this value for faster ORDER BY or GROUP BY operations. 30
  • Per connection variables available for tweeking 31
  • Per connection variables available for tweeking bulk_insert_buffer_size: 31
  • Per connection variables available for tweeking bulk_insert_buffer_size: Dynamic variable - can be set per session 31
  • Per connection variables available for tweeking bulk_insert_buffer_size: Dynamic variable - can be set per session Cache to make bulk inserts faster for INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA INFILE when adding data to non-empty tables. 31
  • Per connection variables available for tweeking bulk_insert_buffer_size: Dynamic variable - can be set per session Cache to make bulk inserts faster for INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA INFILE when adding data to non-empty tables. Limits the size of the cache tree in bytes per thread. 31
  • Per connection variables available for tweeking bulk_insert_buffer_size: Dynamic variable - can be set per session Cache to make bulk inserts faster for INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA INFILE when adding data to non-empty tables. Limits the size of the cache tree in bytes per thread. Set to 0 disables the optimization used 31
  • Per connection variables available for tweeking 32
  • Per connection variables available for tweeking join_buffer_size: 32
  • Per connection variables available for tweeking join_buffer_size: Dynamic variable - can be set per session 32
  • Per connection variables available for tweeking join_buffer_size: Dynamic variable - can be set per session Size of the buffer that is used for plain index scans, range index scans, and joins that do not use indexes - full table scans. 32
  • Per connection variables available for tweeking join_buffer_size: Dynamic variable - can be set per session Size of the buffer that is used for plain index scans, range index scans, and joins that do not use indexes - full table scans. The best way to get fast joins is to add indexes. 32
  • Per connection variables available for tweeking join_buffer_size: Dynamic variable - can be set per session Size of the buffer that is used for plain index scans, range index scans, and joins that do not use indexes - full table scans. The best way to get fast joins is to add indexes. Band Aid - don’t depend on it. 32
  • 33
  • 33
  • MySQL Performance Tuning 101 Ligaya Turmelle MySQL Support Engineer ligaya@mysql.com 34