SlideShare a Scribd company logo
1 of 36
Download to read offline
MySQL Server
Settings Tuning


Peter Zaitsev, co-founder, Percona Ltd

April 23-26 2007
About Speaker
    Peter Zaitsev
    Co-Founder at Percona Ltd,
    - Consulting company specializing in MySQL and LAMP
      Performance
    Founder http://www.mysqlperformanceblog.com
    Spent 4.5 years with MySQL AB,
    - High Performance Group, Manager
      - Performance related Support, Development, Consulting etc
    Have designed and implemented numerous MySQL based
     projects
About Presentation
   What should you consider while tuning MySQL Server
    settings ?
   How much improvement to inspect ?
   What things to look at while setting various settings ?
   Assume you're familiar with MySQL at some level
Things to consider while tuning
   Settings are workload specific
    There is no such thing as optimal config for 16GB of memory
   Storage Engine choice or mix is important
   Few settings depend on your OS and Hardware
Approaching tuning
   You just need to get few of them right for decent
    performance
    Rest are very specific and give hard to notice improvements
   Some settings affect MySQL Behavior and data safety, be
    careful
   Many settings can be set on connection basics, use it.
   Optimize queries first or you may need to revisit your
    settings.
Typical mistakes
   Running in MySQL default settings
    Unless you're running it on laptop to store your DVD collection data
   Using someone elses my.cnf file without checking if it
    matches your needs.
   Setting large global values if only one/two queries need
    them. Instead you can do:
    SET sort_buffer_size=128000000;
    <run query>
    SET sort_buffer_size=DEFAULT
What information do we have available ?
   SHOW STATUS
   SHOW INNODB STATUS
   Operating System monitoring commands
    vmstat
    iostat
    mpstat
Allocating memory
   Allocating more memory to MySQL Server often improves
    performance
   But Allocating too much memory may kill performance and
    stability
   Watch out for
    Swapping
       Look for swap IO rather than simple used swap space
    Running out of address space on 32bit systems
       Make sure OS and MySQL Server are both 64bit
Fighting Swapping
   Some OS would swap even when enough memory is
    available
    Problems balancing IO cache vs Swapping
   --memlock – lock MySQL Server in memory
    can be dangerous
   Tune VM subsystem to use swap only as last resort
    echo 1 > /proc/sys/vm/swappiness
   If using Innodb on Linux try using direct IO
    --innodb_flush_method=O_DIRECT
Know the unit in which variable is set
   table_cache=128M
    Wrong – table cache is measured in entries
   key_buffer_size=1024
    Wrong again, Key buffer should be specified in bytes
   innodb_max_dirty_pages_pct=8G
    This one is set in percents
Know locality and allocation pattern
   key_buffer_size
    Global, shared by all threads
   sort_buffer_size
    Allocated for the thread once sorting needs to be done
   read_buffer_size
    Allocated all at full size, even if smaller is enough
    Overly large values may slow things down
       larger allocations typically done from OS
   tmp_table_size
    Specifies maximum size, will grow to this size as needed
    no performance penalty for setting high.
Lets get to details
Looking at SHOW STATUS
   SHOW GLOBAL STATUS shows global server status –
    good for understanding the load
    The only one available in MySQL 4.1 and below
   SHOW LOCAL STATUS is great for query/transaction
    profiling
    Available since MySQL 5.0
    SHOW STATUS now defaults to this
    Some variables are global only
      Will still be shown in SHOW STATUS output
   mysqladmin extended -i100 -r
    Great to sample what is happening with MySQL Server Now
SHOW STATUS
   Aborted_clients
    Usually no need to worry – many programs do not close connection
      properly
   Aborted_connects
    May mean authentication failure, network timeout or other error
    Worth to look at as may cause host blocked out
      --max_connect_errors=100000
      Beware password break attempts
   Binlog_cache_disk_use/Binlog_cache_use
    how frequently bin log cache size has to spill to the disk
    increase --binlog_cache_size if a lot
Com_XXX
   Understanding server load in terms of queries
   Queries can vary in complexity quite a lot
   Good to catch use mistakes
    Unintended LOCK TABLES with Innodb tables
       Com_lock_tables
    Too many ROLLBACKs
       Com_rollback
    Prepared Statements used only once
    Com_stmt_prepare = Com_stmt_execute
Temporary Objects
   Created_tmp_tables
    Temporary tables can often be avoided by query optimization
   Created_tmp_disk_tables
    Not enough memory is allocated – increase tmp_table_size and
      max_heap_table_size
    Temporary table can't be created in memory
      Typically because of BLOB/TEXT columns required
    Can be placed on tmpfs for better performance
      --tmpdir=/dev/shm on Linux
         Watch out for overflow
Handler_XXX
   Represent what is happening with server on storage engine
    layer (better)
   Does not make a difference between different rows and
    different engines
   No way to see covering index usage
   Handler_read_key, Handler_read_next - indexed
    accesses
   Handler_read_rnd, Handler_read_rnd_next - full table
    scans
    Temporary tables also counted here
Innodb_XXX
   A lot of Innodb status variables added in MySQL 5.0
   Mostly copied from SHOW INNODB STATUS
   Not made per-thread counters yet
   Innodb_data_reads, Innodb_data_writes
    Physical IO to Innodb tablespace files
       Use to tune innodb_buffer_pool_size
   Innodb_buffer_pool_pages_misc - how much memory
    Innodb locks, adaptive hash indexes, insert buffer take
   Innodb_log_waits
    Waits happen when innodb_log_buffer_size is not large enough
Innodb_XXX
   Innodb row operations (Innodb_rows_read etc) can be
    used to view Innodb activity on row level
   Innodb_row_lock_XXX - information about innodb lock
    waits and timing.
   Innodb_data_pending_XXX,
    Innodb_os_log_pending_XXX
    Pending IO operations. IO is overloaded if they stay high
Key Cache Info
   Key_blocks_used / Key_blocks_unused
    How much of your key_buffer is used ?
    key_blocks_used should be key_blocks_ever_used
    Helps not to set key buffer higher than needed
   Key_read_requests, Key_reads, Key_write_requests,
    Key_writes
    How good is your key buffer usage ?
    Look at amount of reads/writes which pass to IO subsystem
    Key Cache hit ratio alone is useless - checking how it is affected
      by buffer sizing is helpful
      As hit ratio does not change much any more it may be no point
        increasing it further
Connections and Tables
    Max_used_connections
    If matches max_connections you may had run out of
       connections
    Open_files - check not to run out of limit
    Open_tables – how table cache is used
    Opened_tables -check how quickly it growths
      Growths due to explicit temporary tables
      Growths if it is not large enough.
      Adjust –table-cache variable
      Make sure --open-file-limit is large enough
Query Cache Status
   Qcache_hits
    How frequently query was used from query cache
      Com_selects is not incremented in this case
   Qcache_inserts
    Query stored in query cache – misses and overhead
   Qcache_free_memory
    Free/Unused memory in query cache
    Often query cache can use limited memory because of invalidation
   Qcache_lowmem_prunes
    Not enough memory or too fragmented – remove some queries
Select Information
   Select_full_join
    Joins without indexes. Bad and dangerous
   Select_range
    Range scan queries. No problem with these
   Select_range_check
    Usually queries worth looking to optimize. No good index.
   Select_scan
    Full Table Scan. Small or Large
Sorting
   Sort_merge_passes
    Consider increasing sort_buffer_size if it is high
   Sort_range
    Sorting of ranges
   Sort_scan
    Sorting full table scans
   Sort_rows
    How many rows sorted per second
Table locks information
   Table_locks_immediate
    Table locks granted without waiting
   Table_locks_waited
    Table locks which had to be waited for
   Helpful to find out if Table locks are problem
   Do not show how long wait was for
    Rare but long table locks may be too bad already
Threads Information
   Threads_cached
    entries currently used in threads_cache
   Threads_connected
    current number of connected threads. Make sure you have some
       gap to max_connections
   Threads_created
    threads_cache “misses” increase threads_cache if it is high
   Threads_running
    Amount of threads running at the same time Keep it reasonable
      Waiting on table locks, row level locks, IO is also counted as
        running
SHOW INNODB STATUS - Mutexes
     Innodb Mutexes information
     Helpful to tune --innodb_thread_concurrency
      If number of OS Waits or Spinlocks is high it is often worth to
          increase it
      What is “High” ?
      More than 1000 OS Waits/sec
      More than 100.000 spin rounds/sec

O S W AI AR R AY I FO :r
        T        N      eser i count419870,si
                            vaton                gnalcount418867
M ut spi w ais 1110481,r
    ex n      t           ounds 3157468,O S w ais 74647
                                               t
RW -     ed   ns               t
     shar spi 650429,O S w ais 320432;R W -  exclspi 44900,O S w ais 20070
                                                    ns            t
Purge activity and memory usage
   “Total memory allocated 13867961114; in additional pool
    allocated 1048576”
    Tune additional pool size
    Check how much memory Innodb really allocated
       May be more than you think due to Innodbs own table cache
   “Trx id counter 0 458146886 Purge done for trx's n:o < 0
    458146877 undo n:o < 0 History list length 31 Total number
    of lock structs in row lock hash table 0”
    Check check how purge is happening
    set innodb_max_purge_lag if it is unable to keep up
       Will slow updates down
Most important settings to set
Memory Settings - Global
   key_buffer_size
    Used by MyISAM tables to cache Index only, not data
    30% of memory for MyISAM only system
    4GB limit per key buffer, can have multiple of these
    MyISAM tables used for temporary tables anyway
   innodb_buffer_pool_size
    Used by Innodb tables
    70% of memory for Innodb only system
    Innodb performance is very critical to this setting
   query_cache_size
    Set if using query cache
Memory Settings - Local
   read_buffer_size, read_rnd_buffer_size
    sequential read buffers used by MyISAM and some others
    Allocated when needed.
    1M/4M typically good to start
   sort_buffer_size
    buffer used for sorting. Increase if a lot of large sorts are done
   tmp_table_size
    Maximum size of in-memory table allowed (used by complex
      queries)
    May need more than one temporary table per query
    max_heap_table_size limit is also used
Other caches
   table_cache
    Number of tables mysql will keep open
    Allows to avoid reopens (expensive for some storage engines)
    Needs file handlers for many storage engines
    Does not affect Innodb Internal table cache.
    Set at least 1024
   thread_cache
    Number of threads MySQL can cache and reuse
    Set so threads_created is low
    32-64 is typical good value.
Innodb Settings
   innodb_log_file_size
    Very important for write performance, reduce dirty buffer flushes
    Tradeoff between performance and recovery speed
    128-512M are generally good value.
   innodb_thread_concurrency
    Number of threads which can be in Innodb kernel at once
    Higher values – better resource usage but beware contension
    2*(NumCPUs+Num_disks) is theoretically good value
    Practical values may be much lower.
   innodb_log_buffer_size
    1-4MB is enough unless you're using large blobs.
More Innodb Settings
   innodb_flush_log_at_trx_commit
    Default behavior is to flush log to the disk on each transaction
      commit
    This includes update statements outside of transactions
    Often unwanted, especially for MyISAM->Innodb migrations
    Use value 2 (flush to OS cache) or 0 (do not flush at all)
    Innodb flushes logs once per second anyway
   innodb_flush_method
    O_DIRECT to avoid double buffering
   innodb_locks_unsafe_for_binlog
    Reduce locks if not using binary logs
Some special tuning settings
   myisam_sort_buffer_size
    Used for rebuilding MyISAM indexes – ALTER, REPAIR,
      OPTIMIZE, LOAD DATA.
   max_length_for_sort_data
    Store row data instead of row pointer in the sort file
    Can help performance or can kill performance
   myisam_stats_method
    Helps to fine tune MySQL optimizer plan selection
    nulls_unequal – count all nulls as different values (default)
    nulls_equal - count all nulls as same value
Time for questions
   Ask your questions now or catch me later on the conference
   pz@mysqlperformanceblog.com
   http://www.mysqlperformanceblog.com
   MySQL Consulting
    consulting@mysqlperformanceblog.com

More Related Content

What's hot

Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceMariaDB plc
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바NeoClova
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)Mydbops
 
MaxScale이해와활용-2023.11
MaxScale이해와활용-2023.11MaxScale이해와활용-2023.11
MaxScale이해와활용-2023.11NeoClova
 
Replication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTIDReplication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTIDMydbops
 
MySQL InnoDB Cluster and Group Replication in a Nutshell: hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a Nutshell:  hands-on tutorialMySQL InnoDB Cluster and Group Replication in a Nutshell:  hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a Nutshell: hands-on tutorialFrederic Descamps
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialJean-François Gagné
 
MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB OptimizationJongJin Lee
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsFederico Razzoli
 
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxKeepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxNeoClova
 
MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼NeoClova
 
MySQL InnoDB Cluster and Group Replication in a Nutshell
MySQL InnoDB Cluster and Group Replication in a NutshellMySQL InnoDB Cluster and Group Replication in a Nutshell
MySQL InnoDB Cluster and Group Replication in a NutshellFrederic Descamps
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기NeoClova
 
MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바NeoClova
 
Maxscale_메뉴얼
Maxscale_메뉴얼Maxscale_메뉴얼
Maxscale_메뉴얼NeoClova
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQLMydbops
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PGConf APAC
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 

What's hot (20)

Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performance
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)
 
MaxScale이해와활용-2023.11
MaxScale이해와활용-2023.11MaxScale이해와활용-2023.11
MaxScale이해와활용-2023.11
 
Replication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTIDReplication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTID
 
Automated master failover
Automated master failoverAutomated master failover
Automated master failover
 
MySQL InnoDB Cluster and Group Replication in a Nutshell: hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a Nutshell:  hands-on tutorialMySQL InnoDB Cluster and Group Replication in a Nutshell:  hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a Nutshell: hands-on tutorial
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 
MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB Optimization
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
 
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxKeepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
 
MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼
 
MySQL InnoDB Cluster and Group Replication in a Nutshell
MySQL InnoDB Cluster and Group Replication in a NutshellMySQL InnoDB Cluster and Group Replication in a Nutshell
MySQL InnoDB Cluster and Group Replication in a Nutshell
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
 
MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바
 
Maxscale_메뉴얼
Maxscale_메뉴얼Maxscale_메뉴얼
Maxscale_메뉴얼
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 

Viewers also liked

MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMark Swarbrick
 
浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook晓 周
 
MySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerMySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerFromDual GmbH
 
MySQL Performance Tuning Variables
MySQL Performance Tuning VariablesMySQL Performance Tuning Variables
MySQL Performance Tuning VariablesFromDual GmbH
 
MySQL Performance Tuning
MySQL Performance TuningMySQL Performance Tuning
MySQL Performance TuningFromDual GmbH
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practiceswebhostingguy
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning晓 周
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLZendCon
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MYXPLAIN
 
MySQL查询优化浅析
MySQL查询优化浅析MySQL查询优化浅析
MySQL查询优化浅析frogd
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance TuningMark Swarbrick
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesIsaac Mosquera
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsOSSCube
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)Aurimas Mikalauskas
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuningPhilip Zhong
 

Viewers also liked (19)

Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
 
浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook
 
MySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerMySQL Performance Tuning für Entwickler
MySQL Performance Tuning für Entwickler
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
MySQL Performance Tuning Variables
MySQL Performance Tuning VariablesMySQL Performance Tuning Variables
MySQL Performance Tuning Variables
 
MySQL Performance Tuning
MySQL Performance TuningMySQL Performance Tuning
MySQL Performance Tuning
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQL
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
 
MySQL查询优化浅析
MySQL查询优化浅析MySQL查询优化浅析
MySQL查询优化浅析
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuning
 

Similar to MySQL Server Settings Tuning

Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningSeveralnines
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
U C2007 My S Q L Performance Cookbook
U C2007  My S Q L  Performance  CookbookU C2007  My S Q L  Performance  Cookbook
U C2007 My S Q L Performance Cookbookguestae36d0
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourWim Godden
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Wim Godden
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialWim Godden
 
MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011Graham Weldon
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling PresentationTommy Falgout
 
MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017Ivan Zoratti
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB plc
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 
IT Made Me Virtualize Essbase and Performance Sucks
IT Made Me Virtualize Essbase and Performance SucksIT Made Me Virtualize Essbase and Performance Sucks
IT Made Me Virtualize Essbase and Performance SucksUS-Analytics
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedEqunix Business Solutions
 

Similar to MySQL Server Settings Tuning (20)

Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
U C2007 My S Q L Performance Cookbook
U C2007  My S Q L  Performance  CookbookU C2007  My S Q L  Performance  Cookbook
U C2007 My S Q L Performance Cookbook
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011
 
Performance tuning in sql server
Performance tuning in sql serverPerformance tuning in sql server
Performance tuning in sql server
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
 
Running MySQL on Linux
Running MySQL on LinuxRunning MySQL on Linux
Running MySQL on Linux
 
ESX performance problems 10 steps
ESX performance problems 10 stepsESX performance problems 10 steps
ESX performance problems 10 steps
 
MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 
IT Made Me Virtualize Essbase and Performance Sucks
IT Made Me Virtualize Essbase and Performance SucksIT Made Me Virtualize Essbase and Performance Sucks
IT Made Me Virtualize Essbase and Performance Sucks
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

MySQL Server Settings Tuning

  • 1. MySQL Server Settings Tuning Peter Zaitsev, co-founder, Percona Ltd April 23-26 2007
  • 2. About Speaker  Peter Zaitsev  Co-Founder at Percona Ltd, - Consulting company specializing in MySQL and LAMP Performance  Founder http://www.mysqlperformanceblog.com  Spent 4.5 years with MySQL AB, - High Performance Group, Manager - Performance related Support, Development, Consulting etc  Have designed and implemented numerous MySQL based projects
  • 3. About Presentation  What should you consider while tuning MySQL Server settings ?  How much improvement to inspect ?  What things to look at while setting various settings ?  Assume you're familiar with MySQL at some level
  • 4. Things to consider while tuning  Settings are workload specific There is no such thing as optimal config for 16GB of memory  Storage Engine choice or mix is important  Few settings depend on your OS and Hardware
  • 5. Approaching tuning  You just need to get few of them right for decent performance Rest are very specific and give hard to notice improvements  Some settings affect MySQL Behavior and data safety, be careful  Many settings can be set on connection basics, use it.  Optimize queries first or you may need to revisit your settings.
  • 6. Typical mistakes  Running in MySQL default settings Unless you're running it on laptop to store your DVD collection data  Using someone elses my.cnf file without checking if it matches your needs.  Setting large global values if only one/two queries need them. Instead you can do: SET sort_buffer_size=128000000; <run query> SET sort_buffer_size=DEFAULT
  • 7. What information do we have available ?  SHOW STATUS  SHOW INNODB STATUS  Operating System monitoring commands vmstat iostat mpstat
  • 8. Allocating memory  Allocating more memory to MySQL Server often improves performance  But Allocating too much memory may kill performance and stability  Watch out for Swapping Look for swap IO rather than simple used swap space Running out of address space on 32bit systems Make sure OS and MySQL Server are both 64bit
  • 9. Fighting Swapping  Some OS would swap even when enough memory is available Problems balancing IO cache vs Swapping  --memlock – lock MySQL Server in memory can be dangerous  Tune VM subsystem to use swap only as last resort echo 1 > /proc/sys/vm/swappiness  If using Innodb on Linux try using direct IO --innodb_flush_method=O_DIRECT
  • 10. Know the unit in which variable is set  table_cache=128M Wrong – table cache is measured in entries  key_buffer_size=1024 Wrong again, Key buffer should be specified in bytes  innodb_max_dirty_pages_pct=8G This one is set in percents
  • 11. Know locality and allocation pattern  key_buffer_size Global, shared by all threads  sort_buffer_size Allocated for the thread once sorting needs to be done  read_buffer_size Allocated all at full size, even if smaller is enough Overly large values may slow things down larger allocations typically done from OS  tmp_table_size Specifies maximum size, will grow to this size as needed no performance penalty for setting high.
  • 12. Lets get to details
  • 13. Looking at SHOW STATUS  SHOW GLOBAL STATUS shows global server status – good for understanding the load The only one available in MySQL 4.1 and below  SHOW LOCAL STATUS is great for query/transaction profiling Available since MySQL 5.0 SHOW STATUS now defaults to this Some variables are global only Will still be shown in SHOW STATUS output  mysqladmin extended -i100 -r Great to sample what is happening with MySQL Server Now
  • 14. SHOW STATUS  Aborted_clients Usually no need to worry – many programs do not close connection properly  Aborted_connects May mean authentication failure, network timeout or other error Worth to look at as may cause host blocked out --max_connect_errors=100000 Beware password break attempts  Binlog_cache_disk_use/Binlog_cache_use how frequently bin log cache size has to spill to the disk increase --binlog_cache_size if a lot
  • 15. Com_XXX  Understanding server load in terms of queries  Queries can vary in complexity quite a lot  Good to catch use mistakes Unintended LOCK TABLES with Innodb tables Com_lock_tables Too many ROLLBACKs Com_rollback Prepared Statements used only once Com_stmt_prepare = Com_stmt_execute
  • 16. Temporary Objects  Created_tmp_tables Temporary tables can often be avoided by query optimization  Created_tmp_disk_tables Not enough memory is allocated – increase tmp_table_size and max_heap_table_size Temporary table can't be created in memory Typically because of BLOB/TEXT columns required Can be placed on tmpfs for better performance --tmpdir=/dev/shm on Linux Watch out for overflow
  • 17. Handler_XXX  Represent what is happening with server on storage engine layer (better)  Does not make a difference between different rows and different engines  No way to see covering index usage  Handler_read_key, Handler_read_next - indexed accesses  Handler_read_rnd, Handler_read_rnd_next - full table scans Temporary tables also counted here
  • 18. Innodb_XXX  A lot of Innodb status variables added in MySQL 5.0  Mostly copied from SHOW INNODB STATUS  Not made per-thread counters yet  Innodb_data_reads, Innodb_data_writes Physical IO to Innodb tablespace files Use to tune innodb_buffer_pool_size  Innodb_buffer_pool_pages_misc - how much memory Innodb locks, adaptive hash indexes, insert buffer take  Innodb_log_waits Waits happen when innodb_log_buffer_size is not large enough
  • 19. Innodb_XXX  Innodb row operations (Innodb_rows_read etc) can be used to view Innodb activity on row level  Innodb_row_lock_XXX - information about innodb lock waits and timing.  Innodb_data_pending_XXX, Innodb_os_log_pending_XXX Pending IO operations. IO is overloaded if they stay high
  • 20. Key Cache Info  Key_blocks_used / Key_blocks_unused How much of your key_buffer is used ? key_blocks_used should be key_blocks_ever_used Helps not to set key buffer higher than needed  Key_read_requests, Key_reads, Key_write_requests, Key_writes How good is your key buffer usage ? Look at amount of reads/writes which pass to IO subsystem Key Cache hit ratio alone is useless - checking how it is affected by buffer sizing is helpful As hit ratio does not change much any more it may be no point increasing it further
  • 21. Connections and Tables  Max_used_connections If matches max_connections you may had run out of connections  Open_files - check not to run out of limit  Open_tables – how table cache is used  Opened_tables -check how quickly it growths Growths due to explicit temporary tables Growths if it is not large enough. Adjust –table-cache variable Make sure --open-file-limit is large enough
  • 22. Query Cache Status  Qcache_hits How frequently query was used from query cache Com_selects is not incremented in this case  Qcache_inserts Query stored in query cache – misses and overhead  Qcache_free_memory Free/Unused memory in query cache Often query cache can use limited memory because of invalidation  Qcache_lowmem_prunes Not enough memory or too fragmented – remove some queries
  • 23. Select Information  Select_full_join Joins without indexes. Bad and dangerous  Select_range Range scan queries. No problem with these  Select_range_check Usually queries worth looking to optimize. No good index.  Select_scan Full Table Scan. Small or Large
  • 24. Sorting  Sort_merge_passes Consider increasing sort_buffer_size if it is high  Sort_range Sorting of ranges  Sort_scan Sorting full table scans  Sort_rows How many rows sorted per second
  • 25. Table locks information  Table_locks_immediate Table locks granted without waiting  Table_locks_waited Table locks which had to be waited for  Helpful to find out if Table locks are problem  Do not show how long wait was for Rare but long table locks may be too bad already
  • 26. Threads Information  Threads_cached entries currently used in threads_cache  Threads_connected current number of connected threads. Make sure you have some gap to max_connections  Threads_created threads_cache “misses” increase threads_cache if it is high  Threads_running Amount of threads running at the same time Keep it reasonable Waiting on table locks, row level locks, IO is also counted as running
  • 27. SHOW INNODB STATUS - Mutexes  Innodb Mutexes information  Helpful to tune --innodb_thread_concurrency If number of OS Waits or Spinlocks is high it is often worth to increase it What is “High” ? More than 1000 OS Waits/sec More than 100.000 spin rounds/sec O S W AI AR R AY I FO :r T N eser i count419870,si vaton gnalcount418867 M ut spi w ais 1110481,r ex n t ounds 3157468,O S w ais 74647 t RW - ed ns t shar spi 650429,O S w ais 320432;R W - exclspi 44900,O S w ais 20070 ns t
  • 28. Purge activity and memory usage  “Total memory allocated 13867961114; in additional pool allocated 1048576” Tune additional pool size Check how much memory Innodb really allocated May be more than you think due to Innodbs own table cache  “Trx id counter 0 458146886 Purge done for trx's n:o < 0 458146877 undo n:o < 0 History list length 31 Total number of lock structs in row lock hash table 0” Check check how purge is happening set innodb_max_purge_lag if it is unable to keep up Will slow updates down
  • 30. Memory Settings - Global  key_buffer_size Used by MyISAM tables to cache Index only, not data 30% of memory for MyISAM only system 4GB limit per key buffer, can have multiple of these MyISAM tables used for temporary tables anyway  innodb_buffer_pool_size Used by Innodb tables 70% of memory for Innodb only system Innodb performance is very critical to this setting  query_cache_size Set if using query cache
  • 31. Memory Settings - Local  read_buffer_size, read_rnd_buffer_size sequential read buffers used by MyISAM and some others Allocated when needed. 1M/4M typically good to start  sort_buffer_size buffer used for sorting. Increase if a lot of large sorts are done  tmp_table_size Maximum size of in-memory table allowed (used by complex queries) May need more than one temporary table per query max_heap_table_size limit is also used
  • 32. Other caches  table_cache Number of tables mysql will keep open Allows to avoid reopens (expensive for some storage engines) Needs file handlers for many storage engines Does not affect Innodb Internal table cache. Set at least 1024  thread_cache Number of threads MySQL can cache and reuse Set so threads_created is low 32-64 is typical good value.
  • 33. Innodb Settings  innodb_log_file_size Very important for write performance, reduce dirty buffer flushes Tradeoff between performance and recovery speed 128-512M are generally good value.  innodb_thread_concurrency Number of threads which can be in Innodb kernel at once Higher values – better resource usage but beware contension 2*(NumCPUs+Num_disks) is theoretically good value Practical values may be much lower.  innodb_log_buffer_size 1-4MB is enough unless you're using large blobs.
  • 34. More Innodb Settings  innodb_flush_log_at_trx_commit Default behavior is to flush log to the disk on each transaction commit This includes update statements outside of transactions Often unwanted, especially for MyISAM->Innodb migrations Use value 2 (flush to OS cache) or 0 (do not flush at all) Innodb flushes logs once per second anyway  innodb_flush_method O_DIRECT to avoid double buffering  innodb_locks_unsafe_for_binlog Reduce locks if not using binary logs
  • 35. Some special tuning settings  myisam_sort_buffer_size Used for rebuilding MyISAM indexes – ALTER, REPAIR, OPTIMIZE, LOAD DATA.  max_length_for_sort_data Store row data instead of row pointer in the sort file Can help performance or can kill performance  myisam_stats_method Helps to fine tune MySQL optimizer plan selection nulls_unequal – count all nulls as different values (default) nulls_equal - count all nulls as same value
  • 36. Time for questions  Ask your questions now or catch me later on the conference  pz@mysqlperformanceblog.com  http://www.mysqlperformanceblog.com  MySQL Consulting consulting@mysqlperformanceblog.com