SlideShare a Scribd company logo
1 of 70
Download to read offline
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
1
50 Tips for Boosting
MySQL Performance
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
2
MySQL Performance
Arnaud ADANT
MySQL Principal Support Engineer
Safe Harbour Statement
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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
3
DECISIONS. THE DEVELOPMENT, RELEASE, AND TIMING OF ANY FEATURES OR
FUNCTIONALITY DESCRIBED FOR ORACLE’S PRODUCTS REMAINS AT THE SOLE
DISCRETION OF ORACLE.
Program Agenda
Introduction
50 MySQL Performance Tips
Q & A
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
4
Q & A
Introduction : Who I am
http://blog.aadant.com
10 year+ Development
MySQL Support for 3 years
Arnaud ADANT
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
5
MySQL Support for 3 years
MySQL Performance
I love my job !
Introduction : Why 50 ?
Effective C++, Meyers, 1991
– 55 items
50 items is an effective format !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
6
Effective Java, Bloch, 2001
– 57 items
Tip 0. Never trust anyone, benchmark
Test, test, test
Benchmark, benchmark, benchmark
Monitor, monitor, monitor
HW and SW vendors are all lying !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
11
One knob at a time
Use sysbench, mysqlslap, monitoring tools
Tip 1. Make sure you have enough RAM
The active data should fit in the buffer pool
MySQL connections and caches take memory
ECC RAM recommended
Depends on your active data and connections
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
13
Extra RAM for
– FS cache
– Monitoring
– RAM disk (tmpfs)
Tip 2. Use fast and multi-core processors
Fast CPU is required for single threaded performance
Recent servers have 32 to 80 cores.
Enable hyper-threading
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
14
MySQL can only scale to 16 cores in 5.5 and 32-48 cores in 5.6
Same core count in fewer sockets is better
Faster cores better than more but slower cores
Tip 3. Use fast and reliable storage
Good for IO bound loads
HDD for sequential reads and writes
Bus-attached SSD for random reads and writes
Will always help
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
15
Big sata or other disk for log files
Several disks !
Life time
Tip 4. Choose the right OS
L of LAMP
Good on Solaris
Oracle invests on Windows
MySQL is excellent on Linux
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
18
For pure performance, favor Linux
Tip 5. Adjust the OS limits
Max open files per process
– ulimit –n
– limits the number of file handles (connections, open tables, …)
OS limits are extremely important !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
19
Max threads per user
– ulimit –u
– limits the number of threads (connections, event scheduler, shutdown)
On Windows, MaxUserPort for TCP/IP, for 2003 and earlier
Tip 6. Consider using alternative malloc
jemalloc is a good malloc replacement
[mysqld_safe]
Some malloc libraries are optimized for multi-core environment
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
20
malloc-lib=/usr/lib64/libjemalloc.so.1
tcmalloc shipped on Linux with MySQL
[mysqld_safe]
malloc-lib=tcmalloc
• Sysbench OLTP RO
• High concurrency
Tip 6. Consider using alternative malloc
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
21
Tip 7. Set CPU affinity
taskset command on Linux
taskset -c 1-4 `pidof mysqld`
On Linux and Windows, CPU affinity helps concurrent WL
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
22
taskset -c 1,2,3,4 `pidof mysqld`
On Windows :
START /AFFINITY 0x1111 binmysqld –console
START /AFFINITY 15 binmysqld –console
Tip 8. Choose the right file system
• xfs is excellent
• With innodb_flush_method = O_DIRECT
• supported by Oracle on OEL
XFS for experts, ext4 or ext3
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
25
• less stable recently
• ext4 best choice for speed and ease of use
• fsyncs a bit slower than ext3
• more reliable
• ext3 is also a good choice
• DYI nfs is problematic with InnoDB
Tip 9. Mount options
• ext4 (rw,noatime,nodiratime,nobarrier,data=ordered)
• xfs (rw, noatime,nodiratime,nobarrier,logbufs=8,logbsize=32k)
• SSD specific
For performance
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
26
• trim
• innodb_page_size = 4K
• Innodb_flush_neighbors = 0
Tip 10. Choose the best I/O scheduler
deadline is generally the best I/O scheduler
echo deadline > /sys/block/{DEVICE-NAME}/queue/scheduler
the best value is HW and WL specific
noop
Use deadline or noop on Linux
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
27
– noop on high end controller (SSD, good RAID card …)
– deadline otherwise
Tip 11. Use a battery backed disk cache
Usually faster fsyncs
– innoDB redo logs
– binary logs
A good investment !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
28
– data files
Crash safety
Durability
Applies to SSD
Tip 12. Balance the load on several disks
One disk is not a good idea
Especially for HDD, read and write
Separate :
90 % of customers use a single disk !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
29
– datadir
– innodb_data_file_path
– innodb_undo_directory
– innodb_log_group_home_dir
– log-bin
– tmpdir
Random, SSD
Sequential, spinning
Random, SSD, tmpfs
13. Turn Off the Query Cache
Only if threads_running <= 4
Becomes fragmented
• Cache should be in the App !
Single threaded bottleneck, only on low concurrency systems
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
32
• Off by default from 5.6
• query_cache_type = 0
• query_cache_size =0
• Sysbench OLTP RO
• QPS drops with
connections and QC
Tip 13. Turn Off the Query Cache
20000
30000
40000
50000
TPS QC = on
TPS QC = off
Qcache_free_blocks
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
33
• qcache_free_blocks >
5-10k
0
10000
1 2 4 8 16
Qcache_free_blocks
connections
QPS
Tip 13. Turn Off the Query Cache
qcache_free_blocks > 5-10k
stage/sql/Waiting for query cache lock
How to see there is a problem ?
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
34
• Stabilize TPS for high
concurrency
• Useful if
threads_running >
Tip 14. Use the Thread Pool
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
35
threads_running >
hardware threads
• Decrease context
switches
• Several connections
for one execution
thread
Tip 15. Configure table caching
table_open_cache
– not too small, not too big, used to size PS
– opened_tables / sec
MySQL has at least one file per table : the FRM file
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
36
table_definition_cache
– do not forget to increase
– opened_table_definitions / sec
table_cache_instances = 8 or 16
innodb_open_files
mdl_hash_instances = 256
Tip 15. Configure table caching
concurrency concurrency
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
37
16 instances
1 instance
concurrency concurrency
TPS
Tip 16. Cache the threads
thread_cache_size
– decreases threads_created rate
capped by max user processes (see OS limits)
Thread creation / initialization is expensive
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
38
5.7.2 refactors this code
Tip 17. Reduce per thread memory usage
max_used_connections * (
read_buffer_size +
read_rnd_buffer_size +
Memory allocation is expensive
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
39
join_buffer_size +
sort_buffer_size +
binlog_cache_size +
thread_stack +
2 * net_buffer_length …
)
• sysbench RW
• sync_binlog = 1 was
a performance killer in
5.5
Tip 18. Beware of sync_binlog = 1
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
41
5.5
• 5.6 binlog group
commit fixed it
• Better with SSD or
battery backed disk
cache
Tip 19. Move your tables to InnoDB
Scalable
99% of MyISAM use cases covered
Online alter operations
InnoDB is the most advanced MySQL storage engine
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
42
Full text engine
Memcached API for high performance
Tip 20. Use a large buffer pool
innodb_buffer_pool_size
Not too large for the data
Do not swap !
50 – 80% of the total RAM
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
45
Beware of memory crash if swapping is disabled
Active data <= innodb_buffer_pool_size <= 0.8 * RAM
Tip 21. Reduce the buffer pool contention
innodb_buffer_pool_instances >= 8
Reduce rows_examined / sec (see Bug #68079)
8 is the default value in 5.6 !
Key to achieve high QPS / TPS
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
46
In 5.5, but even better in 5.6 and 5.7
innodb_spin_wait_delay = 96 on high concurrency
Use read only transactions
– when possible
Tip 21. Reduce the buffer pool contention
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
47
Tip 22. Use large redo logs
Redo logs defer the expensive changes to the data files
Recovery time is no more an issue
innodb_log_file_size = 2047M before 5.6
A key parameter for write performance
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
48
innodb_log_file_size >= 2047M from 5.6
Bigger is better for write QPS stability
Tip 22. Use large redo logs
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
49
Tip 23. Adjust the IO capacity
IO OPS the disk(s) can do
Higher for SSD
Increase if several disks for InnoDB IO
innodb_io_capacity should reflect device capacity
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
50
In 5.6, innodb_lru_scan_depth is per buffer pool instance
so innodb_lru_scan_depth =
innodb_io_capacity / innodb_buffer_pool_instances
Default innodb_io_capacity_max =
min(2000, 2 * innodb_io_capacity)
Tip 24. Configure the InnoDB flushing
Redo logs :
– innodb_flush_log_at_trx_commit = 1 // best durability
– innodb_flush_log_at_trx_commit = 2 // better performance
Durability settings
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
51
– innodb_flush_log_at_trx_commit = 0 // best performance
Data files only :
– innodb_flush_method = O_DIRECT // Linux, skips the FS cache
Increase innodb_adaptive_flushing_lwm (fast disk)
Tip 25. Enable innodb_file_per_table
Increased manageability
Truncate reclaims disk space
Better with innodb_flush_method = O_DIRECT
innodb_file_per_table = ON is the default in 5.6
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
53
Easier to optimize
But …
– not so good with many small tables
– more file handles (see OS limits)
– more fsyncs
Tip 26. Configure the thread concurrency
No thread pool :
– innodb_thread_concurrency = 16 - 32 in 5.5
– innodb_thread_concurrency = 36 in 5.6
innodb_thread_concurrency / innodb_max_concurrency_tickets
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
54
– align to HW threads if less than 32 cores
Thread pool :
– innodb_thread_concurrency = 0 is fine
innodb_max_concurrency_tickets : higher for OLAP, lower for
OLTP
Tip 27. Reduce the transaction isolation
Application dependent
Read committed
– it implies binlog_format = ROW
Default = repeatable reads
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
55
Variable : transaction-isolation
Lower isolation = higher performance
Tip 28. Design the tables
integer primary keys
– avoid varchar, composite for PK
latin1 vs. utf8
Choose the charset, PK and data types carefully
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
58
the smallest varchar for a column
keep the number of partitions low (< 10)
use compression for blob / text data types
Tip 29. Add indexes
for fast access to records
for sorting / grouping
– without temporary table
Indexes help decrease the number of rows examined
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
59
covering indexes
– contain all the selected data
– save access to full record
– reduce random reads
Tip 30. Remove unused indexes
Too many indexes hurt performance
– Bad for the optimizer
– More IO, more CPU to update all the indexes
Redundant indexes must be removed
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
60
Remove same prefix indexes
Use ps_helper views
– schema_unused_indexes
Tip 31. Reduce rows_examined
Rows read from the storage engines
Rows_examined
– slow query log
Maybe the most important tip for InnoDB and queries !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
63
– P_S statement digests
– MEM 3.0 query analysis
– Handler%
rows_examined > 10 * rows_sent
– missing indexes
– query tuning !
Tip 31. Reduce rows_examined
select …
Diff
Per query handlers
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
64
Diff
Sum Handler%
Tip 31. Reduce rows_examined
slow query log
show engine innodb status
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
65
ps_helper
Tip 32. Reduce rows_sent
rows_sent <= rows_examined
Network transfers
CPU involved
Another performance killer
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
66
Apps seldom need more than 100 rows
LIMIT !
Tip 33. Reduce locking
UPDATE, SELECT FOR UPDATE, DELETE, INSERT SELECT
Use a PK ref, UK ref to lock
Avoid large index range and table scans
Make sure the right execution plan is used
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
67
Reduce rows_examined for locking SQL
Locking is expensive (memory, CPU)
Commit when possible
Tip 34. Mine the slow query log
Dynamic collection
The right interval
Top queries
Find the bad queries
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
68
– Sort by query time desc
perl mysqldumpslow.pl –s t slow.log
– Sort by rows_examined desc
Top queries at the 60s range
Tip 34. Mine the slow query log
SET @saved_slow_query_log = @@slow_query_log;
SET @saved_long_query_time = @@long_query_time;
SET global slow_query_log = 1;
SET global long_query_time = 0;
Log everything for 60 seconds to the slow query log :
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
69
SET global long_query_time = 0;
select sleep(60);
SET global slow_query_log = @saved_slow_query_log;
SET global long_query_time = @saved_long_query_time;
Tip 35. Use the performance_schema
ps_helper :
– good entry point
– ready to use views
The performance_schema is a great tool
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
70
– IO / latency / waits / statement digests
– ideal for dev and staging
– https://github.com/MarkLeith/dbahelper/archive/master.zip
For high performance systems, performance_schema = 0
Tip 36. Tune the replication thread
Slow query log with
– log-slow-slave-statements is now dynamic (Bug #59860) from 5.6.11
Performance_schema (Bug #16750433)
Usually replication is a black box
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
71
– Not instrumented before 5.6.14
binlog_format = ROW
– show global status like ‘Handler%’
Tip 37. Avoid temporary tables on disk
Large temporary tables on disk
– handler_write
– created_tmp_disk_tables
Writing to disk is not scalable !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
73
– monitor tmpdir usage
Frequent temporary tables on disk
– High created_tmp_disk_tables / uptime
– show global status like '%tmp%';
In 5.6, included in statement digests and ps_helper
Available in MEM 3.0
Tip 38. Cache data in the App
Good for CPU / IO
Cache the immutable !
– referential data
Save MySQL resources !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
74
– memcached
Query cache can be disabled
Identify frequent statements
– perl mysqldumpslow.pl –s c slow60s.log
Tip 39. Avoid long running transactions
Usually the oldest transactions
A frequent cause of performance drops
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
75
High history_list_length
Prevent the purge
Decrease performance
Kill if abandoned
Tip 40. Close idle connections
Idle connections consume resources !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
76
Either kill or refresh them !
– Connection pools : validation query
Tip 41. Close prepare statements
com_stmt_prepare – com_stmt_close ~= 0
Prepare and close must be balanced
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
77
Tip 42. Configure Connector / J
JDBC property for maximum performance :
– userConfigs=maxPerformance
Connectors must be tuned too !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
78
– Use if the server configuration is stable
– Removes frequent
SHOW COLLATION
SHOW GLOBAL VARIABLES
Fast validation query : /* ping */
Tip 43 - 45
43. Do not use the information_schema in your App
44. Views are not good for performance
– temporary tables (on disk)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
79
45. Scale out, shard
Tip 46. Monitor the database and OS
alerts
graphs
availability and SLAs
A monitoring tool is DBA’s friend :
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
82
availability and SLAs
the effect of tuning
query analysis
MySQL Enterprise Monitor 3.0 is GA !
SLA monitoring
Real-time performance monitoring
Alerts & notifications
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
83
Alerts & notifications
MySQL best practice advisors
"The MySQL Enterprise Monitor is an absolute must
for any DBA who takes his work seriously.”
- Adrian Baumann, System Specialist
Federal Office of Information Technology &
Telecommunications
Query Analyzer
Real-time query performance
Visual correlation graphs
Find & fix expensive queries
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
84
Find & fix expensive queries
Detailed query statistics
Query Response Time index (QRTi)
“With the MySQL Query Analyzer, we were able to
identify and analyze problematic SQL code, and triple
our database performance. More importantly, we were
able to accomplish this in three days, rather than
taking weeks.”
Keith Souhrada
Software Development Engineer
Big Fish Games
Tip 47. Backup the database
Backup is always needed !
Use MEB instead of mysqldump
– especially on large instances
Why is it a performance tip ?
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
87
mysqldump eats MySQL resources
mysqlbackup copies the data files (in parallel)
Tip 48. Optimize table and data files
Fragmentation …
– On disk only due to FS
– Inside InnoDB table spaces
Fragmentation decreases performance
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
88
– Occurs when modifying existing data
alter table … engine=InnoDB
– Fixes everything
Still blocking in 5.6
Tip 48. Optimize table and data files
There is no general formula
– except for fixed length records
create table t_defrag as
How to estimate fragmentation ?
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
89
select * from t
limit 10000;
– Fragmentation if Avg_row_length(t) > Avg_row_length(t_defrag)
Avg_row_length from show table status
Tip 49. Upgrade regularly
Security vulnerability fixes
Bug fixes
Performance improvements
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
90
Ready for the next GA
Do not upgrade without testing.
Tip 50. Perform regular health checks
MySQL Enterprise Monitor 3.0
– does it for you
Use Community tools
MySQL Support can help
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
91
Open a Service Request
– send the MEM support diagnostics zip to MySQL Support
“If everybody follows your advise we'll be looking for
new jobs”
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
92
Anonymous Support Colleague
Questions & Answers
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
93
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
95

More Related Content

Similar to 50-Tips-for-Boosting-MySQL-Performance-CON2655.pdf

8392-exadatamaa-1887964.pptx
8392-exadatamaa-1887964.pptx8392-exadatamaa-1887964.pptx
8392-exadatamaa-1887964.pptxRaniVuppal
 
MySQL Enterprise Backup & Oracle Secure Backup
MySQL Enterprise Backup &  Oracle Secure BackupMySQL Enterprise Backup &  Oracle Secure Backup
MySQL Enterprise Backup & Oracle Secure BackupSanjay Manwani
 
Exadata x4 for_sap
Exadata x4 for_sapExadata x4 for_sap
Exadata x4 for_sapFran Navarro
 
Using preferred read groups in oracle asm michael ault
Using preferred read groups in oracle asm michael aultUsing preferred read groups in oracle asm michael ault
Using preferred read groups in oracle asm michael aultLouis liu
 
A presentaion on Panasas HPC NAS
A presentaion on Panasas HPC NASA presentaion on Panasas HPC NAS
A presentaion on Panasas HPC NASRahul Janghel
 
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 2014Ryusuke Kajiyama
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 
MySQL Cluster Asynchronous replication (2014)
MySQL Cluster Asynchronous replication (2014) MySQL Cluster Asynchronous replication (2014)
MySQL Cluster Asynchronous replication (2014) Frazer Clement
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014Dave Stokes
 
New availability features in oracle rac 12c release 2 anair ss
New availability features in oracle rac 12c release 2 anair   ssNew availability features in oracle rac 12c release 2 anair   ss
New availability features in oracle rac 12c release 2 anair ssAnil Nair
 
Dataswft Intel benchmark 2013
Dataswft Intel benchmark 2013Dataswft Intel benchmark 2013
Dataswft Intel benchmark 2013dhulis
 
PoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAPoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAUlf Wendel
 
Ceph Day Beijing - Ceph all-flash array design based on NUMA architecture
Ceph Day Beijing - Ceph all-flash array design based on NUMA architectureCeph Day Beijing - Ceph all-flash array design based on NUMA architecture
Ceph Day Beijing - Ceph all-flash array design based on NUMA architectureCeph Community
 
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureCeph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureDanielle Womboldt
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimizationLouis liu
 
AIOUG-GroundBreakers-Jul 2019 - 19c RAC
AIOUG-GroundBreakers-Jul 2019 - 19c RACAIOUG-GroundBreakers-Jul 2019 - 19c RAC
AIOUG-GroundBreakers-Jul 2019 - 19c RACSandesh Rao
 
MySQL Performance - Best practices
MySQL Performance - Best practices MySQL Performance - Best practices
MySQL Performance - Best practices Ted Wennmark
 
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014Dave Stokes
 

Similar to 50-Tips-for-Boosting-MySQL-Performance-CON2655.pdf (20)

8392-exadatamaa-1887964.pptx
8392-exadatamaa-1887964.pptx8392-exadatamaa-1887964.pptx
8392-exadatamaa-1887964.pptx
 
Oracle Database 12c : Multitenant
Oracle Database 12c : MultitenantOracle Database 12c : Multitenant
Oracle Database 12c : Multitenant
 
MySQL Enterprise Backup & Oracle Secure Backup
MySQL Enterprise Backup &  Oracle Secure BackupMySQL Enterprise Backup &  Oracle Secure Backup
MySQL Enterprise Backup & Oracle Secure Backup
 
Exadata x4 for_sap
Exadata x4 for_sapExadata x4 for_sap
Exadata x4 for_sap
 
Using preferred read groups in oracle asm michael ault
Using preferred read groups in oracle asm michael aultUsing preferred read groups in oracle asm michael ault
Using preferred read groups in oracle asm michael ault
 
A presentaion on Panasas HPC NAS
A presentaion on Panasas HPC NASA presentaion on Panasas HPC NAS
A presentaion on Panasas HPC NAS
 
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
 
Session 307 ravi pendekanti engineered systems
Session 307  ravi pendekanti engineered systemsSession 307  ravi pendekanti engineered systems
Session 307 ravi pendekanti engineered systems
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 
MySQL Cluster Asynchronous replication (2014)
MySQL Cluster Asynchronous replication (2014) MySQL Cluster Asynchronous replication (2014)
MySQL Cluster Asynchronous replication (2014)
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
 
New availability features in oracle rac 12c release 2 anair ss
New availability features in oracle rac 12c release 2 anair   ssNew availability features in oracle rac 12c release 2 anair   ss
New availability features in oracle rac 12c release 2 anair ss
 
Dataswft Intel benchmark 2013
Dataswft Intel benchmark 2013Dataswft Intel benchmark 2013
Dataswft Intel benchmark 2013
 
PoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAPoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HA
 
Ceph Day Beijing - Ceph all-flash array design based on NUMA architecture
Ceph Day Beijing - Ceph all-flash array design based on NUMA architectureCeph Day Beijing - Ceph all-flash array design based on NUMA architecture
Ceph Day Beijing - Ceph all-flash array design based on NUMA architecture
 
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureCeph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimization
 
AIOUG-GroundBreakers-Jul 2019 - 19c RAC
AIOUG-GroundBreakers-Jul 2019 - 19c RACAIOUG-GroundBreakers-Jul 2019 - 19c RAC
AIOUG-GroundBreakers-Jul 2019 - 19c RAC
 
MySQL Performance - Best practices
MySQL Performance - Best practices MySQL Performance - Best practices
MySQL Performance - Best practices
 
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

50-Tips-for-Boosting-MySQL-Performance-CON2655.pdf

  • 1. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1
  • 2. 50 Tips for Boosting MySQL Performance Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 2 MySQL Performance Arnaud ADANT MySQL Principal Support Engineer
  • 3. Safe Harbour Statement 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 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 3 DECISIONS. THE DEVELOPMENT, RELEASE, AND TIMING OF ANY FEATURES OR FUNCTIONALITY DESCRIBED FOR ORACLE’S PRODUCTS REMAINS AT THE SOLE DISCRETION OF ORACLE.
  • 4. Program Agenda Introduction 50 MySQL Performance Tips Q & A Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 4 Q & A
  • 5. Introduction : Who I am http://blog.aadant.com 10 year+ Development MySQL Support for 3 years Arnaud ADANT Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 5 MySQL Support for 3 years MySQL Performance I love my job !
  • 6. Introduction : Why 50 ? Effective C++, Meyers, 1991 – 55 items 50 items is an effective format ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 6 Effective Java, Bloch, 2001 – 57 items
  • 7. Tip 0. Never trust anyone, benchmark Test, test, test Benchmark, benchmark, benchmark Monitor, monitor, monitor HW and SW vendors are all lying ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 11 One knob at a time Use sysbench, mysqlslap, monitoring tools
  • 8. Tip 1. Make sure you have enough RAM The active data should fit in the buffer pool MySQL connections and caches take memory ECC RAM recommended Depends on your active data and connections Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 13 Extra RAM for – FS cache – Monitoring – RAM disk (tmpfs)
  • 9. Tip 2. Use fast and multi-core processors Fast CPU is required for single threaded performance Recent servers have 32 to 80 cores. Enable hyper-threading Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 14 MySQL can only scale to 16 cores in 5.5 and 32-48 cores in 5.6 Same core count in fewer sockets is better Faster cores better than more but slower cores
  • 10. Tip 3. Use fast and reliable storage Good for IO bound loads HDD for sequential reads and writes Bus-attached SSD for random reads and writes Will always help Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 15 Big sata or other disk for log files Several disks ! Life time
  • 11. Tip 4. Choose the right OS L of LAMP Good on Solaris Oracle invests on Windows MySQL is excellent on Linux Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 18 For pure performance, favor Linux
  • 12. Tip 5. Adjust the OS limits Max open files per process – ulimit –n – limits the number of file handles (connections, open tables, …) OS limits are extremely important ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 19 Max threads per user – ulimit –u – limits the number of threads (connections, event scheduler, shutdown) On Windows, MaxUserPort for TCP/IP, for 2003 and earlier
  • 13. Tip 6. Consider using alternative malloc jemalloc is a good malloc replacement [mysqld_safe] Some malloc libraries are optimized for multi-core environment Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 20 malloc-lib=/usr/lib64/libjemalloc.so.1 tcmalloc shipped on Linux with MySQL [mysqld_safe] malloc-lib=tcmalloc
  • 14. • Sysbench OLTP RO • High concurrency Tip 6. Consider using alternative malloc Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 21
  • 15. Tip 7. Set CPU affinity taskset command on Linux taskset -c 1-4 `pidof mysqld` On Linux and Windows, CPU affinity helps concurrent WL Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 22 taskset -c 1,2,3,4 `pidof mysqld` On Windows : START /AFFINITY 0x1111 binmysqld –console START /AFFINITY 15 binmysqld –console
  • 16. Tip 8. Choose the right file system • xfs is excellent • With innodb_flush_method = O_DIRECT • supported by Oracle on OEL XFS for experts, ext4 or ext3 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 25 • less stable recently • ext4 best choice for speed and ease of use • fsyncs a bit slower than ext3 • more reliable • ext3 is also a good choice • DYI nfs is problematic with InnoDB
  • 17. Tip 9. Mount options • ext4 (rw,noatime,nodiratime,nobarrier,data=ordered) • xfs (rw, noatime,nodiratime,nobarrier,logbufs=8,logbsize=32k) • SSD specific For performance Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 26 • trim • innodb_page_size = 4K • Innodb_flush_neighbors = 0
  • 18. Tip 10. Choose the best I/O scheduler deadline is generally the best I/O scheduler echo deadline > /sys/block/{DEVICE-NAME}/queue/scheduler the best value is HW and WL specific noop Use deadline or noop on Linux Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 27 – noop on high end controller (SSD, good RAID card …) – deadline otherwise
  • 19. Tip 11. Use a battery backed disk cache Usually faster fsyncs – innoDB redo logs – binary logs A good investment ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 28 – data files Crash safety Durability Applies to SSD
  • 20. Tip 12. Balance the load on several disks One disk is not a good idea Especially for HDD, read and write Separate : 90 % of customers use a single disk ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 29 – datadir – innodb_data_file_path – innodb_undo_directory – innodb_log_group_home_dir – log-bin – tmpdir Random, SSD Sequential, spinning Random, SSD, tmpfs
  • 21. 13. Turn Off the Query Cache Only if threads_running <= 4 Becomes fragmented • Cache should be in the App ! Single threaded bottleneck, only on low concurrency systems Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 32 • Off by default from 5.6 • query_cache_type = 0 • query_cache_size =0
  • 22. • Sysbench OLTP RO • QPS drops with connections and QC Tip 13. Turn Off the Query Cache 20000 30000 40000 50000 TPS QC = on TPS QC = off Qcache_free_blocks Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 33 • qcache_free_blocks > 5-10k 0 10000 1 2 4 8 16 Qcache_free_blocks connections QPS
  • 23. Tip 13. Turn Off the Query Cache qcache_free_blocks > 5-10k stage/sql/Waiting for query cache lock How to see there is a problem ? Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 34
  • 24. • Stabilize TPS for high concurrency • Useful if threads_running > Tip 14. Use the Thread Pool Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 35 threads_running > hardware threads • Decrease context switches • Several connections for one execution thread
  • 25. Tip 15. Configure table caching table_open_cache – not too small, not too big, used to size PS – opened_tables / sec MySQL has at least one file per table : the FRM file Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 36 table_definition_cache – do not forget to increase – opened_table_definitions / sec table_cache_instances = 8 or 16 innodb_open_files mdl_hash_instances = 256
  • 26. Tip 15. Configure table caching concurrency concurrency Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 37 16 instances 1 instance concurrency concurrency TPS
  • 27. Tip 16. Cache the threads thread_cache_size – decreases threads_created rate capped by max user processes (see OS limits) Thread creation / initialization is expensive Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 38 5.7.2 refactors this code
  • 28. Tip 17. Reduce per thread memory usage max_used_connections * ( read_buffer_size + read_rnd_buffer_size + Memory allocation is expensive Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 39 join_buffer_size + sort_buffer_size + binlog_cache_size + thread_stack + 2 * net_buffer_length … )
  • 29. • sysbench RW • sync_binlog = 1 was a performance killer in 5.5 Tip 18. Beware of sync_binlog = 1 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 41 5.5 • 5.6 binlog group commit fixed it • Better with SSD or battery backed disk cache
  • 30. Tip 19. Move your tables to InnoDB Scalable 99% of MyISAM use cases covered Online alter operations InnoDB is the most advanced MySQL storage engine Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 42 Full text engine Memcached API for high performance
  • 31. Tip 20. Use a large buffer pool innodb_buffer_pool_size Not too large for the data Do not swap ! 50 – 80% of the total RAM Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 45 Beware of memory crash if swapping is disabled Active data <= innodb_buffer_pool_size <= 0.8 * RAM
  • 32. Tip 21. Reduce the buffer pool contention innodb_buffer_pool_instances >= 8 Reduce rows_examined / sec (see Bug #68079) 8 is the default value in 5.6 ! Key to achieve high QPS / TPS Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 46 In 5.5, but even better in 5.6 and 5.7 innodb_spin_wait_delay = 96 on high concurrency Use read only transactions – when possible
  • 33. Tip 21. Reduce the buffer pool contention Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 47
  • 34. Tip 22. Use large redo logs Redo logs defer the expensive changes to the data files Recovery time is no more an issue innodb_log_file_size = 2047M before 5.6 A key parameter for write performance Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 48 innodb_log_file_size >= 2047M from 5.6 Bigger is better for write QPS stability
  • 35. Tip 22. Use large redo logs Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 49
  • 36. Tip 23. Adjust the IO capacity IO OPS the disk(s) can do Higher for SSD Increase if several disks for InnoDB IO innodb_io_capacity should reflect device capacity Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 50 In 5.6, innodb_lru_scan_depth is per buffer pool instance so innodb_lru_scan_depth = innodb_io_capacity / innodb_buffer_pool_instances Default innodb_io_capacity_max = min(2000, 2 * innodb_io_capacity)
  • 37. Tip 24. Configure the InnoDB flushing Redo logs : – innodb_flush_log_at_trx_commit = 1 // best durability – innodb_flush_log_at_trx_commit = 2 // better performance Durability settings Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 51 – innodb_flush_log_at_trx_commit = 0 // best performance Data files only : – innodb_flush_method = O_DIRECT // Linux, skips the FS cache Increase innodb_adaptive_flushing_lwm (fast disk)
  • 38. Tip 25. Enable innodb_file_per_table Increased manageability Truncate reclaims disk space Better with innodb_flush_method = O_DIRECT innodb_file_per_table = ON is the default in 5.6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 53 Easier to optimize But … – not so good with many small tables – more file handles (see OS limits) – more fsyncs
  • 39. Tip 26. Configure the thread concurrency No thread pool : – innodb_thread_concurrency = 16 - 32 in 5.5 – innodb_thread_concurrency = 36 in 5.6 innodb_thread_concurrency / innodb_max_concurrency_tickets Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 54 – align to HW threads if less than 32 cores Thread pool : – innodb_thread_concurrency = 0 is fine innodb_max_concurrency_tickets : higher for OLAP, lower for OLTP
  • 40. Tip 27. Reduce the transaction isolation Application dependent Read committed – it implies binlog_format = ROW Default = repeatable reads Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 55 Variable : transaction-isolation Lower isolation = higher performance
  • 41. Tip 28. Design the tables integer primary keys – avoid varchar, composite for PK latin1 vs. utf8 Choose the charset, PK and data types carefully Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 58 the smallest varchar for a column keep the number of partitions low (< 10) use compression for blob / text data types
  • 42. Tip 29. Add indexes for fast access to records for sorting / grouping – without temporary table Indexes help decrease the number of rows examined Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 59 covering indexes – contain all the selected data – save access to full record – reduce random reads
  • 43. Tip 30. Remove unused indexes Too many indexes hurt performance – Bad for the optimizer – More IO, more CPU to update all the indexes Redundant indexes must be removed Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 60 Remove same prefix indexes Use ps_helper views – schema_unused_indexes
  • 44. Tip 31. Reduce rows_examined Rows read from the storage engines Rows_examined – slow query log Maybe the most important tip for InnoDB and queries ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 63 – P_S statement digests – MEM 3.0 query analysis – Handler% rows_examined > 10 * rows_sent – missing indexes – query tuning !
  • 45. Tip 31. Reduce rows_examined select … Diff Per query handlers Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 64 Diff Sum Handler%
  • 46. Tip 31. Reduce rows_examined slow query log show engine innodb status Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 65 ps_helper
  • 47. Tip 32. Reduce rows_sent rows_sent <= rows_examined Network transfers CPU involved Another performance killer Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 66 Apps seldom need more than 100 rows LIMIT !
  • 48. Tip 33. Reduce locking UPDATE, SELECT FOR UPDATE, DELETE, INSERT SELECT Use a PK ref, UK ref to lock Avoid large index range and table scans Make sure the right execution plan is used Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 67 Reduce rows_examined for locking SQL Locking is expensive (memory, CPU) Commit when possible
  • 49. Tip 34. Mine the slow query log Dynamic collection The right interval Top queries Find the bad queries Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 68 – Sort by query time desc perl mysqldumpslow.pl –s t slow.log – Sort by rows_examined desc Top queries at the 60s range
  • 50. Tip 34. Mine the slow query log SET @saved_slow_query_log = @@slow_query_log; SET @saved_long_query_time = @@long_query_time; SET global slow_query_log = 1; SET global long_query_time = 0; Log everything for 60 seconds to the slow query log : Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 69 SET global long_query_time = 0; select sleep(60); SET global slow_query_log = @saved_slow_query_log; SET global long_query_time = @saved_long_query_time;
  • 51. Tip 35. Use the performance_schema ps_helper : – good entry point – ready to use views The performance_schema is a great tool Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 70 – IO / latency / waits / statement digests – ideal for dev and staging – https://github.com/MarkLeith/dbahelper/archive/master.zip For high performance systems, performance_schema = 0
  • 52. Tip 36. Tune the replication thread Slow query log with – log-slow-slave-statements is now dynamic (Bug #59860) from 5.6.11 Performance_schema (Bug #16750433) Usually replication is a black box Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 71 – Not instrumented before 5.6.14 binlog_format = ROW – show global status like ‘Handler%’
  • 53. Tip 37. Avoid temporary tables on disk Large temporary tables on disk – handler_write – created_tmp_disk_tables Writing to disk is not scalable ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 73 – monitor tmpdir usage Frequent temporary tables on disk – High created_tmp_disk_tables / uptime – show global status like '%tmp%'; In 5.6, included in statement digests and ps_helper Available in MEM 3.0
  • 54. Tip 38. Cache data in the App Good for CPU / IO Cache the immutable ! – referential data Save MySQL resources ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 74 – memcached Query cache can be disabled Identify frequent statements – perl mysqldumpslow.pl –s c slow60s.log
  • 55. Tip 39. Avoid long running transactions Usually the oldest transactions A frequent cause of performance drops Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 75 High history_list_length Prevent the purge Decrease performance Kill if abandoned
  • 56. Tip 40. Close idle connections Idle connections consume resources ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 76 Either kill or refresh them ! – Connection pools : validation query
  • 57. Tip 41. Close prepare statements com_stmt_prepare – com_stmt_close ~= 0 Prepare and close must be balanced Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 77
  • 58. Tip 42. Configure Connector / J JDBC property for maximum performance : – userConfigs=maxPerformance Connectors must be tuned too ! Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 78 – Use if the server configuration is stable – Removes frequent SHOW COLLATION SHOW GLOBAL VARIABLES Fast validation query : /* ping */
  • 59. Tip 43 - 45 43. Do not use the information_schema in your App 44. Views are not good for performance – temporary tables (on disk) Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 79 45. Scale out, shard
  • 60. Tip 46. Monitor the database and OS alerts graphs availability and SLAs A monitoring tool is DBA’s friend : Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 82 availability and SLAs the effect of tuning query analysis
  • 61. MySQL Enterprise Monitor 3.0 is GA ! SLA monitoring Real-time performance monitoring Alerts & notifications Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 83 Alerts & notifications MySQL best practice advisors "The MySQL Enterprise Monitor is an absolute must for any DBA who takes his work seriously.” - Adrian Baumann, System Specialist Federal Office of Information Technology & Telecommunications
  • 62. Query Analyzer Real-time query performance Visual correlation graphs Find & fix expensive queries Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 84 Find & fix expensive queries Detailed query statistics Query Response Time index (QRTi) “With the MySQL Query Analyzer, we were able to identify and analyze problematic SQL code, and triple our database performance. More importantly, we were able to accomplish this in three days, rather than taking weeks.” Keith Souhrada Software Development Engineer Big Fish Games
  • 63. Tip 47. Backup the database Backup is always needed ! Use MEB instead of mysqldump – especially on large instances Why is it a performance tip ? Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 87 mysqldump eats MySQL resources mysqlbackup copies the data files (in parallel)
  • 64. Tip 48. Optimize table and data files Fragmentation … – On disk only due to FS – Inside InnoDB table spaces Fragmentation decreases performance Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 88 – Occurs when modifying existing data alter table … engine=InnoDB – Fixes everything Still blocking in 5.6
  • 65. Tip 48. Optimize table and data files There is no general formula – except for fixed length records create table t_defrag as How to estimate fragmentation ? Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 89 select * from t limit 10000; – Fragmentation if Avg_row_length(t) > Avg_row_length(t_defrag) Avg_row_length from show table status
  • 66. Tip 49. Upgrade regularly Security vulnerability fixes Bug fixes Performance improvements Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 90 Ready for the next GA Do not upgrade without testing.
  • 67. Tip 50. Perform regular health checks MySQL Enterprise Monitor 3.0 – does it for you Use Community tools MySQL Support can help Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 91 Open a Service Request – send the MEM support diagnostics zip to MySQL Support
  • 68. “If everybody follows your advise we'll be looking for new jobs” Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 92 Anonymous Support Colleague
  • 69. Questions & Answers Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 93
  • 70. Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 95