SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
Friday, October 29, 2010
<Insert Picture Here>
MySQL Server Performance Tuning 101
Ligaya Turmelle
Senior Technical Support Engineer - MySQL
ligaya.turmelle@oracle.com
http://joind.in/2285
Friday, October 29, 2010
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: mysql.org or http://dev.mysql.com/
downloads/
• Online Manual: http://dev.mysql.com/doc/refman/
5.1/en/index.html
Friday, October 29, 2010
<Insert Picture Here>
Before we start
Friday, October 29, 2010
Before you Start
• Single greatest gain can be received by optimizing
the queries
• Optimize the underlying system
• Understand that there are no hard/fast/exact answers
for a “proper” value
– Change one value at a time and benchmark to look for
improvement
– Better to under allocate then to over allocate
Friday, October 29, 2010
How MySQL Uses 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)
Friday, October 29, 2010
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/lig/mysql_install/mysql-enterprise-....
| binlog_cache_size | 32768
| bulk_insert_buffer_size | 8388608
| character_set_client | latin1
– my.cnf or my.ini
Friday, October 29, 2010
Other Information
• How much RAM is on the machine?
• Is the machine dedicated to MySQL?
• 64 bit processor?
• 64 bit MySQL server binary?
Friday, October 29, 2010
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 the command twice with time between
- this allows you to calculate the changes in values (Delta)
over time
Friday, October 29, 2010
+-----------------------------------+-------------+
| 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 |
+-----------------------------------+-------------+
Example Status
Friday, October 29, 2010
Finding the Delta
• Uptime - part of the 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
Friday, October 29, 2010
<Insert Picture Here>
Lets begin
Friday, October 29, 2010
What is the server doing?
• Com_XXXX
– Counter for the number of times XXXX has 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 XXXX/second (INSERT/sec or
DELETE/sec)
Friday, October 29, 2010
<Insert Picture Here>
MyISAM
Friday, October 29, 2010
What is the server doing?
(con’t)
• 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
Friday, October 29, 2010
What is the server doing?
(con’t)
• 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
• large value == key_buffer_size is probably to small
– cache miss rate:
– Key_reads/Key_read_requests
– Key buffer efficiency:
– 1 - cache miss rate
Friday, October 29, 2010
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 system
– after 5.0.52 on 64 bit systems = 4GB+
• dedicated machine - 25% of total memory is common
• uses the OS file cache system to cache the files
• too high == paging == bad
Friday, October 29, 2010
What is the server doing?
(con’t)
• MyISAM table locks
– Table_locks_immediate:
• # of table locks granted immediately to MyISAM tables
– Table_locks_waited:
• # of times we have had to wait to get a table lock for
MyISAM tables
• If value is high - consider changing storage engines
Friday, October 29, 2010
<Insert Picture Here>
InnoDB
Friday, October 29, 2010
What is the server doing?
(con’t)
• Innodb_*
– Has various information about the InnoDB tablespace
• Innodb_buffer_pool_pages_data:
– # of pages containing data (dirty or clean)
• Innodb_buffer_pool_pages_free:
– # of free pages
• Innodb_buffer_pool_pages_total:
– total size of the buffer pool, in pages
• Innodb_buffer_pool_wait_free:
– count of # of times we waited for pages to be flushed
– should be a small value
Friday, October 29, 2010
innodb_buffer_pool_size
• Global variable
• size in bytes
• used to cache data and indexes of InnoDB tables
(clustered indexes - remember)
• the larger the value - the less disk IO is needed to
access the data
• dedicated database server - up to 80% of the physical
memory
• buffers everything itself (O_DIRECT)
• DO NOT set to large - will cause paging/swap == bad
Friday, October 29, 2010
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 IO
– larger the log files - longer the crash recovery time*
• sensible values range from 1MB to 1/N-th of the buffer
pool size
– N is the number of log files in the group
• Combined size of log files must be less then 4GB
Friday, October 29, 2010
<Insert Picture Here>
Query Cache
Friday, October 29, 2010
What is the server doing?
(con’t)
• Query Cache Information
– Qcache_total_blocks:
• total # of blocks in the query cache
– Qcache_free_blocks:
• # of free memory blocks. Can indicate a problem with
fragmentation
– Qcache_hits:
• # of query cache hits
– Qcache_inserts:
• # of queries added to the query cache
Friday, October 29, 2010
What is the server doing?
(con’t)
• Query Cache Information
– Qcache_not_cached:
• # of non-cached queries
– Qcache_queries_in_cache:
• # of queries registered in the query cache
– Qcache_lowmem_prunes:
• # of queries that were deleted from the query cache
because of low memory
Friday, October 29, 2010
What is the server doing?
(con’t)
• Turning Query Cache counters into information
– Query Cache Hit Rate:
• quick and easy way to see if you benefit from using the QC
• QC Hit Rate = Qcache_hits/(Qcache_hits+Com_select)
• higher the value the better
– check to see how often are you invalidating 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
Friday, October 29, 2010
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
Friday, October 29, 2010
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 the query_cache_type is set to 0
Friday, October 29, 2010
<Insert Picture Here>
Threads
Friday, October 29, 2010
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 value is “big” - consider increasing thread_cache_size
– Thread cache miss rate:
• Threads_created/Connections
Friday, October 29, 2010
thread_cache_size
• Global variable but grows as needed
• number of threads to be cached for reuse
– When clients disconnect, the threads are put in the cache
until it is full
– Requests for threads are satisfied by reusing the threads in
the cache. Only when empty is a new thread created
• increase to improve performance if you have a lot of
new connections
– May not provide a notable performance increase if you
already use a good thread implementation
• thread cache efficiency
– 100 - ((Threads_created / Connections) * 100)
Friday, October 29, 2010
What is the server doing?
(con’t)
• General Information counters of importance
– Connections:
• # of connection attempts (successful or not)
– Queries:
• # of statements executed (including within Stored Proc)
– Questions:
• # of statements sent to the server by clients and executed
– Slow_queries
• # of queries that took longer then long_query_time sec.
– Sort_merge_passes
• # of merge passes that the sort algorithm had to do
– If large - consider increasing sort_buffer_size
Friday, October 29, 2010
Final Global Variable to tweek
• table_cache
- Global variable that expands as needed
- The number of open tables for all threads
• Increasing this value increased the number of file
descriptors that mysqld requires
- If Opened_tables is constantly increasing and you do not
use FLUSH TABLES often - increase this variable
Friday, October 29, 2010
<Insert Picture Here>
Session Variables
Friday, October 29, 2010
Per connection variables available for tweeking
• max_heap_table_size
– Dynamic variable - can be set per session
– sets the maximum size that MEMORY tables are allowed to
grow to
• 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 value for
max_heap_table_size or tmp_table_size
– If in-memory temporary table exceeds this limit, it is
automatically converted to an on-disk MyISAM table.
Friday, October 29, 2010
Per connection variables available for tweeking
(con’t)
• 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, consider increasing this
value
– value should be multiples of 4KB
– maximum allowable setting is 2GB
• Do not normally recommend it being higher then 8M
Friday, October 29, 2010
Per connection variables available for tweeking
(con’t)
• 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 it higher then 8M
Friday, October 29, 2010
Per connection variables available for tweeking
(con’t)
• 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
Friday, October 29, 2010
Per connection variables available for tweeking
(con’t)
• 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 no-empty tables.
– limits the size of the cache tree in bytes per thread
– Set to 0 disables the optimization used
Friday, October 29, 2010
Per connection variables available for tweeking
(con’t)
• 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 use indexes
– band-aid - don’t depend on it!
Friday, October 29, 2010
<Insert Picture Here>
Questions?
Friday, October 29, 2010
<Insert Picture Here>
Contact:
Email:
ligaya@mysql.com
ligaya.turmelle@oracle.com
Personal Website:
http://blog.khankennels.com
Twitter: @lig
http://joind.in/2285
Friday, October 29, 2010
Friday, October 29, 2010

Más contenido relacionado

La actualidad más candente

Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataProblems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataJignesh Shah
 
Get More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMXGet More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMXTim Callaghan
 
Introduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsIntroduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsJignesh Shah
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldJignesh Shah
 
Sql server scalability fundamentals
Sql server scalability fundamentalsSql server scalability fundamentals
Sql server scalability fundamentalsChris Adkin
 
Best Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisBest Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisJignesh Shah
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesNETWAYS
 
How shit works: the CPU
How shit works: the CPUHow shit works: the CPU
How shit works: the CPUTomer Gabel
 
SSD Deployment Strategies for MySQL
SSD Deployment Strategies for MySQLSSD Deployment Strategies for MySQL
SSD Deployment Strategies for MySQLYoshinori Matsunobu
 
Highly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupHighly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupNilnandan Joshi
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureDmitry Buzdin
 
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...Severalnines
 
Collaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsCollaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsNelson Calero
 
Scaling out SSIS with Parallelism, Diving Deep Into The Dataflow Engine
Scaling out SSIS with Parallelism, Diving Deep Into The Dataflow EngineScaling out SSIS with Parallelism, Diving Deep Into The Dataflow Engine
Scaling out SSIS with Parallelism, Diving Deep Into The Dataflow EngineChris Adkin
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQLPeter Eisentraut
 
OSS Presentation by Kevin Halgren
OSS Presentation by Kevin HalgrenOSS Presentation by Kevin Halgren
OSS Presentation by Kevin HalgrenOpenStorageSummit
 

La actualidad más candente (20)

Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataProblems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
 
Get More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMXGet More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMX
 
Introduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsIntroduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System Administrators
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
V L S
V L SV L S
V L S
 
Sql server scalability fundamentals
Sql server scalability fundamentalsSql server scalability fundamentals
Sql server scalability fundamentals
 
Best Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisBest Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on Solaris
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin Charles
 
How shit works: the CPU
How shit works: the CPUHow shit works: the CPU
How shit works: the CPU
 
SSD Deployment Strategies for MySQL
SSD Deployment Strategies for MySQLSSD Deployment Strategies for MySQL
SSD Deployment Strategies for MySQL
 
Percona FT / TokuDB
Percona FT / TokuDBPercona FT / TokuDB
Percona FT / TokuDB
 
Highly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupHighly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackup
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
 
Mongo db roma replication and sharding
Mongo db roma replication and shardingMongo db roma replication and sharding
Mongo db roma replication and sharding
 
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
 
PostgreSQL on Solaris
PostgreSQL on SolarisPostgreSQL on Solaris
PostgreSQL on Solaris
 
Collaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsCollaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAs
 
Scaling out SSIS with Parallelism, Diving Deep Into The Dataflow Engine
Scaling out SSIS with Parallelism, Diving Deep Into The Dataflow EngineScaling out SSIS with Parallelism, Diving Deep Into The Dataflow Engine
Scaling out SSIS with Parallelism, Diving Deep Into The Dataflow Engine
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQL
 
OSS Presentation by Kevin Halgren
OSS Presentation by Kevin HalgrenOSS Presentation by Kevin Halgren
OSS Presentation by Kevin Halgren
 

Destacado

Tool it Up! - Session #3 - MySQL
Tool it Up! - Session #3 - MySQLTool it Up! - Session #3 - MySQL
Tool it Up! - Session #3 - MySQLtoolitup
 
Mysqlnd Query Cache
Mysqlnd Query CacheMysqlnd Query Cache
Mysqlnd Query CacheAnis Berejeb
 
Loadays MySQL
Loadays MySQLLoadays MySQL
Loadays MySQLlefredbe
 
Understanding MySql locking issues
Understanding MySql locking issuesUnderstanding MySql locking issues
Understanding MySql locking issuesOm Vikram Thapa
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014Ryusuke Kajiyama
 
MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13Eli Aschkenasy
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance TuningMark Swarbrick
 

Destacado (8)

Tool it Up! - Session #3 - MySQL
Tool it Up! - Session #3 - MySQLTool it Up! - Session #3 - MySQL
Tool it Up! - Session #3 - MySQL
 
Pdt tics
Pdt ticsPdt tics
Pdt tics
 
Mysqlnd Query Cache
Mysqlnd Query CacheMysqlnd Query Cache
Mysqlnd Query Cache
 
Loadays MySQL
Loadays MySQLLoadays MySQL
Loadays MySQL
 
Understanding MySql locking issues
Understanding MySql locking issuesUnderstanding MySql locking issues
Understanding MySql locking issues
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
 
MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 

Similar a MySQL Server Performance Tuning 101

MySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewMySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewSachin Khosla
 
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed SystemsSoftware Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systemsadrianionel
 
KoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbegan
KoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbeganKoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbegan
KoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbeganTobias Koprowski
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Got Problems? Let's Do a Health Check
Got Problems? Let's Do a Health CheckGot Problems? Let's Do a Health Check
Got Problems? Let's Do a Health CheckLuis Guirigay
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool ManagementBIOVIA
 
SQL Server 2017 Enhancements You Need To Know
SQL Server 2017 Enhancements You Need To KnowSQL Server 2017 Enhancements You Need To Know
SQL Server 2017 Enhancements You Need To KnowQuest
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureDAGEOP LTD
 
The 5 Minute DBA-DBA Skills for Non-DBA
The 5 Minute DBA-DBA Skills for Non-DBAThe 5 Minute DBA-DBA Skills for Non-DBA
The 5 Minute DBA-DBA Skills for Non-DBApercona2013
 
MySQL Backup Best Practices and Case Study- .ie Continuous Restore Process
MySQL Backup Best Practices and Case Study- .ie Continuous Restore ProcessMySQL Backup Best Practices and Case Study- .ie Continuous Restore Process
MySQL Backup Best Practices and Case Study- .ie Continuous Restore ProcessMarcelo Altmann
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesRichard Douglas
 
KoprowskiT_SQLDay2016_2AMaDisasterJustBegan
KoprowskiT_SQLDay2016_2AMaDisasterJustBeganKoprowskiT_SQLDay2016_2AMaDisasterJustBegan
KoprowskiT_SQLDay2016_2AMaDisasterJustBeganTobias Koprowski
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDBTim Callaghan
 
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just BeganITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just BeganITCamp
 
KoprowskiT_it_camp2013 - 2amADisasterJustBegan
KoprowskiT_it_camp2013 - 2amADisasterJustBeganKoprowskiT_it_camp2013 - 2amADisasterJustBegan
KoprowskiT_it_camp2013 - 2amADisasterJustBeganTobias Koprowski
 
Performance Tuning
Performance TuningPerformance Tuning
Performance TuningJannet Peetz
 
Introduction to GCP BigQuery and DataPrep
Introduction to GCP BigQuery and DataPrepIntroduction to GCP BigQuery and DataPrep
Introduction to GCP BigQuery and DataPrepPaweł Mitruś
 

Similar a MySQL Server Performance Tuning 101 (20)

MySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewMySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of view
 
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed SystemsSoftware Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
 
Internals of Presto Service
Internals of Presto ServiceInternals of Presto Service
Internals of Presto Service
 
Breaking data
Breaking dataBreaking data
Breaking data
 
KoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbegan
KoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbeganKoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbegan
KoprowskiT_SQLSaturdayManchester_2AMaDisasterJustbegan
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Got Problems? Let's Do a Health Check
Got Problems? Let's Do a Health CheckGot Problems? Let's Do a Health Check
Got Problems? Let's Do a Health Check
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management
 
SQL Server 2017 Enhancements You Need To Know
SQL Server 2017 Enhancements You Need To KnowSQL Server 2017 Enhancements You Need To Know
SQL Server 2017 Enhancements You Need To Know
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser Architecture
 
The 5 Minute DBA-DBA Skills for Non-DBA
The 5 Minute DBA-DBA Skills for Non-DBAThe 5 Minute DBA-DBA Skills for Non-DBA
The 5 Minute DBA-DBA Skills for Non-DBA
 
MySQL Backup Best Practices and Case Study- .ie Continuous Restore Process
MySQL Backup Best Practices and Case Study- .ie Continuous Restore ProcessMySQL Backup Best Practices and Case Study- .ie Continuous Restore Process
MySQL Backup Best Practices and Case Study- .ie Continuous Restore Process
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock Holmes
 
KoprowskiT_SQLDay2016_2AMaDisasterJustBegan
KoprowskiT_SQLDay2016_2AMaDisasterJustBeganKoprowskiT_SQLDay2016_2AMaDisasterJustBegan
KoprowskiT_SQLDay2016_2AMaDisasterJustBegan
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB
 
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just BeganITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
 
KoprowskiT_it_camp2013 - 2amADisasterJustBegan
KoprowskiT_it_camp2013 - 2amADisasterJustBeganKoprowskiT_it_camp2013 - 2amADisasterJustBegan
KoprowskiT_it_camp2013 - 2amADisasterJustBegan
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
Introduction to GCP BigQuery and DataPrep
Introduction to GCP BigQuery and DataPrepIntroduction to GCP BigQuery and DataPrep
Introduction to GCP BigQuery and DataPrep
 

Más de Anis Berejeb

Advanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHPAdvanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHPAnis Berejeb
 
APC & Memcache the High Performance Duo
APC & Memcache the High Performance DuoAPC & Memcache the High Performance Duo
APC & Memcache the High Performance DuoAnis Berejeb
 
Barcelona mysqlnd qc
Barcelona mysqlnd qcBarcelona mysqlnd qc
Barcelona mysqlnd qcAnis Berejeb
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_featuresAnis Berejeb
 

Más de Anis Berejeb (8)

Explain2
Explain2Explain2
Explain2
 
Advanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHPAdvanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHP
 
APC & Memcache the High Performance Duo
APC & Memcache the High Performance DuoAPC & Memcache the High Performance Duo
APC & Memcache the High Performance Duo
 
Barcelona mysqlnd qc
Barcelona mysqlnd qcBarcelona mysqlnd qc
Barcelona mysqlnd qc
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_features
 

MySQL Server Performance Tuning 101

  • 2. <Insert Picture Here> MySQL Server Performance Tuning 101 Ligaya Turmelle Senior Technical Support Engineer - MySQL ligaya.turmelle@oracle.com http://joind.in/2285 Friday, October 29, 2010
  • 3. 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: mysql.org or http://dev.mysql.com/ downloads/ • Online Manual: http://dev.mysql.com/doc/refman/ 5.1/en/index.html Friday, October 29, 2010
  • 4. <Insert Picture Here> Before we start Friday, October 29, 2010
  • 5. Before you Start • Single greatest gain can be received by optimizing the queries • Optimize the underlying system • Understand that there are no hard/fast/exact answers for a “proper” value – Change one value at a time and benchmark to look for improvement – Better to under allocate then to over allocate Friday, October 29, 2010
  • 6. How MySQL Uses 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) Friday, October 29, 2010
  • 7. 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/lig/mysql_install/mysql-enterprise-.... | binlog_cache_size | 32768 | bulk_insert_buffer_size | 8388608 | character_set_client | latin1 – my.cnf or my.ini Friday, October 29, 2010
  • 8. Other Information • How much RAM is on the machine? • Is the machine dedicated to MySQL? • 64 bit processor? • 64 bit MySQL server binary? Friday, October 29, 2010
  • 9. 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 the command twice with time between - this allows you to calculate the changes in values (Delta) over time Friday, October 29, 2010
  • 10. +-----------------------------------+-------------+ | 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 | +-----------------------------------+-------------+ Example Status Friday, October 29, 2010
  • 11. Finding the Delta • Uptime - part of the 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 Friday, October 29, 2010
  • 12. <Insert Picture Here> Lets begin Friday, October 29, 2010
  • 13. What is the server doing? • Com_XXXX – Counter for the number of times XXXX has 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 XXXX/second (INSERT/sec or DELETE/sec) Friday, October 29, 2010
  • 15. What is the server doing? (con’t) • 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 Friday, October 29, 2010
  • 16. What is the server doing? (con’t) • 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 • large value == key_buffer_size is probably to small – cache miss rate: – Key_reads/Key_read_requests – Key buffer efficiency: – 1 - cache miss rate Friday, October 29, 2010
  • 17. 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 system – after 5.0.52 on 64 bit systems = 4GB+ • dedicated machine - 25% of total memory is common • uses the OS file cache system to cache the files • too high == paging == bad Friday, October 29, 2010
  • 18. What is the server doing? (con’t) • MyISAM table locks – Table_locks_immediate: • # of table locks granted immediately to MyISAM tables – Table_locks_waited: • # of times we have had to wait to get a table lock for MyISAM tables • If value is high - consider changing storage engines Friday, October 29, 2010
  • 20. What is the server doing? (con’t) • Innodb_* – Has various information about the InnoDB tablespace • Innodb_buffer_pool_pages_data: – # of pages containing data (dirty or clean) • Innodb_buffer_pool_pages_free: – # of free pages • Innodb_buffer_pool_pages_total: – total size of the buffer pool, in pages • Innodb_buffer_pool_wait_free: – count of # of times we waited for pages to be flushed – should be a small value Friday, October 29, 2010
  • 21. innodb_buffer_pool_size • Global variable • size in bytes • used to cache data and indexes of InnoDB tables (clustered indexes - remember) • the larger the value - the less disk IO is needed to access the data • dedicated database server - up to 80% of the physical memory • buffers everything itself (O_DIRECT) • DO NOT set to large - will cause paging/swap == bad Friday, October 29, 2010
  • 22. 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 IO – larger the log files - longer the crash recovery time* • sensible values range from 1MB to 1/N-th of the buffer pool size – N is the number of log files in the group • Combined size of log files must be less then 4GB Friday, October 29, 2010
  • 23. <Insert Picture Here> Query Cache Friday, October 29, 2010
  • 24. What is the server doing? (con’t) • Query Cache Information – Qcache_total_blocks: • total # of blocks in the query cache – Qcache_free_blocks: • # of free memory blocks. Can indicate a problem with fragmentation – Qcache_hits: • # of query cache hits – Qcache_inserts: • # of queries added to the query cache Friday, October 29, 2010
  • 25. What is the server doing? (con’t) • Query Cache Information – Qcache_not_cached: • # of non-cached queries – Qcache_queries_in_cache: • # of queries registered in the query cache – Qcache_lowmem_prunes: • # of queries that were deleted from the query cache because of low memory Friday, October 29, 2010
  • 26. What is the server doing? (con’t) • Turning Query Cache counters into information – Query Cache Hit Rate: • quick and easy way to see if you benefit from using the QC • QC Hit Rate = Qcache_hits/(Qcache_hits+Com_select) • higher the value the better – check to see how often are you invalidating 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 Friday, October 29, 2010
  • 27. 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 Friday, October 29, 2010
  • 28. 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 the query_cache_type is set to 0 Friday, October 29, 2010
  • 30. 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 value is “big” - consider increasing thread_cache_size – Thread cache miss rate: • Threads_created/Connections Friday, October 29, 2010
  • 31. thread_cache_size • Global variable but grows as needed • number of threads to be cached for reuse – When clients disconnect, the threads are put in the cache until it is full – Requests for threads are satisfied by reusing the threads in the cache. Only when empty is a new thread created • increase to improve performance if you have a lot of new connections – May not provide a notable performance increase if you already use a good thread implementation • thread cache efficiency – 100 - ((Threads_created / Connections) * 100) Friday, October 29, 2010
  • 32. What is the server doing? (con’t) • General Information counters of importance – Connections: • # of connection attempts (successful or not) – Queries: • # of statements executed (including within Stored Proc) – Questions: • # of statements sent to the server by clients and executed – Slow_queries • # of queries that took longer then long_query_time sec. – Sort_merge_passes • # of merge passes that the sort algorithm had to do – If large - consider increasing sort_buffer_size Friday, October 29, 2010
  • 33. Final Global Variable to tweek • table_cache - Global variable that expands as needed - The number of open tables for all threads • Increasing this value increased the number of file descriptors that mysqld requires - If Opened_tables is constantly increasing and you do not use FLUSH TABLES often - increase this variable Friday, October 29, 2010
  • 34. <Insert Picture Here> Session Variables Friday, October 29, 2010
  • 35. Per connection variables available for tweeking • max_heap_table_size – Dynamic variable - can be set per session – sets the maximum size that MEMORY tables are allowed to grow to • 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 value for max_heap_table_size or tmp_table_size – If in-memory temporary table exceeds this limit, it is automatically converted to an on-disk MyISAM table. Friday, October 29, 2010
  • 36. Per connection variables available for tweeking (con’t) • 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, consider increasing this value – value should be multiples of 4KB – maximum allowable setting is 2GB • Do not normally recommend it being higher then 8M Friday, October 29, 2010
  • 37. Per connection variables available for tweeking (con’t) • 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 it higher then 8M Friday, October 29, 2010
  • 38. Per connection variables available for tweeking (con’t) • 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 Friday, October 29, 2010
  • 39. Per connection variables available for tweeking (con’t) • 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 no-empty tables. – limits the size of the cache tree in bytes per thread – Set to 0 disables the optimization used Friday, October 29, 2010
  • 40. Per connection variables available for tweeking (con’t) • 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 use indexes – band-aid - don’t depend on it! Friday, October 29, 2010
  • 42. <Insert Picture Here> Contact: Email: ligaya@mysql.com ligaya.turmelle@oracle.com Personal Website: http://blog.khankennels.com Twitter: @lig http://joind.in/2285 Friday, October 29, 2010