SlideShare ist ein Scribd-Unternehmen logo
1 von 62
Downloaden Sie, um offline zu lesen
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
Installation, Configuration
and performance tuning
Mark Swarbrick
Principle Presales Consultant
MySQL Webinar Series 2/4
Program
Agenda
§  Hardware Specification
§  Setting up Replication
§  Performance tuning
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
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
decision. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole
discretion of Oracle.
Safe Harbor Statement
§  Hardware Specification
MySQL Hardware / Software Platforms
MySQL is supported on a variety of hardware /
software platforms:
Oracle Linux
Oracle Solaris
Red Hat
Canonical (Ubuntu)
SUSE
Debian
Microsoft Windows XP/Vista/7/2003/2008/2012/server
FreeBSD
HPUX
Other Linux – Fedora / OpenSUSE / CentOS etc
MySQL Hardware / Software Platforms
MySQL is supported on a variety of hardware /
software platforms:
X86
X86_64
X86_IA64
SPARC_32
SPARC_64
IBM Power5_64
PA-RISC 2.0
We will support with best efforts on other hardware platforms such
as ARM. For example MySQL Cluster compiled to run on a
raspberry pi!
Copyright Oracle Corporation 2014 | <date>8
Scaling on dense,
multi-core, multi-thread
servers
•  10s - 100GBs RAM
•  SSDs
Scale across cores
within a single instance
You can get a long
way with MySQL 5.6!
The Path to Scalability
Scaling-Up can take you a long way
MySQL Hardware / Software Platforms
Server:
Having the fastest CPU is still beneficial. Can use as many as 32 cores!
OS choice and tuning is important, but Linux / Solaris or windows all give good
performance.
Storage:
Don’t use slow disks
Flash memory (SSD etc) helps for random access (reads are the most costly)
FS is important – ZFS, UFS, QFS, VxFS, EXT3, EXT4 XFS etc..
Use of O_Direct if O/S supports it
Don’t forget the network! Faster is better!
Hardware: The Perfect MySQL Server
•  The more cores the better (especially for 5.5 and later)
•  x86_64 - 64 bit for more memory is important
–  The more the better
•  Fast HD (10-15k RPM SATA) or NAS/SAN……
–  RAID 10 for most, RAID 5 OK if very read intensive
–  Hardware RAID battery backed up cache critical!
–  More disks are always better! - 4+ recommended, 8-16 can increase IO
•  …Or SSD (for higher throughput)
–  Intel, Fusion-IO good choices; good option for Slaves
•  At least 2 x NICs for redundancy
•  Slaves should be as powerful as the Master
§  Replication
MySQL HA Solutions
Note that MySQL Fabric is currently at Release Candidate Status
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13
Why Replicate?
§  Duplicates database from a “master” to a “slave”
§  Redundant copies of the data provide foundation for High Availability
§  Scale out by distributing queries across the replication cluster
Master
Slaves
Web / App Servers
Writes & Reads Reads
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14
Slave
Database
§  Session thread: processes queries from
the application – writes data to master
database & associated events to binary
log
§  Dump thread: reads events from binary
log and sends them to a slave
§  I/O thread: receives replication events
and stores them in slave’s relay log
§  SQL thread: reads replication events from
slave’s relay log and applies them to
slave database
Session
Binary
Log
Master
Database
Dump I/O
Relay
Log
SQL
Replication Workflow
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15
ReplicationReplication Solutions
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16
Async Replication
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17
Semi-sync Replication
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18
MySQL 5.6: Transforming Replication
•  Multi-Threaded Slaves
•  Binary Log Group Commit
•  Optimized Row-Based Replication
PERFORMANCE
•  Global Transaction Identifiers
•  Replication Failover & Admin Utilities
•  Crash Safe Slaves & Binlogs
FAILOVER & RECOVERY
•  Replication Event Checksums
DATA INTEGRITY
•  Replication Utilities
•  Time-Delayed Replication
•  Remote Binlog Backup
•  Informational Log Events
•  Server UUIDs
DEV/OPS AGILITY
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19
5x Higher Performance with MySQL 5.6
0 5 10
QPS 58.11 144.4 282.53
0
50
100
150
200
250
300
QueriesperSecond
Worker Threads
Multi-Threaded Slave Performance
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20
Master
GTID=123456
GTID=123456
GTID=123456 GTID=123456
Global Transaction Identifiers
§  Simple to track & compare replication across the farm
§  Unique identifier for each transaction written to the Binlog
§  Automatically identify the most up-to-date slave for failover
§  Deploy n-tier replication hierarchies
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21
Time Delayed Replication - configuring
slave2> CHANGE MASTER TO
-> MASTER_HOST = 'localhost‘,
-> MASTER_PORT = 3306,
-> MASTER_USER = 'repl_user‘,
-> MASTER_PASSWORD = ‘sun123!‘,
-> MASTER_DELAY = 600;
slave2> START SLAVE;
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22
MySQL Utilities
§  Automate common Dev/Ops tasks
§  Replication: provisioning, testing, monitoring and failover
§  Database comparisons: consistency checking
§  Database administration: users, connections, tables, etc
§  New utilities in development, i.e. log analysis
§  Implemented as Python scripts, plug-in for MySQL Workbench
§  Extensible to include custom scripting
§  Resources: Documentation & Community Forum
§  http://dev.mysql.com/doc/workbench/en/mysql-utils-man.html
§  http://forums.mysql.com/list.php?155
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23
Utility Workflow for Replication
§  Replicate: Initiates Replication to the new slave
§  Check: Validates the replication configuration and operation
§  Show: Display Replication topology
§  Fail-Over & Admin: Detects and failovers (or switches) from master to
slave. Status monitoring
Check Show
Fail-Over
& AdminReplicate
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24
mysqlreplicate Utility
§  Starts replication process
§  User can provide login and
connection parameters for the master
§  Configurable replication start points:
current position / GTID, specific
event, entire binlog
§  Checks storage engine compatibility
§  Enables fast, simple scaling
New Slave
Login,
Connection &
Start-Point
Master
Replication configured,
binlog position
Repl
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25
mysqlreplicate example
$ mysqlreplicate --master=root:billy@localhost:3306
--slave=root:billy@localhost:3307
# master on localhost: ... connected.
# slave on localhost: ... connected.
Repl
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26
mysqlrplshow Utility
§  Discovers & displays replication
topology
§  Shows slaves attached to each
master
§  Labels each slave with hostname
and port number
§  Displays multiple topologies,
including hierarchical and circular
§  Displays results in a graph or list
§  Enables user to monitor topology
on-demand
$ mysqlrplshow --master=root@localhost:3311
# master on localhost: ... connected.
# Finding slaves for master: localhost:3311
# Replication Topology Graph::
localhost:3306 (MASTER)
|
+--- localhost:3307 - (SLAVE)
|
+--- localhost:3308 - (SLAVE + MASTER)
|
+--- localhost:3313 - (SLAVE)
Show
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27
mysqlrplcheck Utility
§  Tests replication on master and slave to ensure proper configuration of
replication
§  Checks binlog is enabled and displays any configured exceptions
§  Checks slave access and privileges to master
§  Checks slave connection status
§  Checks for conflicts in master.info file (or mysql.slave_master_info table)
§  Checks storage engine compatibility
§  Tests executed sequentially
§  Reports status of each test
§  Simple verification of deployment & fast fault resolution
Check
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28
mysqlrplcheck example
$ mysqlrplcheck --master=root@host1:3310
--slave=root@host2:3311
# master on host1: ... connected.
# slave on host2: ... connected. Test Description Status
-------------------------------------------------------------
Checking for binary logging on master [pass]
Are there binlog exceptions? [pass]
Replication user exists? [pass]
Checking server_id values [pass]
Is slave connected to master? [pass]
Check master information file [pass]
Checking InnoDB compatibility [pass]
Checking storage engines compatibility [pass]
Checking lower_case_table_names settings [pass]
Checking slave delay (seconds behind master) [pass]
# ...done.
Check
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29
Replication Administration Utility
§  Perform switchover to eliminate
downtime during planned maintenance
§  Start and stop slaves
§  Slave discovery & monitoring
§  Slave status, thread status
§  Replication processing, including any lag
§  Configure slave promotion policies
Master
Slaves
Administration
Utility
Status &
Switchover
Admin
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30
Planned switchover to new master with
mysqlrpladmin
$ mysqlrpladmin --master=root@rod:3306
--slaves=root@jane:3306,root@jane:3307,root@freddy:3306
--new-master=root@jane:3306 --demote-master switchover
# Performing switchover from master at rod:3306 to slave at jane:3306.
# Checking candidate slave prerequisites.
# Waiting for slaves to catch up to old master.
# Stopping slaves.
# Performing STOP on all slaves.
# Demoting old master to be a slave to the new master.
# Switching slaves to new master.
# Starting all slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Switchover complete.
# ...done.
Switch-
Over
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31
§  Enabling self-healing replication topologies
§  Automated failover & recovery
§  mysqlfailover Utility
§  Switchover & administration
§  mysqlrpladmin Utility
§  Fully configurable slave promotion policies
§  Delivers HA within the core MySQL
distribution
HA UtilitiesMonitoring
Failed
Master
Slaves
Promoted
Master
Fail-Over
& Admin
Replication HA Utilities
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32
mysqlfailover – monitoring resumes
MySQL Replication Monitor and Failover Utility
Failover Mode = auto Next Interval = Mon Mar 19 16:05:12 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
mysql-bin.000001 1117
GTID Executed Set
A0F7E82D-3554-11E2-9950-080027685B56:1-5
UUIDs
+------------+-------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+------------+-------+---------+--------+------------+---------+
| jane | 3306 | MASTER | UP | ON | OK |
| jane | 3307 | SLAVE | UP | ON | OK |
| freddy | 3306 | SLAVE | UP | ON | OK |
+------------+-------+---------+--------+------------+---------+
Fail-Over
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33
mysqlfailover – master failed
Failover starting...
# Candidate slave jane:3306 will become the new master.
# Preparing candidate for failover.
# Creating replication user if it does not exist.
# Stopping slaves.
# Performing STOP on all slaves.
# Switching slaves to new master.
# Starting slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Failover complete.
# Discovering slaves for master at jane:3306
Failover console will restart in 5 seconds.
Fail-Over
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34
An extensible and easy-to-
use framework for
managing a farm of MySQL
server supporting high-
availability and sharding
MySQL Fabric
Copyright Oracle Corporation 2014 | <date>35
MySQL Fabric Framework (HA)
All Data
Primary Secondary
Extra Read
Replicas
MySQL Fabric
Controller
SQL Queries
State &
Routing Info
HA Group
Coordination
and Control
Copyright Oracle Corporation 2014 | <date>36
MySQL Replication & MySQL Fabric HA
§  MySQL Replication is the initial implementation used in HA Groups
–  PRIMARY = Replication Master & receives all writes
§  Failover
–  MySQL Fabric detects failure of PRIMARY/Master
–  Selects a SECONDARY/Slave and promotes it
–  Updates State Store
–  Updated state fetched by Fabric-aware connectors
& how this effects failover
Copyright Oracle Corporation 2014 | <date>37
High-Availability Group Concept
§  Abstract Concept
–  Set of servers
–  Server attributes
§  Connector Attributes
–  Connection information
–  Mode: read-only, read-write, ...
–  Weight: distribute load
§  Management Attributes
–  State: state/role of the server State: Primary
Mode: Read-Write
Host: server-1.example.com
Copyright Oracle Corporation 2014 | <date>38
Create HA Groups and add Servers
§  Define a group
mysqlfabric group create my_group
§  Add servers to group
mysqlfabric group add my_group server1.example.com
mysqlfabric group add my_group server2.example.com
Copyright Oracle Corporation 2014 | <date>39
Create HA Groups and add Servers
§  Promote one server to be primary
mysqlfabric group promote my_group
§  Tell failure detector to monitor group
mysqlfabric group activate my_group
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40
§  Performance Tuning
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Rules of Tuning

	
•  Never make a change in production first
•  Have a good benchmark or reliable load
•  Start with a good baseline
•  Only change 1 thing at a time
–  identify a set of possible changes
–  try each change separately
–  try in combinations of 2, then 3, etc.
•  Monitor the results
–  Query performance - query analyzer, slow query log, etc.
•  throughput
•  single query time
•  average query time
–  CPU - top, vmstat, dstat
–  IO - iostat, top, vmstat, bonnie++, dstat
–  Network bandwidth
•  Document and save the results
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Were do I find a benchmark?
•  Make your own
–  Can use general query log output
–  Could use MySQL Proxy and TCP Dump
•  DBT2
–  http://osdldbt.sourceforge.net/
–  http://samurai-mysql.blogspot.com/2009/03/settingup-dbt-2.html
•  mysqlslap MySQL 5.1 +
–  http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html
•  SysBench
–  http://sysbench.sourceforge.net/
•  supersmack
–  http://vegan.net/tony/supersmack/
•  mybench
–  http://jeremy.zawodny.com/mysql/mybench/
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
InnoDB Tuning

	
•  Unlike MyISAM - InnoDB uses a single cache for both index and data
–  innodb_buffer_pool_size - should be 70-80% of available
memory.
–  It is not uncommon for this to be very large, i.e. 34GB on a system with
40GB of memory
–  Make sure its not set so large as to cause swapping!
–  mysql>show status like 'Innodb_buffer%' ;
•  InnoDB can use direct IO on systems that support it - Linux, FreeBSD,
and Solaris
–  innodb_flush_method = O_DIRECT
•  For more InnoDB tuning see
–  http://dev.mysql.com/doc/refman/5.1/en/innodb-tuning-
troubleshooting.html
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
DBT-2 (W200) Transactions per Minute %user %iowait
Buffer pool 1G 1125.44 2% 30%
Buffer pool 2G 1863.19 3% 28%
Buffer pool 5G 4385.18 5.5% 33%
Buffer pool 30G
(All data in cache)
36784.76 36% 8%
Cache hot application data in memory

	
•  DBT-2 benchmark (write intensive)
•  20-25GB hot data (200 warehouses, running 1 hour)
•  Nehalem 2.93GHz x 8 cores, MySQL 5.5.2, 4 RAID1+0 HDDs
•  RAM size affects everything. Not only for SELECT, but also for INSERT/UPDATE/DELETE
–  INSERT: Random reads/writes happen when inserting into indexes in random order
–  UPDATE/DELETE: Random reads/writes happen when modifying records
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Connections

	
•  MySQL Caches the threads used by a connection
–  thread_cache_size - Number of threads to cache
–  Setting this to 100 or higher is not unusual
•  Monitor Threads_created to see if this is an issue
–  Counts connections not using the thread cache
–  Should be less than 1-2 a minute
–  Usually only an issue if more than 1-2 a second
•  Only an issue if you create and drop a lot of connections, i.e. PHP
•  Overhead is usually about 250k per thread
•  Aborted_clients -
http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
•  Aborted_connections -
http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Sessions

	
•  Some session variables control space allocated by each session (per connection)
–  Setting these to small can give bad performance
–  Setting these too large can cause the server to swap!
–  Can be set by connection
•  SET SORT_BUFFER_SIZE=1024*1024*128
–  Set small by default, increase in connections that need it
•  sort_buffer_size - Used for ORDER BY, GROUP
•  	
 BY, SELECT DISTINCT, UNION DISTINCT
–  Monitor Sort_merge_passes < 1-2 an hour optimal
–  Usually a problem in a reporting or data warehouse database
•  Other important session variables
–  read_rnd_buffer_size - Set to 1/2 sort_buffer_size
–  join_buffer_size - Watch Select_full_join
–  read_buffer_size - Used for full table scans, watch Select_scan
–  tmp_table_size - Max temp table size in memory, watch Created_tmp_disk_tables
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Query Cache

	
•  MySQL’s ‘Jekyll and Hyde’ of performance tuning options, when it is useful it really
helps, when it hurts, it really hurts
•  MySQL Query Cache caches both the query and the full result set
–  query_cache_type - Controls behaviour
•  0 or OFF - Not used (buffer may still be allocated)
•  1 or ON cache all unless SELECT SQL_NO_CACHE (DEFAULT)
•  2 or DEMAND cache none unless SELECT SQL_CACHE
–  query_cache_size - Determines the size of the cache
•  mysql> show status like 'Qc%' ;
•  Gives great performance if:
–  Identical queries returning identical data are used often
–  No or rare inserts, updates or deletes
•  Best Practice
–  Set to DEMAND
–  Add SQL_CACHE to appropriate queries
Indexing
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Indexes in MySQL

	
•  Indexes allow for faster access to data
•  Data accessed via an index is usually in sorted order
•  Unique or Primary - Must refer to only one record
•  Non-Unique - May refer to many records
•  Can be on one or more columns
–  CREATE INDEX IDX ON TAB1(col1,col2,col3) ;
•  Can use prefix index for
–  CHAR, VARCHAR, BINARY, and VARBINARY
–  CREATE INDEX PRE ON TAB1(COL1(10)) ;
–  Prefix is in bytes, not characters
•  Very useful for large strings
•  Works best when leading part of column is selective
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Index Best Practices

	
•  Too many indexes can slow down inserts/deletes
–  Use only the indexes you must have
–  Check often
–  mysql>show create table tabname ;
•  Don’t duplicate leading parts of compound keys
–  index key123 (col1,col2,col3)
–  index key12 (col1,col2) <- Not needed!
–  index key1 (col1) <-- Not needed!
•  Use prefix indexes on large keys
•  Best indexes are 16 bytes/chars or less (> 16 text?)
•  Indexes bigger than 32 bytes/chars should be looked at very closely
–  should have there own cache if in MyISAM
•  For large strings that need to be indexed, i.e. URLs, consider using a separate
column using the MySQL MD5 to create a hash key and index on it instead
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and
L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+
| 1 | SIMPLE | C | ALL | NULL | NULL | NULL | NULL | 239 | Using where |
| 1 | SIMPLE | Y | ALL | NULL | NULL | NULL | NULL | 4079 | Using where; Using join buffer |
| 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index |
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+
3 rows in set (0.00 sec)
(Using the MySQL World database)
http://dev.mysql.com/doc/index-other.html
Explain 

	
•  Order that the tables are accessed
•  Indexes used
•  Estimated number of rows accessed per table
•  select C.Name, Y.Name, Y.Population, Language from Country
as C, City as Y, CountryLanguage as L where Y.Name = C.Name
and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Explain - Details

	
•  Tables are accessed from top to bottom
•  Columns
–  Select Type - SELECT if no Union or Subquery
–  Table, uses aliases
–  Type - Most common ref or eq_ref
–  Possible Keys - Indexes the optimizer is considering
–  Key = The index the optimizer chose
–  Ref - What column in what table (using alias) is referenced by the index
–  Rows - Estimated number of rows per reference
•  Multiple these to get overall cost
•  There are more values, see:
•  http://dev.mysql.com/doc/refman/5.6/en/using-explain.html
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
mysql> explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and
L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
|+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+
| 1 | SIMPLE | C | ref | c2 | c2 | 52 | const | 1 | Using where; Using index |
| 1 | SIMPLE | Y | ref | c2 | c2 | 35 | const | 1 | Using where |
| 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index
|+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+
3 rows in set (0.00 sec)
More Explain

	
•  alter table Country add index c2 (Name) ;
•  alter table City add index c2 (Name) ;
•  The original cost was 239 * 4079 * 9 = 8,773,929
•  The new cost is 1 * 1 * 9 = 9
Query Tuning Rules
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Queries

	
•  Often the # 1 issue in overall performance
•  Always, Always have your slow query log on!
–  http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html
–  Use: log_queries_not_using_indexes
–  Check it regularly
–  Use mysqldumpslow : http://dev.mysql.com/doc/refman/5.1/en/mysqldumpslow.html
–  Best practice is to automate running mysqldumpslow every morning and email results
to DBA, DBDev, etc.
•  Understand and use EXPLAIN
–  http://dev.mysql.com/doc/refman/5.1/en/using-explain.html
•  Select_scan - Number of full table scans
•  Select_full_join - Joins without indexes
•  MySQL Query Analyzer
–  http://www.mysql.com/products/enterprise/query.html
Schema
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Schemas

	
•  Size = performance, smaller is better
–  Size right! Do not automatically use 255 for VARCHAR
•  Temp tables, most caches, expand to full size
•  Use “procedure analyse” to determine the optimal types given the values in your
table
–  http://dev.mysql.com/doc/refman/5.1/en/procedure-analyse.html
–  mysql> select * from tab procedure analyse (64,2000) G
•  Consider the types:
–  enum : http://dev.mysql.com/doc/refman/5.1/en/enum.html
–  set : http://dev.mysql.com/doc/refman/5.1/en/set.html
•  Compress large strings
–  Use the MySQL COMPRESS and UNCOMPRESS functions
–  Very important in InnoDB 5.5, now with barracuda not so bad
Partitioning can help performance
l  Single inserts and selects faster
l  Range selects faster
l  More efficiently split the data across different paths
l  Historical data stored efficiently
l  delete large chunks of data (drop partition)
l  Move from table to partition easy 5.6
MySQL 5.6 Performance Schema
•  PERFORMANCE_SCHEMA presents low level
MySQL performance information
•  Data can be cleared
•  Filters with WHERE are allowed
•  Must be enabled with --performance_schema
mysql> SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT
-> FROM EVENTS_WAITS_HISTORY WHERE THREAD_ID = 13
-> ORDER BY EVENT_ID;
+----------+-----------------------------------------+------------+
| EVENT_ID | EVENT_NAME | TIMER_WAIT |
+----------+-----------------------------------------+------------+
| 86 | wait/synch/mutex/mysys/THR_LOCK::mutex | 686322 |
| 87 | wait/synch/mutex/mysys/THR_LOCK_malloc | 320535 |
| 88 | wait/synch/mutex/mysys/THR_LOCK_malloc | 339390 |
| 89 | wait/synch/mutex/mysys/THR_LOCK_malloc | 377100 |
| 90 | wait/synch/mutex/sql/LOCK_plugin | 614673 |
| 91 | wait/synch/mutex/sql/LOCK_open | 659925 |
| 92 | wait/synch/mutex/sql/THD::LOCK_thd_data | 494001 |
| 93 | wait/synch/mutex/mysys/THR_LOCK_malloc | 222489 |
| 94 | wait/synch/mutex/mysys/THR_LOCK_malloc | 214947 |
| 95 | wait/synch/mutex/mysys/LOCK_alarm | 312993 |
+----------+-----------------------------------------+------------+
mysql> UPDATE SETUP_INSTRUMENTS
-> SET ENABLED = 'NO'
-> WHERE NAME = 'wait/synch/mutex/myisammrg/MYRG_INFO::mutex';
mysql> UPDATE SETUP_CONSUMERS
-> SET ENABLED = 'NO' WHERE NAME = 'file_summary_by_instance';
© 2010 Oracle Corporation – Proprietary and Confidential
•  Statements/Stages
•  What are my most resource intensive queries? Where do they spend time?
•  Table/Index I/O, Table Locks
•  Which application tables/indexes cause the most load or contention?
•  Network I/O
•  What is the network load like? How long do sessions idle?
•  Users/Hosts/Accounts
•  Which application users, hosts, accounts are consuming the most resources?
•  Summaries
•  Aggregated statistics grouped by thread, user, host, account or object
MySQL 5.6.3 – Performance Schema Instrumentation
Improved Database Profiling/Application Tuning

Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
Next Steps
Learn More
Evaluate MySQL 5.6 Book a Workshop
HA Solutions
Guide
http://bit.ly/NB8up1
Download Today
http://dev.mysql.com/
downloads/mysql/
High Availability
Jumpstart
http://www.mysql.com/
consulting/
Copyright 2011 Oracle Corporation
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
mark.swarbrick@oracle.com

Weitere ähnliche Inhalte

Was ist angesagt?

My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2
Morgan Tocker
 

Was ist angesagt? (20)

My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2
 
AUSOUG Oracle Password Security
AUSOUG Oracle Password SecurityAUSOUG Oracle Password Security
AUSOUG Oracle Password Security
 
MySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersMySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and Developers
 
Looking at RAC, GI/Clusterware Diagnostic Tools
Looking at RAC,   GI/Clusterware Diagnostic Tools Looking at RAC,   GI/Clusterware Diagnostic Tools
Looking at RAC, GI/Clusterware Diagnostic Tools
 
MySQL JSON Functions
MySQL JSON FunctionsMySQL JSON Functions
MySQL JSON Functions
 
MySQL Monitoring Mechanisms
MySQL Monitoring MechanismsMySQL Monitoring Mechanisms
MySQL Monitoring Mechanisms
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 Updates
 
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
MySQL Group Replicatio  in a nutshell - MySQL InnoDB ClusterMySQL Group Replicatio  in a nutshell - MySQL InnoDB Cluster
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
 
IaC MeetUp Active Directory Setup for Oracle Security LAB
IaC MeetUp Active Directory Setup for Oracle Security LABIaC MeetUp Active Directory Setup for Oracle Security LAB
IaC MeetUp Active Directory Setup for Oracle Security LAB
 
Oracle Linux and Oracle Database - A Trusted Combination
Oracle Linux and Oracle Database - A Trusted Combination Oracle Linux and Oracle Database - A Trusted Combination
Oracle Linux and Oracle Database - A Trusted Combination
 
Everything You Need to Know About MySQL Group Replication
Everything You Need to Know About MySQL Group ReplicationEverything You Need to Know About MySQL Group Replication
Everything You Need to Know About MySQL Group Replication
 
Database 12c is ready for you... Are you ready for 12c?
Database 12c is ready for you... Are you ready for 12c?Database 12c is ready for you... Are you ready for 12c?
Database 12c is ready for you... Are you ready for 12c?
 
OTN Tour 2014: Rac 11g vs 12c
OTN Tour 2014: Rac 11g vs 12cOTN Tour 2014: Rac 11g vs 12c
OTN Tour 2014: Rac 11g vs 12c
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
 
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Southeast Linuxfest -- MySQL User Admin Tips & TricksSoutheast Linuxfest -- MySQL User Admin Tips & Tricks
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
 
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
 
MythBusters Globalization Support - Avoid Data Corruption
MythBusters Globalization Support - Avoid Data CorruptionMythBusters Globalization Support - Avoid Data Corruption
MythBusters Globalization Support - Avoid Data Corruption
 
REST in Piece - Administration of an Oracle Cluster/Database using REST
REST in Piece - Administration of an Oracle Cluster/Database using RESTREST in Piece - Administration of an Oracle Cluster/Database using REST
REST in Piece - Administration of an Oracle Cluster/Database using REST
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 

Andere mochten auch

MySQL Server Settings Tuning
MySQL Server Settings TuningMySQL Server Settings Tuning
MySQL Server Settings Tuning
guest5ca94b
 
MySQL Performance Tuning
MySQL Performance TuningMySQL Performance Tuning
MySQL Performance Tuning
FromDual GmbH
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
webhostingguy
 
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
MYXPLAIN
 

Andere mochten auch (19)

Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuning
 
MySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerMySQL Performance Tuning für Entwickler
MySQL Performance Tuning für Entwickler
 
MySQL Server Settings Tuning
MySQL Server Settings TuningMySQL Server Settings Tuning
MySQL Server Settings Tuning
 
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
 
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 Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
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
 

Ähnlich wie MySQL Webinar 2/4 Performance tuning, hardware, optimisation

Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Manuel Contreras
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New Features
Tarique Saleem
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
Dave Stokes
 

Ähnlich wie MySQL Webinar 2/4 Performance tuning, hardware, optimisation (20)

TWJUG August, MySQL JDBC Driver "Connector/J"
TWJUG August, MySQL JDBC Driver "Connector/J"TWJUG August, MySQL JDBC Driver "Connector/J"
TWJUG August, MySQL JDBC Driver "Connector/J"
 
MySql's NoSQL -- best of both worlds on the same disks
MySql's NoSQL -- best of both worlds on the same disksMySql's NoSQL -- best of both worlds on the same disks
MySql's NoSQL -- best of both worlds on the same disks
 
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source Code
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New Features
 
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
 
State of the Dolphin, at db tech showcase Osaka 2014
State of the Dolphin, at db tech showcase Osaka 2014State of the Dolphin, at db tech showcase Osaka 2014
State of the Dolphin, at db tech showcase Osaka 2014
 
My sql fabric webinar v1.1
My sql fabric webinar v1.1My sql fabric webinar v1.1
My sql fabric webinar v1.1
 
20141011 my sql clusterv01pptx
20141011 my sql clusterv01pptx20141011 my sql clusterv01pptx
20141011 my sql clusterv01pptx
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
 
1 my sql20151219-kaji_ivan
1 my sql20151219-kaji_ivan1 my sql20151219-kaji_ivan
1 my sql20151219-kaji_ivan
 
Using Snap Clone with Enterprise Manager 12c
Using Snap Clone with Enterprise Manager 12cUsing Snap Clone with Enterprise Manager 12c
Using Snap Clone with Enterprise Manager 12c
 
MySQL Tech Tour 2015 - Manage & Tune
MySQL Tech Tour 2015 - Manage & TuneMySQL Tech Tour 2015 - Manage & Tune
MySQL Tech Tour 2015 - Manage & Tune
 
20140722 Taiwan MySQL User Group Meeting Tech Updates
20140722 Taiwan MySQL User Group Meeting Tech Updates20140722 Taiwan MySQL User Group Meeting Tech Updates
20140722 Taiwan MySQL User Group Meeting Tech Updates
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
MySQL Replication
MySQL ReplicationMySQL Replication
MySQL Replication
 
MySQL Quick Dive
MySQL Quick DiveMySQL Quick Dive
MySQL Quick Dive
 

Mehr von Mark Swarbrick

Mehr von Mark Swarbrick (20)

MySQL NoSQL Document Store
MySQL NoSQL Document StoreMySQL NoSQL Document Store
MySQL NoSQL Document Store
 
MySQL @ the University Of Nottingham
MySQL @ the University Of NottinghamMySQL @ the University Of Nottingham
MySQL @ the University Of Nottingham
 
InnoDb Vs NDB Cluster
InnoDb Vs NDB ClusterInnoDb Vs NDB Cluster
InnoDb Vs NDB Cluster
 
MySQL Security & GDPR
MySQL Security & GDPRMySQL Security & GDPR
MySQL Security & GDPR
 
Intro To MySQL 2019
Intro To MySQL 2019Intro To MySQL 2019
Intro To MySQL 2019
 
MySQL 8
MySQL 8MySQL 8
MySQL 8
 
MySQL Dublin Event Nov 2018 - MySQL 8
MySQL Dublin Event Nov 2018 - MySQL 8MySQL Dublin Event Nov 2018 - MySQL 8
MySQL Dublin Event Nov 2018 - MySQL 8
 
MySQL Dublin Event Nov 2018 - State of the Dolphin
MySQL Dublin Event Nov 2018 - State of the DolphinMySQL Dublin Event Nov 2018 - State of the Dolphin
MySQL Dublin Event Nov 2018 - State of the Dolphin
 
Oracle Code Event - MySQL JSON Document Store
Oracle Code Event - MySQL JSON Document StoreOracle Code Event - MySQL JSON Document Store
Oracle Code Event - MySQL JSON Document Store
 
TLV - MySQL Security overview
TLV - MySQL Security overviewTLV - MySQL Security overview
TLV - MySQL Security overview
 
TLV - MySQL Enterprise Edition + Cloud
TLV - MySQL Enterprise Edition + CloudTLV - MySQL Enterprise Edition + Cloud
TLV - MySQL Enterprise Edition + Cloud
 
TLV - Whats new in MySQL 8
TLV - Whats new in MySQL 8TLV - Whats new in MySQL 8
TLV - Whats new in MySQL 8
 
MySQL At University Of Nottingham - 2018 MySQL Days
MySQL At University Of Nottingham - 2018 MySQL DaysMySQL At University Of Nottingham - 2018 MySQL Days
MySQL At University Of Nottingham - 2018 MySQL Days
 
MySQL At Mastercard - 2018 MySQL Days
MySQL At Mastercard - 2018 MySQL DaysMySQL At Mastercard - 2018 MySQL Days
MySQL At Mastercard - 2018 MySQL Days
 
MySQL 8 - 2018 MySQL Days
MySQL 8 - 2018 MySQL DaysMySQL 8 - 2018 MySQL Days
MySQL 8 - 2018 MySQL Days
 
MySQL Security + GDPR - 2018 MySQL Days
MySQL Security + GDPR - 2018 MySQL DaysMySQL Security + GDPR - 2018 MySQL Days
MySQL Security + GDPR - 2018 MySQL Days
 
MySQL InnoDB + NDB Cluster - 2018 MySQL Days
MySQL InnoDB + NDB Cluster - 2018 MySQL DaysMySQL InnoDB + NDB Cluster - 2018 MySQL Days
MySQL InnoDB + NDB Cluster - 2018 MySQL Days
 
MySQL Cloud - 2018 MySQL Days
MySQL Cloud - 2018 MySQL DaysMySQL Cloud - 2018 MySQL Days
MySQL Cloud - 2018 MySQL Days
 
MySQL 2018 Intro - 2018 MySQL Days
MySQL 2018 Intro - 2018 MySQL DaysMySQL 2018 Intro - 2018 MySQL Days
MySQL 2018 Intro - 2018 MySQL Days
 
MySQL + GDPR
MySQL + GDPRMySQL + GDPR
MySQL + GDPR
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

MySQL Webinar 2/4 Performance tuning, hardware, optimisation

  • 1. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
  • 2. Installation, Configuration and performance tuning Mark Swarbrick Principle Presales Consultant MySQL Webinar Series 2/4
  • 3. Program Agenda §  Hardware Specification §  Setting up Replication §  Performance tuning
  • 4. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012 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 decision. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Safe Harbor Statement
  • 6. MySQL Hardware / Software Platforms MySQL is supported on a variety of hardware / software platforms: Oracle Linux Oracle Solaris Red Hat Canonical (Ubuntu) SUSE Debian Microsoft Windows XP/Vista/7/2003/2008/2012/server FreeBSD HPUX Other Linux – Fedora / OpenSUSE / CentOS etc
  • 7. MySQL Hardware / Software Platforms MySQL is supported on a variety of hardware / software platforms: X86 X86_64 X86_IA64 SPARC_32 SPARC_64 IBM Power5_64 PA-RISC 2.0 We will support with best efforts on other hardware platforms such as ARM. For example MySQL Cluster compiled to run on a raspberry pi!
  • 8. Copyright Oracle Corporation 2014 | <date>8 Scaling on dense, multi-core, multi-thread servers •  10s - 100GBs RAM •  SSDs Scale across cores within a single instance You can get a long way with MySQL 5.6! The Path to Scalability Scaling-Up can take you a long way
  • 9. MySQL Hardware / Software Platforms Server: Having the fastest CPU is still beneficial. Can use as many as 32 cores! OS choice and tuning is important, but Linux / Solaris or windows all give good performance. Storage: Don’t use slow disks Flash memory (SSD etc) helps for random access (reads are the most costly) FS is important – ZFS, UFS, QFS, VxFS, EXT3, EXT4 XFS etc.. Use of O_Direct if O/S supports it Don’t forget the network! Faster is better!
  • 10. Hardware: The Perfect MySQL Server •  The more cores the better (especially for 5.5 and later) •  x86_64 - 64 bit for more memory is important –  The more the better •  Fast HD (10-15k RPM SATA) or NAS/SAN…… –  RAID 10 for most, RAID 5 OK if very read intensive –  Hardware RAID battery backed up cache critical! –  More disks are always better! - 4+ recommended, 8-16 can increase IO •  …Or SSD (for higher throughput) –  Intel, Fusion-IO good choices; good option for Slaves •  At least 2 x NICs for redundancy •  Slaves should be as powerful as the Master
  • 12. MySQL HA Solutions Note that MySQL Fabric is currently at Release Candidate Status
  • 13. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13 Why Replicate? §  Duplicates database from a “master” to a “slave” §  Redundant copies of the data provide foundation for High Availability §  Scale out by distributing queries across the replication cluster Master Slaves Web / App Servers Writes & Reads Reads
  • 14. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14 Slave Database §  Session thread: processes queries from the application – writes data to master database & associated events to binary log §  Dump thread: reads events from binary log and sends them to a slave §  I/O thread: receives replication events and stores them in slave’s relay log §  SQL thread: reads replication events from slave’s relay log and applies them to slave database Session Binary Log Master Database Dump I/O Relay Log SQL Replication Workflow
  • 15. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15 ReplicationReplication Solutions
  • 16. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16 Async Replication
  • 17. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17 Semi-sync Replication
  • 18. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18 MySQL 5.6: Transforming Replication •  Multi-Threaded Slaves •  Binary Log Group Commit •  Optimized Row-Based Replication PERFORMANCE •  Global Transaction Identifiers •  Replication Failover & Admin Utilities •  Crash Safe Slaves & Binlogs FAILOVER & RECOVERY •  Replication Event Checksums DATA INTEGRITY •  Replication Utilities •  Time-Delayed Replication •  Remote Binlog Backup •  Informational Log Events •  Server UUIDs DEV/OPS AGILITY
  • 19. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19 5x Higher Performance with MySQL 5.6 0 5 10 QPS 58.11 144.4 282.53 0 50 100 150 200 250 300 QueriesperSecond Worker Threads Multi-Threaded Slave Performance
  • 20. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20 Master GTID=123456 GTID=123456 GTID=123456 GTID=123456 Global Transaction Identifiers §  Simple to track & compare replication across the farm §  Unique identifier for each transaction written to the Binlog §  Automatically identify the most up-to-date slave for failover §  Deploy n-tier replication hierarchies
  • 21. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21 Time Delayed Replication - configuring slave2> CHANGE MASTER TO -> MASTER_HOST = 'localhost‘, -> MASTER_PORT = 3306, -> MASTER_USER = 'repl_user‘, -> MASTER_PASSWORD = ‘sun123!‘, -> MASTER_DELAY = 600; slave2> START SLAVE;
  • 22. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22 MySQL Utilities §  Automate common Dev/Ops tasks §  Replication: provisioning, testing, monitoring and failover §  Database comparisons: consistency checking §  Database administration: users, connections, tables, etc §  New utilities in development, i.e. log analysis §  Implemented as Python scripts, plug-in for MySQL Workbench §  Extensible to include custom scripting §  Resources: Documentation & Community Forum §  http://dev.mysql.com/doc/workbench/en/mysql-utils-man.html §  http://forums.mysql.com/list.php?155
  • 23. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23 Utility Workflow for Replication §  Replicate: Initiates Replication to the new slave §  Check: Validates the replication configuration and operation §  Show: Display Replication topology §  Fail-Over & Admin: Detects and failovers (or switches) from master to slave. Status monitoring Check Show Fail-Over & AdminReplicate
  • 24. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24 mysqlreplicate Utility §  Starts replication process §  User can provide login and connection parameters for the master §  Configurable replication start points: current position / GTID, specific event, entire binlog §  Checks storage engine compatibility §  Enables fast, simple scaling New Slave Login, Connection & Start-Point Master Replication configured, binlog position Repl
  • 25. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25 mysqlreplicate example $ mysqlreplicate --master=root:billy@localhost:3306 --slave=root:billy@localhost:3307 # master on localhost: ... connected. # slave on localhost: ... connected. Repl
  • 26. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26 mysqlrplshow Utility §  Discovers & displays replication topology §  Shows slaves attached to each master §  Labels each slave with hostname and port number §  Displays multiple topologies, including hierarchical and circular §  Displays results in a graph or list §  Enables user to monitor topology on-demand $ mysqlrplshow --master=root@localhost:3311 # master on localhost: ... connected. # Finding slaves for master: localhost:3311 # Replication Topology Graph:: localhost:3306 (MASTER) | +--- localhost:3307 - (SLAVE) | +--- localhost:3308 - (SLAVE + MASTER) | +--- localhost:3313 - (SLAVE) Show
  • 27. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27 mysqlrplcheck Utility §  Tests replication on master and slave to ensure proper configuration of replication §  Checks binlog is enabled and displays any configured exceptions §  Checks slave access and privileges to master §  Checks slave connection status §  Checks for conflicts in master.info file (or mysql.slave_master_info table) §  Checks storage engine compatibility §  Tests executed sequentially §  Reports status of each test §  Simple verification of deployment & fast fault resolution Check
  • 28. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28 mysqlrplcheck example $ mysqlrplcheck --master=root@host1:3310 --slave=root@host2:3311 # master on host1: ... connected. # slave on host2: ... connected. Test Description Status ------------------------------------------------------------- Checking for binary logging on master [pass] Are there binlog exceptions? [pass] Replication user exists? [pass] Checking server_id values [pass] Is slave connected to master? [pass] Check master information file [pass] Checking InnoDB compatibility [pass] Checking storage engines compatibility [pass] Checking lower_case_table_names settings [pass] Checking slave delay (seconds behind master) [pass] # ...done. Check
  • 29. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29 Replication Administration Utility §  Perform switchover to eliminate downtime during planned maintenance §  Start and stop slaves §  Slave discovery & monitoring §  Slave status, thread status §  Replication processing, including any lag §  Configure slave promotion policies Master Slaves Administration Utility Status & Switchover Admin
  • 30. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30 Planned switchover to new master with mysqlrpladmin $ mysqlrpladmin --master=root@rod:3306 --slaves=root@jane:3306,root@jane:3307,root@freddy:3306 --new-master=root@jane:3306 --demote-master switchover # Performing switchover from master at rod:3306 to slave at jane:3306. # Checking candidate slave prerequisites. # Waiting for slaves to catch up to old master. # Stopping slaves. # Performing STOP on all slaves. # Demoting old master to be a slave to the new master. # Switching slaves to new master. # Starting all slaves. # Performing START on all slaves. # Checking slaves for errors. # Switchover complete. # ...done. Switch- Over
  • 31. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31 §  Enabling self-healing replication topologies §  Automated failover & recovery §  mysqlfailover Utility §  Switchover & administration §  mysqlrpladmin Utility §  Fully configurable slave promotion policies §  Delivers HA within the core MySQL distribution HA UtilitiesMonitoring Failed Master Slaves Promoted Master Fail-Over & Admin Replication HA Utilities
  • 32. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32 mysqlfailover – monitoring resumes MySQL Replication Monitor and Failover Utility Failover Mode = auto Next Interval = Mon Mar 19 16:05:12 2012 Master Information ------------------ Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB mysql-bin.000001 1117 GTID Executed Set A0F7E82D-3554-11E2-9950-080027685B56:1-5 UUIDs +------------+-------+---------+--------+------------+---------+ | host | port | role | state | gtid_mode | health | +------------+-------+---------+--------+------------+---------+ | jane | 3306 | MASTER | UP | ON | OK | | jane | 3307 | SLAVE | UP | ON | OK | | freddy | 3306 | SLAVE | UP | ON | OK | +------------+-------+---------+--------+------------+---------+ Fail-Over
  • 33. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33 mysqlfailover – master failed Failover starting... # Candidate slave jane:3306 will become the new master. # Preparing candidate for failover. # Creating replication user if it does not exist. # Stopping slaves. # Performing STOP on all slaves. # Switching slaves to new master. # Starting slaves. # Performing START on all slaves. # Checking slaves for errors. # Failover complete. # Discovering slaves for master at jane:3306 Failover console will restart in 5 seconds. Fail-Over
  • 34. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34 An extensible and easy-to- use framework for managing a farm of MySQL server supporting high- availability and sharding MySQL Fabric
  • 35. Copyright Oracle Corporation 2014 | <date>35 MySQL Fabric Framework (HA) All Data Primary Secondary Extra Read Replicas MySQL Fabric Controller SQL Queries State & Routing Info HA Group Coordination and Control
  • 36. Copyright Oracle Corporation 2014 | <date>36 MySQL Replication & MySQL Fabric HA §  MySQL Replication is the initial implementation used in HA Groups –  PRIMARY = Replication Master & receives all writes §  Failover –  MySQL Fabric detects failure of PRIMARY/Master –  Selects a SECONDARY/Slave and promotes it –  Updates State Store –  Updated state fetched by Fabric-aware connectors & how this effects failover
  • 37. Copyright Oracle Corporation 2014 | <date>37 High-Availability Group Concept §  Abstract Concept –  Set of servers –  Server attributes §  Connector Attributes –  Connection information –  Mode: read-only, read-write, ... –  Weight: distribute load §  Management Attributes –  State: state/role of the server State: Primary Mode: Read-Write Host: server-1.example.com
  • 38. Copyright Oracle Corporation 2014 | <date>38 Create HA Groups and add Servers §  Define a group mysqlfabric group create my_group §  Add servers to group mysqlfabric group add my_group server1.example.com mysqlfabric group add my_group server2.example.com
  • 39. Copyright Oracle Corporation 2014 | <date>39 Create HA Groups and add Servers §  Promote one server to be primary mysqlfabric group promote my_group §  Tell failure detector to monitor group mysqlfabric group activate my_group
  • 40. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40 §  Performance Tuning
  • 41. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41 The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Rules of Tuning
 •  Never make a change in production first •  Have a good benchmark or reliable load •  Start with a good baseline •  Only change 1 thing at a time –  identify a set of possible changes –  try each change separately –  try in combinations of 2, then 3, etc. •  Monitor the results –  Query performance - query analyzer, slow query log, etc. •  throughput •  single query time •  average query time –  CPU - top, vmstat, dstat –  IO - iostat, top, vmstat, bonnie++, dstat –  Network bandwidth •  Document and save the results
  • 42. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Were do I find a benchmark? •  Make your own –  Can use general query log output –  Could use MySQL Proxy and TCP Dump •  DBT2 –  http://osdldbt.sourceforge.net/ –  http://samurai-mysql.blogspot.com/2009/03/settingup-dbt-2.html •  mysqlslap MySQL 5.1 + –  http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html •  SysBench –  http://sysbench.sourceforge.net/ •  supersmack –  http://vegan.net/tony/supersmack/ •  mybench –  http://jeremy.zawodny.com/mysql/mybench/
  • 43. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle InnoDB Tuning
 •  Unlike MyISAM - InnoDB uses a single cache for both index and data –  innodb_buffer_pool_size - should be 70-80% of available memory. –  It is not uncommon for this to be very large, i.e. 34GB on a system with 40GB of memory –  Make sure its not set so large as to cause swapping! –  mysql>show status like 'Innodb_buffer%' ; •  InnoDB can use direct IO on systems that support it - Linux, FreeBSD, and Solaris –  innodb_flush_method = O_DIRECT •  For more InnoDB tuning see –  http://dev.mysql.com/doc/refman/5.1/en/innodb-tuning- troubleshooting.html
  • 44. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle DBT-2 (W200) Transactions per Minute %user %iowait Buffer pool 1G 1125.44 2% 30% Buffer pool 2G 1863.19 3% 28% Buffer pool 5G 4385.18 5.5% 33% Buffer pool 30G (All data in cache) 36784.76 36% 8% Cache hot application data in memory
 •  DBT-2 benchmark (write intensive) •  20-25GB hot data (200 warehouses, running 1 hour) •  Nehalem 2.93GHz x 8 cores, MySQL 5.5.2, 4 RAID1+0 HDDs •  RAM size affects everything. Not only for SELECT, but also for INSERT/UPDATE/DELETE –  INSERT: Random reads/writes happen when inserting into indexes in random order –  UPDATE/DELETE: Random reads/writes happen when modifying records
  • 45. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Connections
 •  MySQL Caches the threads used by a connection –  thread_cache_size - Number of threads to cache –  Setting this to 100 or higher is not unusual •  Monitor Threads_created to see if this is an issue –  Counts connections not using the thread cache –  Should be less than 1-2 a minute –  Usually only an issue if more than 1-2 a second •  Only an issue if you create and drop a lot of connections, i.e. PHP •  Overhead is usually about 250k per thread •  Aborted_clients - http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html •  Aborted_connections - http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
  • 46. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Sessions
 •  Some session variables control space allocated by each session (per connection) –  Setting these to small can give bad performance –  Setting these too large can cause the server to swap! –  Can be set by connection •  SET SORT_BUFFER_SIZE=1024*1024*128 –  Set small by default, increase in connections that need it •  sort_buffer_size - Used for ORDER BY, GROUP •  BY, SELECT DISTINCT, UNION DISTINCT –  Monitor Sort_merge_passes < 1-2 an hour optimal –  Usually a problem in a reporting or data warehouse database •  Other important session variables –  read_rnd_buffer_size - Set to 1/2 sort_buffer_size –  join_buffer_size - Watch Select_full_join –  read_buffer_size - Used for full table scans, watch Select_scan –  tmp_table_size - Max temp table size in memory, watch Created_tmp_disk_tables
  • 47. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Query Cache
 •  MySQL’s ‘Jekyll and Hyde’ of performance tuning options, when it is useful it really helps, when it hurts, it really hurts •  MySQL Query Cache caches both the query and the full result set –  query_cache_type - Controls behaviour •  0 or OFF - Not used (buffer may still be allocated) •  1 or ON cache all unless SELECT SQL_NO_CACHE (DEFAULT) •  2 or DEMAND cache none unless SELECT SQL_CACHE –  query_cache_size - Determines the size of the cache •  mysql> show status like 'Qc%' ; •  Gives great performance if: –  Identical queries returning identical data are used often –  No or rare inserts, updates or deletes •  Best Practice –  Set to DEMAND –  Add SQL_CACHE to appropriate queries
  • 49. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Indexes in MySQL
 •  Indexes allow for faster access to data •  Data accessed via an index is usually in sorted order •  Unique or Primary - Must refer to only one record •  Non-Unique - May refer to many records •  Can be on one or more columns –  CREATE INDEX IDX ON TAB1(col1,col2,col3) ; •  Can use prefix index for –  CHAR, VARCHAR, BINARY, and VARBINARY –  CREATE INDEX PRE ON TAB1(COL1(10)) ; –  Prefix is in bytes, not characters •  Very useful for large strings •  Works best when leading part of column is selective
  • 50. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Index Best Practices
 •  Too many indexes can slow down inserts/deletes –  Use only the indexes you must have –  Check often –  mysql>show create table tabname ; •  Don’t duplicate leading parts of compound keys –  index key123 (col1,col2,col3) –  index key12 (col1,col2) <- Not needed! –  index key1 (col1) <-- Not needed! •  Use prefix indexes on large keys •  Best indexes are 16 bytes/chars or less (> 16 text?) •  Indexes bigger than 32 bytes/chars should be looked at very closely –  should have there own cache if in MyISAM •  For large strings that need to be indexed, i.e. URLs, consider using a separate column using the MySQL MD5 to create a hash key and index on it instead
  • 51. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ; +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+ | 1 | SIMPLE | C | ALL | NULL | NULL | NULL | NULL | 239 | Using where | | 1 | SIMPLE | Y | ALL | NULL | NULL | NULL | NULL | 4079 | Using where; Using join buffer | | 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index | +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+ 3 rows in set (0.00 sec) (Using the MySQL World database) http://dev.mysql.com/doc/index-other.html Explain 
 •  Order that the tables are accessed •  Indexes used •  Estimated number of rows accessed per table •  select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
  • 52. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Explain - Details
 •  Tables are accessed from top to bottom •  Columns –  Select Type - SELECT if no Union or Subquery –  Table, uses aliases –  Type - Most common ref or eq_ref –  Possible Keys - Indexes the optimizer is considering –  Key = The index the optimizer chose –  Ref - What column in what table (using alias) is referenced by the index –  Rows - Estimated number of rows per reference •  Multiple these to get overall cost •  There are more values, see: •  http://dev.mysql.com/doc/refman/5.6/en/using-explain.html
  • 53. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle mysql> explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ; +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+ | 1 | SIMPLE | C | ref | c2 | c2 | 52 | const | 1 | Using where; Using index | | 1 | SIMPLE | Y | ref | c2 | c2 | 35 | const | 1 | Using where | | 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index |+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+ 3 rows in set (0.00 sec) More Explain
 •  alter table Country add index c2 (Name) ; •  alter table City add index c2 (Name) ; •  The original cost was 239 * 4079 * 9 = 8,773,929 •  The new cost is 1 * 1 * 9 = 9
  • 55. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Queries
 •  Often the # 1 issue in overall performance •  Always, Always have your slow query log on! –  http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html –  Use: log_queries_not_using_indexes –  Check it regularly –  Use mysqldumpslow : http://dev.mysql.com/doc/refman/5.1/en/mysqldumpslow.html –  Best practice is to automate running mysqldumpslow every morning and email results to DBA, DBDev, etc. •  Understand and use EXPLAIN –  http://dev.mysql.com/doc/refman/5.1/en/using-explain.html •  Select_scan - Number of full table scans •  Select_full_join - Joins without indexes •  MySQL Query Analyzer –  http://www.mysql.com/products/enterprise/query.html
  • 57. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Schemas
 •  Size = performance, smaller is better –  Size right! Do not automatically use 255 for VARCHAR •  Temp tables, most caches, expand to full size •  Use “procedure analyse” to determine the optimal types given the values in your table –  http://dev.mysql.com/doc/refman/5.1/en/procedure-analyse.html –  mysql> select * from tab procedure analyse (64,2000) G •  Consider the types: –  enum : http://dev.mysql.com/doc/refman/5.1/en/enum.html –  set : http://dev.mysql.com/doc/refman/5.1/en/set.html •  Compress large strings –  Use the MySQL COMPRESS and UNCOMPRESS functions –  Very important in InnoDB 5.5, now with barracuda not so bad
  • 58. Partitioning can help performance l  Single inserts and selects faster l  Range selects faster l  More efficiently split the data across different paths l  Historical data stored efficiently l  delete large chunks of data (drop partition) l  Move from table to partition easy 5.6
  • 59. MySQL 5.6 Performance Schema •  PERFORMANCE_SCHEMA presents low level MySQL performance information •  Data can be cleared •  Filters with WHERE are allowed •  Must be enabled with --performance_schema mysql> SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT -> FROM EVENTS_WAITS_HISTORY WHERE THREAD_ID = 13 -> ORDER BY EVENT_ID; +----------+-----------------------------------------+------------+ | EVENT_ID | EVENT_NAME | TIMER_WAIT | +----------+-----------------------------------------+------------+ | 86 | wait/synch/mutex/mysys/THR_LOCK::mutex | 686322 | | 87 | wait/synch/mutex/mysys/THR_LOCK_malloc | 320535 | | 88 | wait/synch/mutex/mysys/THR_LOCK_malloc | 339390 | | 89 | wait/synch/mutex/mysys/THR_LOCK_malloc | 377100 | | 90 | wait/synch/mutex/sql/LOCK_plugin | 614673 | | 91 | wait/synch/mutex/sql/LOCK_open | 659925 | | 92 | wait/synch/mutex/sql/THD::LOCK_thd_data | 494001 | | 93 | wait/synch/mutex/mysys/THR_LOCK_malloc | 222489 | | 94 | wait/synch/mutex/mysys/THR_LOCK_malloc | 214947 | | 95 | wait/synch/mutex/mysys/LOCK_alarm | 312993 | +----------+-----------------------------------------+------------+ mysql> UPDATE SETUP_INSTRUMENTS -> SET ENABLED = 'NO' -> WHERE NAME = 'wait/synch/mutex/myisammrg/MYRG_INFO::mutex'; mysql> UPDATE SETUP_CONSUMERS -> SET ENABLED = 'NO' WHERE NAME = 'file_summary_by_instance'; © 2010 Oracle Corporation – Proprietary and Confidential
  • 60. •  Statements/Stages •  What are my most resource intensive queries? Where do they spend time? •  Table/Index I/O, Table Locks •  Which application tables/indexes cause the most load or contention? •  Network I/O •  What is the network load like? How long do sessions idle? •  Users/Hosts/Accounts •  Which application users, hosts, accounts are consuming the most resources? •  Summaries •  Aggregated statistics grouped by thread, user, host, account or object MySQL 5.6.3 – Performance Schema Instrumentation Improved Database Profiling/Application Tuning

  • 61. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012 Next Steps Learn More Evaluate MySQL 5.6 Book a Workshop HA Solutions Guide http://bit.ly/NB8up1 Download Today http://dev.mysql.com/ downloads/mysql/ High Availability Jumpstart http://www.mysql.com/ consulting/ Copyright 2011 Oracle Corporation
  • 62. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012 mark.swarbrick@oracle.com