8. Replication Binary Log Group Commit
• Days of losing 50%+
master performance
are gone!
• 10% overhead when
configuring
sync_binlog=0
• Additional 5% when
configuring
sync_binlog=1
https://blogs.oracle.com/MySQL/entry/mysql_5_6_replication_performance
11. • Simple word but many meanings
• Main objective:
• Users (direct or indirect) should be satisfied
• Most typical performance metrics
• Throughput
• Latency / Response time
• Scalability
• Combined metrics
Starvation
transactions/time
Defining Performance
12. • Multi User applications
• Request waits in queue before being processed
• User response time = queueing delay + service time
• Non high tech example – support call center.
• “Hockey Stick” - queuing delay grows rapidly when
system getting close to saturation
• Need to improve queueing delay or service time
to improve performance
• Improving service time reduces queuing delay
Connections
ResponseTime
Queuing Theory
13. • Main Question – where does service time comes from ?
• network, cpu, disk, locks...
• Direct Measurements
• Sum up all query times from web pages
• Indirect measurements
• CPU usage
• Disk IO latency
• Network traffic
• Load Average
• Number of running queries
• etc.
Service Time: Key to the hotspot
14. Benchmark Tests
• Great tool to:
• Quantify application performance
• Measure performance effect of the changes
• Validate Scalability
• Plan deployment
• But
• Can be very misleading if done wrong
• Need to be able to read results correctly
• Typical Errors
• Testing with 1GB size with 100G in production
• Using uniform distribution
• “Harry Potter” ordered as frequent as Zulu dictionary
• Testing in single user scenario
15. Benchmark Tools for MySQL
• Creating own benchmark tool
– Generating from SQL statements in General Log
– Fetching SQL statements with MySQL Proxy or TCP Dump
• DBT2
– http://osdldbt.sourceforge.net/
– http://nippondanji.blogspot.com/2009/03/dbt-2.html
• mysqlslap MySQL 5.1 +
– http://dev.mysql.com/doc/refman/5.6/en/mysqlslap.html
• SysBench
– http://sysbench.sourceforge.net/
16. • Performance costs money, whatever road you take
• Investigate different possibilities
• Better hardware could be cheaper than a major rewrite
• How much performance/scalability/reliability do you need ?
• 99.999% could be a lot more expensive than 99.9%
• Is peak traffic requirements 100x average or just 3x ?
• Take a look at whole picture
• Is this the largest risk/bottleneck ?
• Identify which optimizations are critical for business
• Optimization of “everything” is often waste of resources
• What is the cost of suboptimal performance ?
Business side of optimization
17. Basic1: Checking Server Configurations
• The MySQL server is controlled by “System Variables”
• Set via:
• Option File: my.cnf / my.ini
• Temporary change: SET [GLOBAL] <vriable>=<value>
• Can be per connection (LOCAL) or server wide(GLOBAL)
18. Basic2: Checking Status of Server
Monitor system performance using “Status Variables”
• Knowing internal commands of one query
Mysql> FLUSH STATUS; <run query>; SHOW STATUS;
• Checking status periodically
shell> mysqladmin -u -p ... ex -i 15 -r | grep -v ‘ 0 ‘
http://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html
19. Client2 ClientN
Connection Thread Pool
Parser Query 101101
Client1
Optimizer
Storage Engines
InnoDB
MyISAM
MERGE
MEMORY
ARCHIVE
Query Cache
MySQL Server
MySQL Server Architecture
20. • max_connections (151)
• number of connections server will
allow. May run out of memory if too
high, because of per connections
memory usage
• thread_cache_size (8)
• Keep up to this amount of threads
“cached” after disconnect
• Typical setting
max_connections/3
Client2 ClientN
Connection Thread Pool
Client1
mysql> show status;
• Max_used_connections
• check if it matches
max_connections, too low value or
sign of overload
• Threads_created
• thread_cache misses
• should be low.
Server Connections & Threads
21. • sort_buffer_size (2M)
• Memory to allocate for sort. Will use
disk based sort for larger data sets.
Often fine at 512K or 1M
• other buffers, read,
read_rnd, etc… smaller
defaults often OK
• You can change dynamically if
large sort operation is needed
in batch operation etc
Client2 ClientN
Connection Thread Pool
Client1
mysql> show status;
• Sort_merge_passes -
• number of passes made
during file merge sort.
• check if file sort needs to be
done at all
• use index if possible
Connection Thread Work Buffers
22. • query_cache_size (0)
• Amount of memory to use for query
cache
• Typically 32M is fine, some
databases need 128M
• query_cache_type (ON)
• Worst case performance overhead
is about 15%-20%
• Favors servers with higher
SELECT/WRITE ratios
• Best Practice
• Set to DEMAND
• Add SQL_CACHE to appropriate
queries
Connection Thread Pool
Parser Query 101101
Query Cache
mysql> show status;
• Qcache_hits, Qcache_inserts
• hits/inserts cache hit ratio, if small, maybe
disable query cache
• Qcache_lowmem_prunes
• times older queries were removed due to
low memory, need to increase
query_cache_size if high
Server Query Cache
23. • innodb_buffer_pool_size
• 80% of memory on Innodb only system
• caches data & indexes unlike MyISAM
• innodb_log_file_size
• A key parameter for write performance
• Recovery time is no more an issue.
• Bigger is better for write QPS stability
• innodb_flush_log_at_trx_commit
• 1 (slow) will flush (fsync) log at each commit. Truly
ACID
• 2 (fast) will only flush log buffer to OS cache on
commit, sync to disk once/sec.
• 0 (fastest) will flush (fsync) log every second or so
• innodb_file_per_table
• Always good choice to distribute i/o
• Default ON from 5.6
Storage Engines
InnoDB
MyISAM
MERGE
MEMORY
ARCHIVE
mysql> SHOW ENGINE
INNODB STATUS;
Great way to see what is
going on inside InnoDB,
hard to parse
• File IO
• Buffer Pool
• Log activity
• Row activity
InnoDB Performance Tips
24. • innodb_flush_method = O_DIRECT
• Not to consume OS cache
• innodb_buffer_pool_instances (5.5+)
• To avoid mutex contention
• 2 or more in can
• innodb_io_capacity (5.5+)
• Enlarge if you have fast disks
• Default 200 is good for 2 disks striped
• innodb_read_io_threads (5.5+)
• innodb_write_io_threads (5.5+)
• Enlarge if you have fast disks
• Default 4 is usually good enough
Storage Engines
InnoDB
MyISAM
MERGE
MEMORY
ARCHIVE
mysql> SHOW ENGINE
INNODB STATUS;
Great way to see what is
going on inside InnoDB,
hard to parse
• File IO
• Buffer Pool
• Log activity
• Row activity
InnoDB Performance Tips (Cont.)
25. 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%
Semi-in-memory Database with InnoDB
• 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
26. • Normalization
• good for OLTP, writes
• data redundancies eliminated
• join performance penalty
• smaller total data set
• E/R diagram clean translation
• Denormalization
• good for OLAP, reporting
• data redundancies across tables
for better indexing
• maybe eliminate joins
• Data types
– use tinyint, smallint, mediumint,
save space!
– join columns same data type
– varchar(64) instead of char(64)
– declare NOT NULL if true
– varchar(64) instead of varchar(255)
– INT not DECIMAL(9)
• Indexing
– multi-column
– ordered BTREE
– index prefixes
– covering
Schema Design
27. #Time: 08073101 16:25:24
#User@Host: root[root] @ localhost [127.0.0.1]
#Query_time: 8 Lock_time: 0 Rows_sent: 20 Rows_examined: 243661
SELECT part_num FROM `inventory`.`parts` WHERE
(`ven` = "foo") ORDER BY `delivery_datetime` DESC LIMIT 100;
Monitoring Queries - Slow Query Log
Cons
• Requires MySQL restart (5.0 and lower)
• Growth must be managed using FLUSH LOGS
• Entries must be parsed/sorted for relevance
• mysqldumpslow helps, but still tedious, takes time
Pros
• Logs queries that took longer than X (user defined)
• Logs queries that do not use indexes (5.0 and higher)
• Includes data needed to trace offending queries
28. Monitoring Queries – SHOW PROCESSLIST;
mysql> SHOW FULL PROCESSLISTG
******** 1. row *****************
Id: 1
User: MyUser
Host: localhost
db: inventory
Command: Query
Time: 1030455
State: Sending Data
Info: SELECT part_num from ‘inv’;
…..
2 rows in set (0.00 sec)
Pros
• Shows current processes
• Shows status of executing
queries
• Includes data needed to trace
offending queries
Con
Scripting needed to:
• automate,
• integrate with Slow Query Log,
• Aggregate/parse results for
analysis,
• notify DBA of problem
29. Fixing Problem Queries – EXPLAIN;
EXPLAIN SELECT part_num
FROM `inventory`.`parts`
WHERE (`ven` = "foo")
ORDER BY `delivery_datetime`
DESC LIMIT 100;G
******** 1. row *************
ID: 1
select_type: SIMPLE
table: parts
type: ref
possible_keys: ven, part#
key: ven
key_len: 3
ref: null
rows: 872
Extra: Using WHERE
1 row in set (0.00 sec)
Analyze
• How indexes are being used (or
not…)
• required filesorts
• What tables, columns are being
queried
Fix/Tune - involves iterations of:
• Add/alter indexes
• Alter tables, columns, datatypes
• Alter query structure
• Test, 10 GOTO 10 until done
32. MySQL Enterprise Scalability
MySQL Thread Pool
• MySQL default thread-handling – excellent
performance, can limit scalability as connections grow
• MySQL Thread Pool improves sustained
performance/scale as user connections grow
• Thread Pool API
New!
Since Oracle acquired Sun we have delivered A TON of MySQL Innovation
Go through the different deliverables
We’ve improved the MySQL experience for users, customers, for folks using MySQL on Windows, for Oracle customers using MySQL...etc
In case anyone still has any doubt about Oracle’s commitment to MySQL, those doubts clearly can be put to rest. We’re delivering more than ever before in MySQL’s history, and will continue to do so.
MySQL is in an incredibly favorable position, and the platform of choice for next generation Web, mobile and cloud applications.
It is....(the 4 key points)
We’re also seeing great momentum for MySQL: talk about 3 points on the side
We want to ensure that MySQL remains the platform of choice for next gen web apps, and we are evolving the database by developing new features, enhancements and integrating in it new capabilities useful for modern apps. Give example of the 2 other points in orange (NoSQL and new languages)
MySQL 5.6 delivers across the board improvements designed to enable innovative DBAs and Developers to create and deploy the next generation of web, embedded and Cloud/SaaS/DaaS applications on the latest generation of development frameworks and hardware platforms.
At a glance, MySQL 5.6 is simply a better MySQL with improvements that enhance every functional area of the database kernel, including:
Improved Performance Scalability
5.6 scales up 48 CPU threads which enables users to leverage the full processing power of modern architectures
5.6 performs up to 230% faster over 5.5 on transactional work loads.
Improved InnoDB
Allow 5.6 to provide better transactional throughput and availability over previous versions.
Improved Optimizer
Provides better query execution times and more diagnostics for monitoring, tuning and debugging
Impoved Replication
Provides higher performance, availability and data integrity
Improved Performance Schema
Provides better instrumentation and user/application level statistics and monitoring
New! NoSQL Access to InnoDB
Provides fast, Key Value access with full ACID compliance, better developer agility
Improved InnoDB storage engine for better transactional throughput
Improved Optimizer for better query execution times and diagnostics
Better Application Availability with Online DDL/Schema changes
Better Developer Agility with NoSQL Access with Memcached API to InnoDB
Improved Replication for high performance, self-healing distributed deployments
Improved Performance Schema for better instrumentation
Improved Security for worry-free application deployments
And other Important Enhancements
In MySQL 5.6 performance has been improved to provide better linear performance and scale on systems supporting multi-processors and high CPU thread concurrency.
Internal benchmarks for SysBench Read/Write and Read Only workloads show a marked improvement in scale over the most current version of MySQL 5.5.
For Linux, SysBench Read/Write benchmarks show that 5.6 scales “up and to the right” on &gt; 48 CPU threads/cores.
Similar improvements have been delivered on Windows.
For Linux, SysBench Read Only benchmarks show that 5.6 performance is improved up to 234% over 5.5 at the same user concurrency.
Similar improvements have been delivered on Windows.
Many of the latest generation of web, cloud, social and mobile applications require fast operations against simple Key/Value pairs. At the same time, they must retain the ability to run complex queries against the same data, as well as ensure the data is protected with ACID guarantees. With the new NoSQL API for InnoDB, developers have all the benefits of a transactional RDBMS, coupled with the performance capabilities of Key/Value store.
MySQL 5.6 provides simple, key-value interaction with InnoDB data via the familiar Memcached API. Implemented via a new Memcached daemon plug-in to mysqld, the new Memcached protocol is mapped directly to the native InnoDB API and enables developers to use existing Memcached clients to bypass the expense of query parsing and go directly to InnoDB data for lookups and transactional compliant updates. The API makes it possible to re-use standard Memcached libraries and clients, while extending Memcached functionality by integrating a persistent, crash-safe, transactional database back-end.
Real-time MySQL Performance and Availability Monitoring
Visual Dashboad for Better Visibility
Visually Find and Fix Problem Queries
Pinpoint SQL code that causing a slowdown
Visual Capacity Planning
Forecasting using Projections and Trend Analysis
Agentless, Cloud Friendly Architecture
Remotely Monitor MySQL without agents
Start Monitoring MySQL in 10 minutes
Easy to use with zero configuration