Monday, September 15, 14

Similar documents
MySQL Performance Tuning 101

MySQL Server Performance Tuning 101

Reading MySQL fingerprints

MySQL Performance Tuning

How to Stop Hating MySQL: Fixing Common Mistakes and Myths

The MySQL Query Cache

Optimizing MySQL Configuration. Peter Zaitsev,CEO Technical Webinars Series March 2012

MySQL Performance Tuning 101

MySQL Architecture and Components Guide

Optimizing MySQL Configuration

Tips & Tricks on Tuning MySQL Performance

Optimizing MySQL Configuration. Peter Zaitsev,CEO OSCON 2012, Portland,OR July 20, 2012

System Characteristics

OPTIMIZING MYSQL SERVER ON SUN X64 SERVERS AND STORAGE. Luojia Chen, ISV Engineering. Sun BluePrints Online February 2008

Optimizing MySQL Configuration. Peter Zaitsev,CEO Percona Live, Washington DC 11 January 2012

MySQL Performance Optimization and Troubleshooting with PMM. Peter Zaitsev, CEO, Percona

Pandora FMS Administrator Manual MySQL Server Monitoring in Unix

MySQL 5.1 Configuration Files & Options Part II. Presented by: Sheeri K. Cabral

InnoDB: What s new in 8.0

15 practical examples of using commands Mysqladmin to administer a MySQL server Wednesday, 17 March :23

InnoDB: Status, Architecture, and Latest Enhancements

Written by Marco Tusa Wednesday, 23 February :03 - Last Updated Sunday, 18 August :39

InnoDB: What s new in 8.0

LAMP Tuning. Sean Walberg Network guy, server ninja

Manual Mysql Query Cache Hit Rate 0

MySQL Performance Troubleshooting

Capacity metrics in daily MySQL checks. Vladimir Fedorkov MySQL and Friends Devroom FOSDEM 15

MySQL 8.0: Atomic DDLs Implementation and Impact

What s New in MySQL 5.7 Geir Høydalsvik, Sr. Director, MySQL Engineering. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

MySQL Performance Optimization and Troubleshooting with PMM. Peter Zaitsev, CEO, Percona Percona Technical Webinars 9 May 2018

What's new in MySQL 5.5? Performance/Scale Unleashed

ScaleArc Performance Benchmarking with sysbench

Optimizing BOINC project databases

Inside the PostgreSQL Shared Buffer Cache

<Insert Picture Here> Looking at Performance - What s new in MySQL Workbench 6.2

Innodb Performance Optimization

Switching to Innodb from MyISAM. Matt Yonkovit Percona

Effective Testing for Live Applications. March, 29, 2018 Sveta Smirnova

MySQL Performance Improvements

How to Fulfill the Potential of InnoDB's Performance and Scalability

InnoDB Scalability Limits. Peter Zaitsev, Vadim Tkachenko Percona Inc MySQL Users Conference 2008 April 14-17, 2008

MySQL Configuration Settings

Here, we consider Database bottleneck as a problem and provide solution for some of common problems.

1-2 Copyright Ó Oracle Corporation, All rights reserved.

MySQL Performance Tuning

Delegates must have a working knowledge of MariaDB or MySQL Database Administration.

Introduction to MySQL Cluster: Architecture and Use

Wednesday, May 15, 13

Innodb Architecture and Performance Optimization

RAID in Practice, Overview of Indexing

Backup Strategies with MySQL Enterprise Backup

How To Rock with MyRocks. Vadim Tkachenko CTO, Percona Webinar, Jan

Kathleen Durant PhD Northeastern University CS Indexes

FS Consistency & Journaling

mysql Certified MySQL 5.0 DBA Part I

Best Practices for Database Administrators

MySQL 5.6: Advantages in a Nutshell. Peter Zaitsev, CEO, Percona Percona Technical Webinars March 6, 2013

Everything You Need to Know About MySQL Group Replication

Build ETL efficiently (10x) with Minimal Logging

Why Choose Percona Server For MySQL? Tyler Duzan

MySQL Performance Tuning

Avoiding Common (but Deadly) MySQL Operations Mistakes

Rdb features for high performance application

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Mastering the art of indexing

Scale out Read Only Workload by sharing data files of InnoDB. Zhai weixiang Alibaba Cloud

<Insert Picture Here> MySQL Cluster What are we working on

The Right Read Optimization is Actually Write Optimization. Leif Walsh

What's New in MySQL 5.7?

MySQL Replication Update

OPS-23: OpenEdge Performance Basics

Jyotheswar Kuricheti

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Today s Class. Faloutsos/Pavlo CMU /615

BigTable. Chubby. BigTable. Chubby. Why Chubby? How to do consensus as a service

Innodb Architecture and Performance Optimization. Peter Zaitsev, CEO Percona 25 September 2017

Jens Bollmann. Welcome! Performance 101 for Small Web Apps. Principal consultant and trainer within the Professional Services group at SkySQL Ab.

Ext3/4 file systems. Don Porter CSE 506

Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

Innodb Architecture and Internals. Peter Zaitsev Percona Live, Washington DC 11 January 2012

State of the Dolphin Developing new Apps in MySQL 8

ò Very reliable, best-of-breed traditional file system design ò Much like the JOS file system you are building now

Chapter 8: Working With Databases & Tables

16 Sharing Main Memory Segmentation and Paging

PolarDB. Cloud Native Alibaba. Lixun Peng Inaam Rana Alibaba Cloud Team

Manual Trigger Sql Server 2008 Update Inserted Rows

Ext4 Filesystem Scaling

CS510 Operating System Foundations. Jonathan Walpole

Percona Live September 21-23, 2015 Mövenpick Hotel Amsterdam

Build ETL efficiently (10x) with Minimal Logging

MySQL Database Scalability

Memory Management. Goals of Memory Management. Mechanism. Policies

Lesson 9 Transcript: Backup and Recovery

Database Applications (15-415)

Lock Tuning. Concurrency Control Goals. Trade-off between correctness and performance. Correctness goals. Performance goals.

#MySQL #oow16. MySQL Server 8.0. Geir Høydalsvik

How TokuDB Fractal TreeTM. Indexes Work. Bradley C. Kuszmaul. MySQL UC 2010 How Fractal Trees Work 1

1Z Oracle. MySQL 5 Database Administrator Certified Professional Part I

OS and Hardware Tuning

Performance Monitoring

Transcription:

1 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

MySQL Server Performance Tuning 101 Ligaya Turmelle Principle Technical Support Engineer - MySQL @lig ligaya.turmelle@oracle.com We will be covering some of the most basic and common areas you should consider. Who is on 5.6? 5.5? 5.1? 5.0? lower?

THE FOLLOWING IS INTENDED TO OUTLINE OUR GENERAL PRODUCT DIRECTION. IT IS INTENDED FOR INFORMATION PURPOSES ONLY, AND MAY NOT BE INCORPORATED INTO ANY CONTRACT. IT IS NOT A COMMITMENT TO DELIVER ANY MATERIAL, CODE, OR FUNCTIONALITY, AND SHOULD NOT BE RELIED UPON IN MAKING PURCHASING DECISIONS. THE DEVELOPMENT, RELEASE, AND TIMING OF ANY FEATURES OR FUNCTIONALITY DESCRIBED FOR ORACLE'S PRODUCTS REMAINS AT THE SOLE DISCRETION OF ORACLE. 3 Copyright 2013, Oracle and/or its affiliates. All rights reserved. safe harbor - basically if I tell you about any upcoming products it is for informational purposes only. Oracle makes no guarantee.

MySQL in a Nutshell Worlds most popular open source database M of LAMP Main Site: mysql.com Developer Zone: dev.mysql.com OR mysql.org Downloads and Labs Manuals and Bugs Forums and Worklogs 4 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Laying the Foundation 5 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Step 0 General No easy answers Benchmark and test Under allocate 6 Copyright 2013, Oracle and/or its affiliates. All rights reserved. This is a soft skill with no absolute answers Change 1 thing at a time Under allocate rather then over allocate or you swap There is such a thing as over-tuning the system

Step 0 The Server OS Network Filesystem 7 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Storage, swappiness, scheduler

Step 0 The MySQL Server Optimize the queries Database Schema 8 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Slow query log, EXPLAIN, Indexing strategies

MySQL and Memory Global Server Start Large Values Allocated Once Per Connection As Needed Small Values Allocated 0-N Times Global Memory + (Max_Connections * Session Buffers) 9 Copyright 2013, Oracle and/or its affiliates. All rights reserved. To tune the server you have to understand how MySQL uses memory.

Current Settings mysql> SHOW GLOBAL VARIABLES; 10 Copyright 2013, Oracle and/or its affiliates. All rights reserved. mysql> SHOW GLOBAL VARIABLES; +--------------------------------------------+------------------ Variable_name Value +--------------------------------------------+------------------ auto_increment_increment 1 auto_increment_offset 1 autocommit ON automatic_sp_privileges ON back_log 80 basedir /usr big_tables OFF bind_address * binlog_cache_size 32768 binlog_checksum CRC32 binlog_direct_non_transactional_updates OFF binlog_format STATEMENT binlog_max_flush_queue_time 0 binlog_order_commits ON binlog_row_image FULL binlog_rows_query_log_events OFF binlog_stmt_cache_size 32768 What are the current settings for the server?

Current Settings my.cnf / my.ini [client] socket = /var/run/mysqld/mysql.sock [mysqld] # These settings are for this specific box. server-id = 1 log-bin = /var/lib/mysql/binlogs/xxxxxxxx-bin pid-file = /var/run/mysqld/mysql.pid socket = /var/run/mysqld/mysql.sock performance_schema max_connections = 200 # The ft_min_word_len is set to 3 instead of the default # 3 letter acronyms in the tables with full text ft_min_word_len = 3 11 Copyright 2013, Oracle and/or its affiliates. All rights reserved. everything else

Anything Else? RAM? Dedicated? 32 or 64 bit OS? 32 or 64 bit MySQL? Workload? Storage Engines? 12 Copyright 2013, Oracle and/or its affiliates. All rights reserved. 32 bit addressing limit read/write heavy? short or report queries Mostly InnoDB? MyISAM? Memory? Etc.

Current Status mysql> SHOW GLOBAL STATUS; mysql> show global status; +--------------------------------------+---------------+ Variable_name Value +--------------------------------------+---------------+ Aborted_clients 9363 Aborted_connects 15925 Binlog_cache_disk_use 15684 Binlog_cache_use 272758675 Bytes_received 1219816389366 Bytes_sent 5227022143540 Com_admin_commands 12803263 Com_assign_to_keycache 0 Com_alter_db 0 Com_alter_db_upgrade 0 Com_alter_event 0 Com_alter_function 0 Com_alter_procedure 0 Com_alter_server 0 Com_alter_table 37 Com_alter_tablespace 0 Com_analyze 0 13 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Counters - what is done, not what we think is done. Issued twice to find the Delta. Ok during normal operations but best during peak times.

DANGER - Math Ahead! 14 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Finding the Delta Uptime - seconds Ex: 8249391 sec = ~2291.5 hrs = ~95.5 days Find your rate of change 15 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Example 16 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Time to Start 17 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

GENERAL INFO 18 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

COM_* Counters Each command Used to calculate the Delta 19 Copyright 2013, Oracle and/or its affiliates. All rights reserved. What you are actually doing. Com_select 1530076294 Com_set_option 18004985 Com_signal 0 Com_show_authors 0 Com_show_binlog_events 0 Com_show_binlogs 27498 Com_show_charsets 1 Com_show_collations 39 Com_show_contributors 0 Com_show_create_db 3 Com_show_create_event 0 Com_show_create_func 1120 Com_show_create_proc 14499 Com_show_create_table 183538 Com_show_create_trigger 0 Com_show_databases 435 Com_show_engine_logs 0 Com_show_engine_mutex 0 Com_show_engine_status 1180106

Et Al. Connections Queries Questions Slow_queries Sort_merge_passes 20 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Connections - # of attempts to connect - successful or not Queries - # of statements executed - including stored procedures Questions - # of statements sent to the server by clients and executed Slow_queries - # of queries that took longer then long_query_time sec to run Sort_merge_passes - # of merge passes that sort algorithm had to do

INNODB BASICS 21 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Starting in 5.5 this is the default storage engine

How is InnoDB doing? Space Innodb_buffer_pool_pages_data Innodb_buffer_pool_pages_total Innodb_buffer_pool_pages_free 22 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Pages data number of pages containing data (clean and dirty) - Pages total total size in pages (innodb_page_size compiled in, default is 16KB) - Pages_free some are fine but if you see a lot for a while, you over allocated - Dirty page = a page that has changes in the buffer that has been saved to the log files

How is InnoDB doing? Efficiency Innodb_buffer_pool_read_requests Innodb_buffer_pool_reads Formula: 1 - (Innodb_buffer_pool_read / Innodb_buffer_pool_read_requests) = buffer pool hit ratio 23 Copyright 2013, Oracle and/or its affiliates. All rights reserved. reads - reads from disk read_requests - disk or memory

innodb_buffer_pool_size Global Caches data and indexes Larger values reduces IO Self-contained 80% max 24 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Size in bytes - InnoDB uses clustered indexes remember - Larger the value the more it acts like an in-memory database. - Handles and buffers *everything* for itself - Setting it too high can lead to swap === bad

innodb_log_file_size Size of file on disk Larger the file, the less checkpoint activity Size for each log file Max combined log file size 4G <= 5.5 5.6 = 512GB Larger the log file longer recover time 25 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Less checkpoint activity means less IO - Typically there are 2 log files in a log group (innodb_log_files_in_group) - crash recovery code was optimized in 5.5. So the recovery time will be significantly lower in 5.5 then in 5.1. - 5.5 Start test using the full 4G and modify as needed for your requirements and limitations.

innodb_log_buffer_size Buffer for writing to log files on disk Large transactions? Yes - increasing may help with IO Default is 8MB 26 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - If you have large transactions, try to have them fit in here. This reduces the need to write the log to disk before the transactions commit.

innodb_file_per_table.ibd files Default: Off <= 5.6.5 > On Easier to reclaim space TRUNCATE for a table is faster Can monitor table size at the file system Can store specific tables on different storage devices (5.6) Transportable tablespaces 27 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - for each newly created table the data and indexes will be placed in a separate ibd file rather then in the shared tablespace - reclaiming space from the shared tablespace is not trivial. - reasons for separate devices: IO Optimization, space management, backup purposes - Transportable tablespaces allow the moving of the.ibd files from 1 database server to another. Manual has limitations and usage notes as well as a page covering how to do it.

MyISAM 28 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

How is MyISAM doing? Space Key_blocks_unused Formula: key_buffer_size - (Key_blocks_unused * key_cache_block_size) = amount actually in use Key_blocks_used High water mark 29 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Block size can be found in key_cache_block_size - Key_blocks_used indicates the max number of blocks that have ever been in use at one time.

How is MyISAM doing? Efficiency Key_read_requests Key_reads Formula: Key_reads/Key_read_requests = key cache miss rate Key_write_requests Key_writes 30 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Key_read_requests requests to read a key block - Key_reads number of physical reads from disk. Large value may mean your key_buffer_size is too small * Key cache miss rate the lower the value, the better - Key_write_requests # of requests to write a key block - Key_writes - # of physical writes of a key block to disk

How is MyISAM doing? Locking Table_locks_immediate Table_locks_waited 31 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - MyISAM uses table level locking. That means that every time you have to change it, the whole table will be locked for the duration. (Yes - concurrent inserts but that only works under specific circumstances (If a MyISAM table has no holes in the data file (deleted rows in the middle), an INSERT statement can be executed to add rows to the end of the table at the same time that SELECT statements are reading rows from the table.)) - Want to watch Table_locks_waited since this iterates every time you had to wait to get a table lock. If you have high values for this, and you do not use the MyISAM specific features, you may want to consider changing to another storage engine for better concurrency.

key_buffer_size AKA key cache Global Index blocks only 25% - maybe 32 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - The index blocks are buffered and shared by all threads. - MyISAM uses the OS file caching system to hold the data files. This means that we have to leave space for the OS file system otherwise we can start swapping. And swapping can be bad with MySQL. - For this reason, on a dedicated machine heavy on MyISAM, 25% of RAM is a place to start. Notes: - The maximum size is 4G for each key cache. - You can have more then one key cache see the manual for more information on that.

QUERY CACHE 33 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Ask if people understand how the query cache works. If they do not understand - explain it. Also explain that this can become a bottle neck for performance with high concurrency since it is single threaded.

How is the QC doing? Qcache_total_blocks Qcache_free_blocks Not what you think Qcache_lowmem_prunes 34 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Free_blocks think this would be a good thing, but isn t. The higher the value, the greater the fragmentation in the query cache. * As Qcache_free_blocks approaches Qcache_total_blocks/2 the more severe the fragmentation * To defragment the query cache use the FLUSH QUERY CACHE statement - lowmem prunes number of queries deleted from the QC because of low memory

How is the QC doing? Qcache_hits Qcache_inserts Qcache_not_cached Qcache_queries_in_cache 35 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

QC Data into Info Hit rate Higher the better Formula: Qcache_hits / (Qcache_hits + Com_select) = Query Cache Hit Rate Invalidating queries Bigger the diff - the better Comparison: Qcache_inserts << Com_select 36 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Keep in mind warming up the cache

- Minor side note - http://bugs.mysql.com/bug.php?id=38551 (5.1) Query cache mutex still acquired even with query cache size set to 0 query_cache_size Global Allocated all at once Default is disabled Default size 0 < 5.6.8 => 1M 37 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - The default of 0 disables the query cache. Generally speaking it is recommended that you start with the query cache off, and only if you think it can help you, do you turn it on. Be sure to check the performance of the system when you turn it on to verify that it does increase. There is potential for substantial performance improvement, but do not assume that it will happen. With some query cache configurations or server workloads, it is possible to see a performance decrease. Before 5.6.8 default size was 0 - now 1M with query_cache_type=0.

query_cache_type Global - but can be session 3 options 0 Off 1 On 2 On Demand Default: 1 < 5.6.8 => 0 38 Copyright 2013, Oracle and/or its affiliates. All rights reserved. 0 - Do not cache results or pull results from the QC 1 - Cache all you can unless told not to with SQL_NO_CACHE 2 - Cache only those queries that have SQL_CACHE Turning it Off (0) - now saves a significant amount of overhead since it will no longer try to acquire the query cache mutex at all. However that means you can not turn on the query cache at runtime (dynamically).

Gotcha! 39 Copyright 2013, Oracle and/or its affiliates. All rights reserved. The query cache size will still be allocated when the server starts up even if you have the type set to 0.

THREADS 40 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Threads Threads == Connection Thread Cache Threads_cached Threads_connected Threads_created Formula: Threads_created /Connections = Thread cache miss rate 41 Copyright 2013, Oracle and/or its affiliates. All rights reserved. This is more for those using an older system. - In regards to this discussion that is. - Thread cache * threads can be expensive to create and destroy for every connection. - explain how the thread cache works. (starts out empty and as new connections are made it checks the cache to see if one is there. If so it uses it. If not it makes a new thread. When done it puts the threads back into the thread cache until it has its max value. Watch Threads_created if large consider increasing the thread_cache

thread_cache_size Global but grows as needed Number to be cached until needed May increase performance with lots of new connections or may not Formula: 100 - ((Threads_created/Connections) * 100) = Thread cache efficiency 42 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Because of modern thread implementations be sure to test to see if you get any improvement.

SESSION LEVEL 43 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - These values should in the global scope be set to a small value since they are used for each session. Only if you have a session that is doing something out of the ordinary should you consider dynamically changing these values. Keep in mind that each query can potentially have 1 N instances of a session level buffer as well (think multiple temp tables), so if you increase these values for a specific session you have to be sure the space is available.

Temporary Tables max_heap_table_size Dynamic Sets maximum size of all MEMORY tables tmp_table_size Dynamic In-memory - MEMORY table Max size of internal in-memory temp tables Becomes on-disk MyISAM table 44 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Other reasons temp tables can automatically go to disk: * BLOB * column in a GROUP BY or DISTINCT clause larger than 512 bytes * any column larger than 512 bytes in the SELECT list, if UNION or UNION ALL is used

sort_buffer_size Dynamic Doing a sort - allocates a buffer this size Helps with ORDER BY and/or GROUP BY Watch Sort_merge_passes 45 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Whole buffer is allocated even if it is not used prior to 5.6.4

bulk_insert_buffer_size Dynamic Cache to assist with MyISAM bulk inserts Set to 0 to disable 46 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - Bulk inserts == INSERT SELECT, INSERT VALUES ( ), ( ), ( ), LOAD DATA INFILE when adding data to non-empty tables.

join_buffer_size Use with care Used for plain index scan range index scan joins that do not use indexes - full table scan One buffer for EACH full join between tables 47 Copyright 2013, Oracle and/or its affiliates. All rights reserved. - I am always hesitant to show this slide. I do not want people to think this can be used to help poorly optimized queries. Should be used as a band aid or if adding the appropriate indexes is not possible. Make it very large - and you may have to wait for the the allocation of the memory

Questions? 48 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Thank you for time and attention.

MySQL Server Performance Tuning 101 Ligaya Turmelle Principle Technical Support Engineer - MySQL @lig ligaya.turmelle@oracle.com https://joind.in/10284

50 Copyright 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12