18
MySQL Performance Tuning Author: Trifon M. Anguelov Jamshid T C Creation Date: August 2, 2006 Last Update date: August 16, 2006 Version: 1.1

MySQL Performance Tuning

Embed Size (px)

Citation preview

Page 1: MySQL Performance Tuning

MySQL Performance Tuning

Author: Trifon M. Anguelov Jamshid T C

Creation Date: August 2, 2006

Last Update date: August 16, 2006

Version: 1.1

Page 2: MySQL Performance Tuning

1

1. Purpose

To describe the troubleshooting scenarios and the escalation procedure forMDR – MySQL database failures from DBA group to the MDR team

2. FreeBSD kernel tweaks for MySQL database servers

For MySQL on FreeBSD OS installations some kernel parameters could betuned to improve the MySQL database performance. All changes need to goto /boot/loader.conf.local and the machine needs to be rebooted for changesto take effect.

• kern.maxdsiz: make this about 70% of your RAM but no larger than2GB. It needs to be greater than your innodb_buffer_pool size

• kern.ipc.nmbufs="262144" #nmbufs should be 2 * nmbclusters.Setting nmbclusters will automatically set this correctly.

• kern.ipc.nmbclusters="131072"

• kern.ipc.maxsockets="131072"

Also when using demand based connections, if you have a large number ofrequests/sec, you need to change these values as the kernel runs of socketsto use as the sockets don't clean up quickly enough.

Sample loader.conf.local file:

# $Yahoo: loader.conf.local,v 1.3 2000/03/16 07:32:20 filo Exp $# This is loader.conf.local - these defs override defaults found # in /boot/defaults/loader.conf and /boot/loader.conf## This file contains machine specific settings. Yahoo! specific# settings are found in /boot/loader.conf

################################################################# Kernel tunables######################################################################################################kern.maxdsiz="1800000000"kern.ipc.nmbufs="131072"

Page 3: MySQL Performance Tuning

2

kern.ipc.nmbclusters="131072"kern.ipc.maxsockets="131072"

For database servers where a large number of MySQL threads is going to beused, it might be necessary to increase the number of open files in thekernel. For FreeBSD, the limit on the number of open files is determinedwith the following formula:

system wide open files limit = 2 * [20 + (16 * maxusers)]

where maxusers is defined in your kernel configuration file and has a defaultof 10. So by default, your entire system is limited to 360 open files and network socket connections:

2 * [20 + (16 * 10)] = 360 open files and sockets

The limit on the number of open files per process is the same as this systemwide limit.

You can increase the limits without rebooting by entering the commandsshown below as root.

# sysctl -w kern.maxfiles=4096kern.maxfiles: 360 -> 4096# sysctl -w kern.maxfilesperproc=4096kern.maxfilesperproc: 360 -> 4096

For a permanent change, add the following two lines to the script /etc/rc.local.

sysctl -w kern.maxfiles=4096sysctl -w kern.maxfilesperproc=4096

Alternatively, you can increase the value of maxusers in your kernelconfiguration file from its default of 10 to a higher number, such as 100. It isnot recommended to increase this number beyond 256, though.

See the file /usr/src/sys/i386/conf/LINT for more information.

Be careful to avoid syntax errors. The caveat is the server might notcome up if you set the variables inappropriately.

Page 4: MySQL Performance Tuning

3

3. MySQL tweaks for production database servers

3.1 Tuning the MySQL parameters

Whenever MySQL server is installed by using yinst, the defaultconfiguration in my.cnf is not optimal for production usage. The defaultmy.cnf file has to be replaced by optimized configuration.

Sample /etc/my.cnf for MASTER defined for machines with 4 GB RAM is:

[mysqld]port = 3306socket = /tmp/mysql.sockuser = mysqlskip-lockingset-variable = key_buffer=32Mset-variable = max_allowed_packet=8Mset-variable = table_cache=256set-variable = sort_buffer=512Kset-variable = net_buffer_length=8Kset-variable = myisam_sort_buffer_size=1Mset-variable = max_connect_errors=999999999set-variable = max_connections=250set-variable = wait_timeout=30 set-variable = thread_cache_size=30 basedir = /home/ydatadir = /home/y/var/mysql/datalog-error = /home/y/logs/mysql/mysqld.errtmpdir = /tmp/pid-file = /home/y/var/mysql/mysqld.pidset-variable = log_slow_queries=slow.logset-variable = long_query_time=1

## avoid FreeBSD DNS problemsskip-name-resolve

## avoid "niced" "threads" on FreeBSDskip-thread-priority

## Uncomment these if this server will be a master.

log-binserver-id = 1

## InnoDB settings

innodb_data_home_dir = /home/y/var/mysql/ibdatainnodb_data_file_path = ibdata1:256M:autoextendinnodb_log_group_home_dir = /home/y/var/mysql/ibloginnodb_log_arch_dir = /home/y/var/mysql/iblog

Page 5: MySQL Performance Tuning

4

set-variable = innodb_buffer_pool_size=1400Mset-variable = innodb_additional_mem_pool_size=50Mset-variable = innodb_log_file_size=800Mset-variable = innodb_log_buffer_size=8Minnodb_flush_log_at_trx_commit=1set-variable = innodb_lock_wait_timeout=50

## Query cache

query_cache_size = 8Mquery_cache_type = 0

## SSL Support

#ssl-ca=/home/y/etc/mysql/cacert.pem#ssl-cert=/home/y/etc/mysql/server-cert.pem#ssl-key=/home/y/etc/mysql/server-key.pem

[myisamchk]set-variable = key_buffer=20Mset-variable = sort_buffer=20Mset-variable = read_buffer=2Mset-variable = write_buffer=2M

Sample /etc/my.cnf for SLAVE defined for machines with 4 GB RAM is:

[mysqld]port = 3306socket = /tmp/mysql.sockuser = mysqlskip-lockingset-variable = key_buffer=32Mset-variable = max_allowed_packet=8Mset-variable = table_cache=256set-variable = sort_buffer=512Kset-variable = net_buffer_length=8Kset-variable = myisam_sort_buffer_size=1Mset-variable = max_connect_errors=999999999set-variable = max_connections=250set-variable = wait_timeout=30 set-variable = thread_cache_size=30 basedir = /home/ydatadir = /home/y/var/mysql/datalog-error = /home/y/logs/mysql/mysqld.errtmpdir = /tmp/pid-file = /home/y/var/mysql/mysqld.pidset-variable = log_slow_queries=slow.logset-variable = long_query_time=1

Page 6: MySQL Performance Tuning

5

## avoid FreeBSD DNS problemsskip-name-resolve

## avoid "niced" "threads" on FreeBSDskip-thread-priority

## Uncomment these if this server will be a master.

log-binlog-slave-updatesserver-id = 3

## InnoDB settings

innodb_data_home_dir = /home/y/var/mysql/ibdatainnodb_data_file_path = ibdata1:256M:autoextendinnodb_log_group_home_dir = /home/y/var/mysql/ibloginnodb_log_arch_dir = /home/y/var/mysql/iblogset-variable = innodb_buffer_pool_size=1400Mset-variable = innodb_additional_mem_pool_size=50Mset-variable = innodb_log_file_size=800Mset-variable = innodb_log_buffer_size=8Minnodb_flush_log_at_trx_commit=1set-variable = innodb_lock_wait_timeout=50

## Query cache

query_cache_size = 8Mquery_cache_type = 0

## SSL Support

#ssl-ca=/home/y/etc/mysql/cacert.pem#ssl-cert=/home/y/etc/mysql/server-cert.pem#ssl-key=/home/y/etc/mysql/server-key.pem

[myisamchk]set-variable = key_buffer=20Mset-variable = sort_buffer=20Mset-variable = read_buffer=2Mset-variable = write_buffer=2M

3.2 Tuning MySQL parameter for master/slave replication

For MySQL 4.1 use the following commands to configure MySQL master:

yinst set mysql_config.max_connections=1000yinst set mysql_config.wait_timeout=30 yinst set mysql_config.thread_cache_size=30 yinst set mysql_config.innodb_buffer_pool_size=1400M

Page 7: MySQL Performance Tuning

yinst set mysql_config.innodb_additional_mem_pool_size=50Myinst set mysql_config.innodb_log_file_size=800Myinst set mysql_config.innodb_log_buffer_size=8Myinst set mysql_config.query_cache_type=0yinst set mysql_config.server_id=1 yinst set mysql_config.log_bin=log-bin

For MySQL 4.1 use the following commands to configure slave:

yinst set mysql_config.max_connections=yinst set mysql_config.wait_timeout=30 yinst set mysql_config.thread_cache_size=30 yinst set mysql_config.innodb_buffer_pool_size=1400Myinst set mysql_config.innodb_additional_mem_pool_size=50Myinst set mysql_config.innodb_log_file_size=800Myinst set mysql_config.innodb_log_buffer_size=8Myinst set mysql_config.query_cache_type=0yinst set mysql_config.server_id=2 yinst set mysql_config.log_bin=log-bin yinst set mysql_config.log_slave_updates=log-slave-updates

The last 2 commands are needed only if you want bin logging turned on theslave with the updates that come from the master. Once the slave is setupconsider setting read_only=on so as to prevent accidental updates on theslave.

yinst set mysql_config.read_only=read-only

For 2 GB RAM machines, 2 things need to be changed in the above my.cnffiles:

• set-variable = innodb_buffer_pool_size=1100M

• set-variable = innodb_log_file_size=600M

For MySQL? 4.1 :

yinst set mysql_config.innodb_buffer_pool_size=1100Myinst set mysql_config.innodb_log_file_size=600M

Page 8: MySQL Performance Tuning

7

3.3 MySQL database performance monitoring

Daily Performance Monitoring script is about to be implemented for allMySQL database servers. This script will monitor the database parametersbelow parameters and then use them to calculate the DB hit rations.

The script is based on the following commands:

mysql> show status; | Parameters are taken from output of thesequeries.mysql> show slave status; |

Uptime : Shows database uptimeQueries per second avg : Nos of queries database handling per second.Innodb Ratio : (100 * <buffer value> ) / 1000Thread Cache : 100 - ((Threads_created / Connections) * 100)Myisam Ratio : (Key_read_requests / (Key_reads + Key_read_requests)) * 100Query Ratio : Qcache_hits * 100 / (Qcache_inserts + cache_not_cached + Qcache_hits)

The script will them create a report with the performance metrics. If theratios are below 90% it will be in red and these are the ratios DBA has totune.

Some times InnoDB ratio will be having " No Value " it means that No bufferpool page hit rate generated. Means no buffer page used since x seconds soit can be ignored .

3.4 MySQL database performance tuning

The following section contains some of the best practices for tuning MySQLdatabase servers. MySQL tuning depends upon the server configuration anddatabase also by the hardware specifications. In this document, we willreview only the MySQL tuning.

3.4.1 Tuning the thread cache

If the "thread_cache_size" variable is setup, then when a client disconnects,the client's threads are put in the cache if there aren't more thanthread_cache_size threads from before. All new threads are first taken fromthe cache, and only when cache is empty is a new thread created.

Page 9: MySQL Performance Tuning

8

The variable thread_cache_size can be increased to improve theperformance if you have a lot of new connections. By examing the differencebetween "Connections" and "Threads_created" you can see how efficient thecurrent thread cache is for you.

Once the thread_cache_size variable is setup, this will setup the samenumber of threads to hold open in memory to service new connections. Youcan determine how many connections are being serviced by already cachedthreads, and how many are having to wait for a new thread stack to beallocated by using the SHOW VARIABLES command. Example:

mysql> show variables like 'thread%';+-------------------+--------+| Variable_name | Value |+-------------------+--------+| thread_cache_size | 64 || thread_stack | 196608 |+-------------------+--------+

If "Threads_created" is big, you may want to increase the"thread_cache_size" variable. The cache hit rate can be calculated with theformula:

hit rate = "Threads_created" / "Connections"

Here is an example

| Connections | 5964647 |

| Threads_cached | 54 || Threads_created | 448983 |

In case the thread cache is not enabled, the "Threads_cached" value is goingto be zero.

| Connections | 7577159 |

| Threads_cached | 0 || Threads_created | 7577158 |

Page 10: MySQL Performance Tuning

9

mysql> show variables like 'thread%';+-------------------+--------+| Variable_name | Value |+-------------------+--------+| thread_cache_size | 64 || thread_stack | 196608 |+-------------------+--------+2 rows in set (0.00 sec)

You can monitor the effect of the threads caching with the followingparameters:

mysql> show status;+--------------------------+------------+| Variable_name | Value |+--------------------------+------------+| Table_locks_immediate | 27636539 || Table_locks_waited | 0 || Threads_cached | 45 || Threads_created | 3080 || Threads_connected | 28 || Threads_running | 1 || Uptime | 87103 |+--------------------------+------------+

3.4.2 Tuning the Myisam hit ratio

The key buffer ( key_buffer_size ) is where mysql caches index blocks forMyisam tables. Anytime a query uses an index, mysql will first check to seeif the relevant index is in memory or not. So , on a dedicated mysqlserver,allocate somewhere between 20% - 50% of your RAM for mysql keybuffer.

The sort buffer ( sort_buffer_size ) is used to answer queries that invokesorting data -- those with an ( order by , group by )

The table cache ( table_cache ) contains the number of open tables for allthreads.You can check whether you need to increase the table cache bychecking the Opened_tables status variable. If the value of Opened_tablesis large and you do not do FLUSH TABLES often then you should increasethe value of the table_cache variable.

Tuning Myisam is not on high priority since We dont have too many Myisamtables since Myisam tables have been migrated to InnoDB tables due tocorruption error .

Page 11: MySQL Performance Tuning

10

3.4.3 Tuning the query ratio

The MySQL server can use a query cache to speed up processing of SELECTstatements that are executed repeatedly. The resulting performanceimprovement often is dramatic.

To determine whether a server supports the query cache, check the value ofthe have_query_cache system variable:

mysql> SHOW VARIABLES LIKE 'have_query_cache';+------------------+-------+| Variable_name | Value |+------------------+-------+| have_query_cache | YES |+------------------+-------+

For servers that do include query cache support, cache operation is basedon the values of three system variables:

– query_cache_type determines the operating mode of the query cache

– query_cache_size determines the amount of memory to allocate for thecache, in bytes

- query_cache_limit sets the maximum result set size that will be cached;query results larger than this value are never cached

For example, to enable the query cache and allocate 16MB of memory for it,use the following settings in an option file:

[mysqld]query_cache_type=1query_cache_size=16M

The amount of memory indicated by query_cache_size is allocated even ifquery_cache_type is zero. To avoid wasting memory, don't set the sizegreater than zero unless you plan to enable the cache. Also, a size of zeroeffectively disables the cache even if query_cache_type is non-zero.

query_cache_size sets the amount of memory used for the query cachesome guidelines, how to set this variable is Qcache_inserts will show youhow many queries are added to query cache while qcache_hits will showyou how many query results are taken directly from the query cache insteadof executing them.

You should compare qcache_hits value to total number of your selectqueries to see what is your current hit rate.

Page 12: MySQL Performance Tuning

11

You may increase or degrease query_cache_size to find the value, whichprovides best performance.

Qcache_free_memory shows amount of free memory in query cache, whichis not used at the moment. If this value stays constantly high during the loadit might be good idea to decrease the query cache size, i.e. to free somememory from the query cache to other caches and buffers.

query_cache_limit variable sets the maximum result size, which would bestored in the query cache.The reason to have this variable is to limit querieshaving very large result sets to overwrite all the queries in the query set.

A rule of start tuning the parameter might be setting query_cache_limit1/100 to 1/10 of query_cache_size.

3.4.4 Tuning the size of the server's caches

The most important parameters you can change are the sizes of the tablecache and the caches used by the storage engines to buffer information forindexing operations. If you have memory available, allocating it to theserver's caches allows information to be held in memory longer and reducesdisk activity. This is good, because it's much faster to access information from memory than to read it from disk.

When the MySQL server opens table files, it tries to keep them open so as tominimize the number of file-opening operations. To do this, it maintainsinformation about open files in the table cache. The table_cache systemvariable controls the size of this cache. If the server accesses lots of tables,the table cache fills up and the server closes tables that haven't been usedfor a while to make room for opening new tables. You can assess howeffective the table cache is by checking the Opened_tables status indicator:

SHOW STATUS LIKE 'Opened_tables';

Opened_tables indicates the number of times a table had to be openedbecause it wasn't already open. (This value is also displayed as the Opensvalue in the output of the mysqladmin status command.) If the numberremains stable or increases slowly, it's probably set to about the right value.If the number grows quickly, it means the cache is too small and that tablesoften have to be closed to make room to open other tables. If you have filedescriptors available, increasing the table cache size will reduce the numberof table opening operations.

The key buffer is used by the MyISAM storage engine to hold index blocksfor index-related operations.

Page 13: MySQL Performance Tuning

12

Its size is controlled by the key_buffer_size system variable. Larger valuesallow MySQL to hold more index blocks in memory at once, which increasesthe likelihood of finding key values in memory without having to read a newblock from disk. The default size of the key buffer is 8MB. If you have lots of memory, that's avery conservative value and you should be able to increase it substantiallyand see a considerable improvement in performance for index-basedretrievals and for index creation and modification operations.

In MySQL 4.1 and up, you can create additional key caches for MyISAMtables and assign specific tables to them.

The InnoDB has its own caches for buffering data and index values. Thesizes are controlled by the innodb_buffer_pool_size. The InnoDB engines alsomaintains a log buffer. The innodb_log_buffer_size variable controls its size.

3.4.5 Tuning the thread concurency

You can also setup the thread concurency with the following parameter in /etc/my.cnf file:

thread_concurency=4

3.4.6 Tuning the InnoDB performance

3.4.6.1 Checking the InnoDB performance statistics

The main InnoDB performance metric is the InnoDB ratio.

SHOW INNODB STATUS command is the easiest way to get the pastInnoDB performance statistics. The statistics are cumulatative and will givesome inputs about your I/O performance and if it's neccessary to increasingthe size of innodb_buffer_pool_size parameter.

Example of the command output is:

mysql> SHOW INNODB STATUS\G*************************** 1. row ***************************Status:

Page 14: MySQL Performance Tuning

13

060525 17:35:04 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 53 seconds----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 2627806, signal count 1584991Mutex spin waits 306880889, rounds 1622971889, OS waits 1544762RW-shared spins 13956, OS waits 2287; RW-excl spins 4730, OS waits 1825

-----------TRANSACTIONS------------Trx id counter 0 3366693020Purge done for trx's n:o < 0 3366685195 undo n:o < 0 0Total number of lock structs in row lock hash table 0LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 0 3366682027, not started, OS thread id 6006796MySQL thread id 247276, query id 53122286 207.126.226.110 mdr---TRANSACTION 0 3366680749, not started, OS thread id 6062138MySQL thread id 247273, query id 53120941 207.126.226.78 mdr---TRANSACTION 0 3366673336, not started, OS thread id 5904428MySQL thread id 247252, query id 53112674 207.126.226.77 mdr---TRANSACTION 0 0, not started, OS thread id 6012943MySQL thread id 247244, query id 53142434 localhost rootSHOW INNODB STATUS---TRANSACTION 0 3366666446, not started, OS thread id 6273084MySQL thread id 247229, query id 53104696 207.126.226.76 mdr---TRANSACTION 0 3366661041, not started, OS thread id 6320224MySQL thread id 247194, query id 53097685 207.126.226.75 mdr---TRANSACTION 0 3366650526, not started, OS thread id 6234178MySQL thread id 247150, query id 53084783 207.126.226.74 mdr---TRANSACTION 0 3366350666, not started, OS thread id 2955336MySQL thread id 244163, query id 52583796 207.126.226.77 mdr---TRANSACTION 0 3366350562, not started, OS thread id 4958545MySQL thread id 244160, query id 52583623 207.126.226.75 mdr---TRANSACTION 0 3366350544, not started, OS thread id 6244386MySQL thread id 244159, query id 52583585 207.126.226.74 mdr---TRANSACTION 0 3366350526, not started, OS thread id 6014995MySQL thread id 244157, query id 52583509 66.228.173.45 mdr---TRANSACTION 0 3366350503, not started, OS thread id 6182952MySQL thread id 244155, query id 52583448 66.228.173.44 mdr---TRANSACTION 0 3366350243, not started, OS thread id 6240278MySQL thread id 244151, query id 52583043 66.228.173.42 mdr---TRANSACTION 0 3366348976, not started, OS thread id 6314077MySQL thread id 244149, query id 52581725 66.228.173.41 mdr

Page 15: MySQL Performance Tuning

14

---TRANSACTION 0 3366348568, not started, OS thread id 6295632MySQL thread id 244146, query id 52581220 66.228.173.39 mdr---TRANSACTION 0 3366348078, not started, OS thread id 6236228MySQL thread id 244142, query id 52580624 66.228.173.38 mdr---TRANSACTION 0 3366348025, not started, OS thread id 6252573MySQL thread id 244140, query id 52580408 207.126.226.71 mdr---TRANSACTION 0 3366614159, not started, OS thread id 6225982MySQL thread id 240548, query id 53037023 66.228.172.221 mdr---TRANSACTION 0 3366612876, not started, OS thread id 5742781MySQL thread id 240540, query id 53035475 66.228.172.221 mdr---TRANSACTION 0 3366611420, not started, OS thread id 6258720MySQL thread id 240530, query id 53032159 66.228.172.221 mdr

---TRANSACTION 0 3363914103, not started, OS thread id 5804119MySQL thread id 230558, query id 53113945 66.228.172.246 mdr---TRANSACTION 0 3363897237, not started, OS thread id 6246436MySQL thread id 230455, query id 53130716 66.228.172.246 mdr---TRANSACTION 0 3362377804, not started, OS thread id 5397045MySQL thread id 208888, query id 53130675 66.228.172.246 mdr---TRANSACTION 0 3366506882, not started, OS thread id 40981MySQL thread id 26650, query id 53045812 207.126.226.133 mdr---TRANSACTION 0 3366611419, not started, OS thread id 155725MySQL thread id 5722, query id 53032157 66.228.172.221 mdr---TRANSACTION 0 3366685193, not started, OS thread id 20491MySQL thread id 2, query id 53126457 Slave: waiting for binlog update--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (write thread)Pending normal aio reads: 0, aio writes: 0, ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0104445 OS file reads, 358363 OS file writes, 29504 OS fsyncs0.00 reads/s, 0 avg bytes/read, 1.55 writes/s, 0.28 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf for space 0: size 1, free list len 5, seg size 7,1002 inserts, 1002 merged recs, 1002 mergesHash table size 553253, used cells 28442, node heap has 30 buffer(s)459.46 hash searches/s, 1309.45 non-hash searches/s---LOG

Page 16: MySQL Performance Tuning

15

---Log sequence number 6 3856962699Log flushed up to 6 3856962699Last checkpoint at 6 38569626490 pending log writes, 0 pending chkp writes185563 log i/o's done, 0.91 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 165742729; in additional pool allocated 2037376Buffer pool size 8192Free buffers 0Database pages 8162Modified db pages 1Pending reads 0

Pending writes: LRU 0, flush list 0, single page 0Pages read 118699, created 13948, written 2232260.00 reads/s, 0.00 creates/s, 0.57 writes/sBuffer pool hit rate 1000 / 1000--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queueMain thread id 14344, state: sleepingNumber of rows inserted 91368, updated 147654, deleted 0, read36219780220.04 inserts/s, 0.13 updates/s, 0.00 deletes/s, 10760.33 reads/s----------------------------END OF INNODB MONITOR OUTPUT

InnoDB cache size could be increased to up to 60% - 80% of the totalavaiable RAM on a dedicated database machines would increase MySQLperformance significantly. Another InnoDB related parameter isinnodb_log_file_size, which could be increased to up to 25 % of buffer poolsize. This will reduce the I/O writes in most of the cases.

It is a risk if the value of the following expression is close to or exceeds 2GB:

innodb_buffer_pool_size + key_buffer_size +

(read_buffer_size + sort_buffer_size)*max_connections

Page 17: MySQL Performance Tuning

16

3.4.6.2 Checking the InnoDB related variables

mysql> show variables like 'innodb%'; +---------------------------------+--------------------------+| Variable_name | Value |+---------------------------------+--------------------------+| innodb_additional_mem_pool_size | 2097152 || innodb_buffer_pool_size | 134217728 || innodb_data_file_path | ibdata1:256M:autoextend || innodb_data_home_dir | /home/y/var/mysql/ibdata || innodb_file_io_threads | 4 || innodb_force_recovery | 0 || innodb_thread_concurrency | 8 || innodb_flush_log_at_trx_commit | 1 || innodb_fast_shutdown | ON || innodb_flush_method | O_DSYNC || innodb_lock_wait_timeout | 50 || innodb_log_arch_dir | /home/y/var/mysql/iblog || innodb_log_archive | OFF || innodb_log_buffer_size | 8388608 || innodb_log_file_size | 67108864 || innodb_log_files_in_group | 2 || innodb_log_group_home_dir | /home/y/var/mysql/iblog || innodb_mirrored_log_groups | 1 || innodb_max_dirty_pages_pct | 90 |+---------------------------------+--------------------------+

4. Benchmarking MySQL server performance

To benchmark the MySQL server you can use the benchmark() function tosee how long it takes to process a given expression.

The purpose of benchmark() is not to retrieve the result of the expressionbut to see how long it takes to repeat the expression for a specific number oftimes. For example, the following command executes the expression"10+10" for one million times:

mysql> select benchmark(1000000, 10+10);+---------------------------+| benchmark(1000000, 10+10) |+---------------------------+| 0 |+---------------------------+1 row in set (0.07 sec)

Page 18: MySQL Performance Tuning

17

This command executes the date extraction, also one million times:

mysql> select benchmark(1000000, extract(year from now()) );+-----------------------------------------------+| benchmark(1000000, extract(year from now()) ) |+-----------------------------------------------+| 0 |+-----------------------------------------------+1 row in set (0.06 sec)

5. MySQL query tuning

MySQL queries comply with the ANSI standard and all the SQL syntax applyfor the MySQL queries. As in Oracle, getting the explain plan for a SQLquery is the first step to determine if the query is optimal or not.

Example of getting the explain plan for a query is:

mysql> explain select oid from MDR_DataSet where (validto = '9999-12-3123:59:59') and ( (c_instanceof = 3058627));+-------------+------+----------------+----------------+---------+-------+-------+--------------------------+| table | type | possible_keys | key | key_len | ref | rows | Extra|+-------------+------+----------------+----------------+---------+-------+-------+--------------------------+| MDR_DataSet | ref | DS_faster_poll | DS_faster_poll | 9 | const | 13440 |Using where; Using index |+-------------+------+----------------+----------------+---------+-------+-------+--------------------------+1 row in set (0.01 sec)

The Extra column shows is index is used for a particular query. If index isnot used, the query should be reviewed and if appropriate index could becreated.