SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
<Insert Picture Here>




MySQL Cluster –
Performance Tuning
Johan Andersson
Principal Field Technologist
The presentation is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
General Design Principles

•  MySQL Cluster is designed for
   •  Short transactions
   •  Many parallel transactions
•  Utilize Simple access patterns to fetch data
   •  Solution that scales!
•  Analyze what your most typical use cases are
   •  optimize for those

              Overall design goal
       Minimize network roundtrips for your
            most important requests!
General Design Principles

•  Application spaces where Cluster is being used heavily
   •    Subscriber databases (telecom)
   •    Session management
   •    Online gaming
   •    Finance
   •    E-commerce
   •    As a Shard catalog in web 2.0 shops
•  The key denominator for all these applications are:
   •  high throughput, low response times, high-availability, and
      simple access patterns.
•  Reporting is typically performed on a subsystem
   •  Replicate to a slave (e.g, MYISAM or INNODB database)
Tuning Options
               •  e-normalization
                D
Schema
               •  ptimize data types
                O
Optimization
               •  atching
                B
Query Tuning   •  ewrite slow queries
                R
               • ndex Tuning
                I

Parameter      •  se a good Configuration (affects mostly stability)
                U
Tuning         •  ainly MySQL server parameters
                M


Network / OS   •  une Network (TCP) buffers (not the scope of this presentation)
                T
Tuning         •  luster Interconnects
                C


Hardware       •  aster CPU/Disk (not the scope of this presentation)
                F
Tuning
Detecting Problems – PT 101
•  Enable the slow query log!
   •    set global slow_query_log=1;
   •    set global long_query_time=3; //3 seconds
   •    set global log_queries_not_using_indexes=1;
   •    Slow queries will be written in the slow query log:
        mysql> show global variables like 'slow_query_log_file';
        +---------------------+------------------------------+
        | Variable_name       | Value                        |
        +---------------------+------------------------------+
        | slow_query_log_file | /data1/mysql/mysqld-slow.log |
        +---------------------+------------------------------+
        1 row in set (0.00 sec)

•  Slow Queries will be written in plain text.
   •  Or use MEM (but MEM cannot monitor data nodes)
Detecting Problems – PT 101
BEGIN
  1.  Start by analyzing the slow query log
       Change long_query_time if needed
   2.  Use EXPLAIN to figure out if the query is
       • Using the correct indexes
       • JOINing the tables in the wrong order
       • so bad it needs to be rewritten.
   3.  Re-run the optimized typical use cases using
       mysqlslap
   4.  GOTO BEGIN;
END;
•  Other tools such as mysqlsla can also be used
•  Performance tuning is a never-ending task.
•  Never tune unless you can measure and test
•  Don't optimize unless you have a problem
Tuning Options
               •  e-normalization
                D
Schema
               •  ptimize data types
                O
Optimization
               •  atching
                B
Query Tuning   •  ewrite slow queries
                R
               • ndex Tuning
                I

Parameter      •  se a good Configuration (affects mostly stability)
                U
Tuning         •  ainly MySQL server parameters
                M


Network / OS   •  une Network (TCP) buffers (not the scope of this presentation)
                T
Tuning         •  luster Interconnects
                C


Hardware       •  aster CPU/Disk (not the scope of this presentation)
                F
Tuning
Schema Optimization - Data Types

•  Denormalize tables
  •  Tables having the same PRIMARY KEY can be denormalized
•  Change Data Types
  •  Does an EMAIL need to be a TEXT?
Schema Optimization -
 Denormalization
•  Two tables with the same PRIMARY KEY can be
   denormalized into a single table:




          •  SER_SVC_VOIP
           U                           •  SER_SVC_BROADBAND
                                        U

  •  Requires two roundtrips to get data
•  Denormalize:



                            •  SER_SVC_VOIP_ BB
                             U
Schema Optimization -
 Denormalization
•  Normalized:
   •  SELECT * FROM
      USER_SVC_BROADBAND AS bb, USER_SVC_VOIP AS
      voip
      WHERE bb.id=voip.id AND bb.id=1;
   •  Total throughput = 12623.09 tps
   •  Average response time=658us
•  Denormalized:
   •  SELECT * FROM USER_SVC_VOIP_BB AS bb_voip
      WHERE bb_voip=1;
   •  Total throughput = 21591.64 tps
   •  Average response time=371us
Schema Optimization – Data Types

•  BLOB/TEXT columns are stored in an external
   hidden table.
   •  First 255B are stored inline in main table
   •  Reading a BLOB/TEXT requires two reads
   •  Read without lock will be upgraded to shared lock!
•  Reading/Writing a VARCHAR/VARBINARY is less
   expensive.
•  Change to VARBINARY/VARCHAR if:
   •  Your BLOBs/TEXTs can fit within an 8052B record (and
      you need a 4B PK as well)
   •  (record size is currently 8052 Bytes)
Schema Optimization – Data Types
•  SELECT data1, data2 FROM t1 WHERE
   id=<rand>
   •  sizeof(data1) = 1024B, sizeof(data2) = 1024B.
•  1 App - 8 Threads , 1 MySQLD, 2 Data nodes
•  data1 and data2 represented as BLOBs
   •  5844 TPS
•  data1 and data2 represented as VARBINARYs
   •  19206 TPS

•  Note 1: BLOB/TEXT are also more expensive in Innodb as BLOB/
   TEXT data is not inlined with the table. Thus, two disk seeks are
   needed to read a BLOB.
•  Note 2: We recommend (for any storage engine) to store images,
  movies etc outside the database on the filesystem.
Schema Optimzation - PK selection

•  Engineer your schema for the problem you need to
   solve!
   •  Call setup? Locate all friends of a user?
•  Very common…                                     UNIQUE KEY
                          PK
                      ID (auto_inc)     USER_ID         FRIEND_ID
                      1                 10001           11000
                      2                 10001           11001
                      3                 10001           11002
                      4                 10002           12022
•  Better:
   •  Introduce PK <USER_ID, FRIEND_ID>
   •  Get rid of column ID
   •  Get rid of the UNIQUE (as it is now the PK)
Tuning Options
               •  e-normalization
                D
Schema
               •  ptimize data types
                O
Optimization
               •  atching
                B
Query Tuning   •  ewrite slow queries
                R
               • ndex Tuning
                I

Parameter      •  se a good Configuration (affects mostly stability)
                U
Tuning         •  ainly MySQL server parameters
                M


Network / OS   •  une Network (TCP) buffers (not the scope of this presentation)
                T
Tuning         •  luster Interconnects
                C


Hardware       •  aster CPU/Disk (not the scope of this presentation)
                F
Tuning
Simple Access Patterns

•  Simple Access Patterns are key to build scalable and
   high performing solutions (this is not subject to
   Cluster only)
  •  PRIMARY KEY lookups are done in constant time O(1
     •  Fastest way to access data in MySQL Cluster
  •  INDEX searches are done in O(log n) time.
  •  JOINs are ok if you understand what can make them slow.
     •  If your most important requests are 10-way JOINs with
        huge result sets then Cluster may not be for you.
     •  Or use scale out (write to cluster read from innodb): http://
        johanandersson.blogspot.com/2009/05/ha-mysql-write-scaling-
        using-cluster-to.html
Operation Cost

•  Cost of typical operations (depends on HW/Network)




  •  Synchronous replication adds ~2.1x - 2.8x for writes
     compared to reads
  •  Index scan takes 2.4x longer than PK read
  •  Test was with 8 threads connecting to one mysqld
  •  'bencher' was used to generate the load. (Xeon 5160 @
     3.00GHz)
Batching

•  MySQL Cluster allows batching on
  •  INSERT (PK)
  •  Most PK UPDATE
  •  DELETE (PK)
  •  SELECT (PK and some INDEX scans and not in JOINs)
•  Batching means
  •  One transaction with >1 operation are executed in one round-
     trip
Batching

•  Example – Insert 1M records
  •  No batching:
      • INSERT INTO t1(data) VALUES (<data>);
  •  Batching (batches of 16):
      • INSERT INTO t1(<columns>) VALUES (<data0>),
        (<data1>)..., (<data15>)
  •  50 seconds to insert 1M records
  •  15 times faster!
Batching
•  Read 10 records services for a user:
  •  PK is <userid, friend_id>
•  Batching (batches of 10):
  •  SELECT * FROM t1 WHERE user_id=1 AND friend_id IN
     (1,2,3,4,5,7,8,9,10);
  • 0.001s
•  No batching:
  • 10 x SELECT * FROM t1 WHERE user_id=1 AND
       friend_id={ id };
  • 0.006s
Batching

•  Another way – batching on different tables
SET transaction_allow_batching=1; /set on the
     connection
BEGIN;
INSERT INTO user(uid, fname, lname, email) VALUES
     ( … );
10 x INSERT INTO service(uid, sid, data ) VALUES
     ( … );
COMMIT;
•  The above will be executed in one batch (one roundtrip)
   •  transaction_allow_batching=0: 1223 TPS
   •  transaction_allow_batching=1: 2204 TPS ( 80% faster)
•  Batching using transaction_allow_batching
   does not work with
   •  UPDATE .. SET X=X+1 .. , JOINs, REPLACE
Efficient Scanning – Partition Pruning
•  Scanning only one partition is sometimes better than
   scanning all partitions (all nodes).
   –  By default, all index scans hit all data nodes – good if big
      result set.
   –  User-defined partitioning can help to improve equality index
      scans on part of a primary key.
   –  CREATE TABLE user_friends (user_id,
                              friend_id,
                              data,
                              PRIMARY KEY(user_id, friend_id))
                              PARTITION BY KEY(user_id);
     •  All data belonging to a particular user_id will be on the same
        partition.
   –  SELECT * FROM user_friends WHERE user_id=1;
     •  Only one data node will be scanned (no matter how many nodes
        you have)
Efficient Scanning – Partition Pruning
•  You can verify if you got it correct checking the
   Ndb_pruned_scan_count status variable
   •  Increases when a pruned scan occurs

mysql> select * from user_friend where user_id=1;


mysql> show global status like
  'ndb_pruned_scan_count';
+-----------------------+-------+
| Ndb_pruned_scan_count | 1     |
+-----------------------+-------+
1 row in set (0.00 sec)
Efficient Scanning – Partition Pruning

•  Partition Pruning is better up to a certain point
   –  Depends on number of data nodes and records retrieved




                 (shorter bars are better)
Query Optimization – JOINs
•  JOINs are executed in the MySQL server.
•  The OPTIMIZER in MYSQL only knows one
   algorithm
   –  Nested Loop Join
   –  This algorithm is not brilliant in its effectiveness
•  If we have the following query:
   –  SELECT fname, lname, title
      FROM a,b
      WHERE b.id=a.id AND a.country='France';




               •  uthor a
                A                                       •  uthorBook b
                                                         A
Query Optimization - JOINs

    •  SELECT fname, lname, title FROM a,b WHERE
       b.id=a.id AND a.country='France';


                                    2
1
                •  uthor a
                 A                                    •  uthorBook b
                                                       A

    •  1. Index scan left table to find matches.
    •  2. For each match in 'a', find matches in 'b'
      •  In this an index scan on the right table on b.id for each
         matching record in 'a’
      •  This could be very expensive if there are many records
         matching a.country='France'
Query Optimization - jOIN

•  The main performance limiter for JOINs are
   –  Number of tables in JOIN
   –  Number of Records matching the JOIN criteria
•  In general
   –  JOINs are limiting scalability even for INNODB/MYISAM
      •  It is a complex access pattern
   –  JOINs should be as simple as possible
      •  WHERE – conditions should be as limiting as possible
   •  Consider this:
      •  Every inspected record costs about 200us for a PK join
      •  A join hitting 2000 (2000 x 200 us) records → 0.4seconds
      •  A join hitting 2 000 000 records → 40 seconds
   –  Using SCI/DX can help a lot as JOINs are subject to network
       latency that is problematic.
Query Optimization - jOIN

•  Make sure the tables are joined in the correct order
  •  Check with EXPLAIN!
  •  Sometime the order is screwed up
  •  Make sure you have the necessary indexes
  •  Make sure tables are JOINed with the table having the best/
     most conditions comes first in the JOIN.
  •  Preferably take the smallest table first in the JOIN
  • STRAIGHT_JOIN can help a lot
Query Optimization - SUB-SELECT

•  Rewrite SUB-SELECTS as JOINs
  • SELECT x FROM t1 WHERE t1.id IN
    (SELECT t2.id FROM t2 WHERE t2.y>10
  Becomes
  • SELECT x FROM t1,t2 WHERE t1.id=t2.id AND
    t2.y>10;
Indexes

•  Don't trust the OPTIMIZER!
  •  Statistics gathering is very bad
  •  Optimizer thinks there are only 10 rows to examine in each
     table!
•  If you have two similar indexes on a table
  •  index(a)
  •  index(a,ts)
•  Use FORCE INDEX to use the correct index
  •  Don’t use USE INDEX!
•  Check with EXPLAIN!
Tuning Options
               •  e-normalization
                D
Schema
               •  ptimize data types
                O
Optimization
               •  atching
                B
Query Tuning   •  ewrite slow queries
                R
               • ndex Tuning
                I

Parameter      •  se a good Configuration (affects mostly stability)
                U
Tuning         •  ainly MySQL server parameters
                M


Network / OS   •  une Network (TCP) buffers (not the scope of this presentation)
                T
Tuning         •  luster Interconnects
                C


Hardware       •  aster CPU/Disk (not the scope of this presentation)
                F
Tuning
Parameter Tuning –
 ndb_cluster_connection_pool
•  Problem:
  •  A mutex on the connection from the mysqld to the data
     nodes prevents scalability.
  •  Many threads → contention on the mutex
  •  Must have many mysqld processes running...
•  Solution:
  •  Ndb_cluster_connection_pool (in my.cnf) creates
     more connections from one mysqld to the data nodes
     •  One free [mysqld] slot is required in config.ini for each
        connection.
     •  Threads load balance on the connections→ less
        contention on mutex → increased scalabilty
Parameter Tuning –
 Ndb_cluster_connection_pool




•  Gives at least 70% better performance
 •  >70% better perf
 • Ndb_cluster_connection_pool=2x<CPU
    cores> is a good starting point.
•  www.severalnines.com/config allows you to specify
   this
Parameter Tuning – auto_increments
•  A range of auto_increments are cached in the
   MySQL Server
  •  ServerA gets 1..1024 , serverB gets 1025-2048
  •  When out of values in range → go to data nodes, lock, fetch
     next range, unlock → serialization!
  •  ndb_autoincrement_prefetch_sz=1 (default - too
     small)
  •  Must fetch new ranges all the time from data nodes! Round-
     trip!
•  16 BATCHED INSERTS / 8 THREADS / 1 APP
   Default=1:      1211.91TPS
   256:            3471.71TPS
   1024 :          3659.52TPS
•  Increase ndb_auto_increment_prefetch_sz depending
   on INSERT load.
Parameter Tuning - Misc

•  Don't forget to set:
  •  thread_cache_size = <max_connections>
  •  table_open_cache=512
•  Use SHOW GLOBAL STATUS;
  •  If Threads_created increases -> increase thread_cache_size!
  •  If Opened_tables increases -> increase table_open_cache!
•  Please note that www.severalnines.com/config sets
   great default values! (the best in the industry actually)
Tuning Options
               •  e-normalization
                D
Schema
               •  ptimize data types
                O
Optimization
               •  atching
                B
Query Tuning   •  ewrite slow queries
                R
               • ndex Tuning
                I

Parameter      •  se a good Configuration (affects mostly stability)
                U
Tuning         •  ainly MySQL server parameters
                M

Network / OS   •  une Network (TCP) buffers
                T
                  (not the scope of this presentation)
Tuning
               •  luster Interconnects
                C


Hardware       •  aster CPU/Disk (not the scope of this presentation)
                F
Tuning
Network – Cluster Interconnects
•  Cluster Interconnects
  •  Instead of spending $$$ on application tuning/development
  •  Also great for DRBD!
•  DX (SCI) is a Cluster Interconnect offering:
  •  High Bandwidth ( 20 Gb/sec full duplex), Low latency (<2us)
  •  Offers a socket interface – any socket based application
     benefits from it
  •  10 Gig-E form factor on cabling
  •  Seamless fallback to Gig-E
  •  >2x more performance just plugging it in.
  •  DXH510 PCI Express Host Adapter (600USD list price Oct
     2008) DXS410 DX 10 Port Switch (4200USD list price Oct
     2008)
  •  Read more at http://www.dolphinics.com
Other things

•  Make sure you never:
  •  Run in SWAP – the data nodes will be sub-performing and
     you will have an unstable system.
•  Make sure you do:
  •  Lock data nodes threads to CPUs not handling interrupts for
     ETH.
  •  Vm.swappiness=0
  •  Mount with noatime
  •  On SUN CMT (T5240 etc) it is very important to create
     processor sets and bind interrupt handling to particular Core
     (HW Thread)
Tools

•  Third party tools at www.severalnines.com
  •  Configurator
      •  Uses best practices for setting up a good config.ini and
         my.cnf
      •  Scripts to control cluster from one single location.
  •  CMON – Cluster Monitor
      •  Monitor X number of Clusters (and mysqld statistics) from
         a single web interface
  •  Sizer – Capacity Planning
  •  Sandbox – Development package (localhost) for Cluster
Questions?

THANK YOU!

Johan.Andersson@sun.com
www.severalnines.com
johanandersson.blogspot.com

Mais conteúdo relacionado

Mais procurados

Get More Out of MySQL with TokuDB
Get More Out of MySQL with TokuDBGet More Out of MySQL with TokuDB
Get More Out of MySQL with TokuDBTim Callaghan
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
Think Exa!
Think Exa!Think Exa!
Think Exa!Enkitec
 
Oracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerOracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerChristian Antognini
 
2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation2008 Collaborate IOUG Presentation
2008 Collaborate IOUG PresentationBiju Thomas
 
Indexing in Exadata
Indexing in ExadataIndexing in Exadata
Indexing in ExadataEnkitec
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsfMao Geng
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracleTrainings
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuningSimon Huang
 
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo... Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...Enkitec
 
2009 Collaborate IOUG Presentation
2009 Collaborate IOUG Presentation2009 Collaborate IOUG Presentation
2009 Collaborate IOUG PresentationBiju Thomas
 
2013 Collaborate - OAUG - Presentation
2013 Collaborate - OAUG - Presentation2013 Collaborate - OAUG - Presentation
2013 Collaborate - OAUG - PresentationBiju Thomas
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPGConf APAC
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
 
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataProblems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataJignesh Shah
 
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库YUCHENG HU
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraSveta Smirnova
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsEnkitec
 

Mais procurados (20)

Get More Out of MySQL with TokuDB
Get More Out of MySQL with TokuDBGet More Out of MySQL with TokuDB
Get More Out of MySQL with TokuDB
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
Think Exa!
Think Exa!Think Exa!
Think Exa!
 
Oracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerOracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query Optimizer
 
2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation
 
Indexing in Exadata
Indexing in ExadataIndexing in Exadata
Indexing in Exadata
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo... Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 
2009 Collaborate IOUG Presentation
2009 Collaborate IOUG Presentation2009 Collaborate IOUG Presentation
2009 Collaborate IOUG Presentation
 
2013 Collaborate - OAUG - Presentation
2013 Collaborate - OAUG - Presentation2013 Collaborate - OAUG - Presentation
2013 Collaborate - OAUG - Presentation
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability Improvements
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
 
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataProblems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
 
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
 
06 External Memory
06  External  Memory06  External  Memory
06 External Memory
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 

Destaque

MySQL Community and Commercial Edition
MySQL Community and Commercial EditionMySQL Community and Commercial Edition
MySQL Community and Commercial EditionMario Beck
 
How to think like a startup
How to think like a startupHow to think like a startup
How to think like a startupLoic Le Meur
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakShelly Sanchez Terrell
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Destaque (6)

MySQL Community and Commercial Edition
MySQL Community and Commercial EditionMySQL Community and Commercial Edition
MySQL Community and Commercial Edition
 
Inaugural Addresses
Inaugural AddressesInaugural Addresses
Inaugural Addresses
 
How to think like a startup
How to think like a startupHow to think like a startup
How to think like a startup
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Semelhante a 30334823 my sql-cluster-performance-tuning-best-practices

Real World Performance - Data Warehouses
Real World Performance - Data WarehousesReal World Performance - Data Warehouses
Real World Performance - Data WarehousesConnor McDonald
 
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAmazon Web Services
 
Deep Dive into DynamoDB
Deep Dive into DynamoDBDeep Dive into DynamoDB
Deep Dive into DynamoDBAWS Germany
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentationMichael Keane
 
Best Practices for Migrating Your Data Warehouse to Amazon Redshift
Best Practices for Migrating Your Data Warehouse to Amazon RedshiftBest Practices for Migrating Your Data Warehouse to Amazon Redshift
Best Practices for Migrating Your Data Warehouse to Amazon RedshiftAmazon Web Services
 
Intro to Cassandra
Intro to CassandraIntro to Cassandra
Intro to CassandraJon Haddad
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...Amazon Web Services
 
Pre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctlyPre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctlyAntonios Chatzipavlis
 
Best Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon RedshiftBest Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon RedshiftSnapLogic
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesAlfredo Abate
 
PostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FuturePostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FutureAaron Thul
 
Dynamics ax performance tuning
Dynamics ax performance tuningDynamics ax performance tuning
Dynamics ax performance tuningOutsourceAX
 
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesMySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesSeveralnines
 
Design Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System ArchitectureDesign Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System ArchitectureInductive Automation
 

Semelhante a 30334823 my sql-cluster-performance-tuning-best-practices (20)

Cassandra training
Cassandra trainingCassandra training
Cassandra training
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
Real World Performance - Data Warehouses
Real World Performance - Data WarehousesReal World Performance - Data Warehouses
Real World Performance - Data Warehouses
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
 
Deep Dive into DynamoDB
Deep Dive into DynamoDBDeep Dive into DynamoDB
Deep Dive into DynamoDB
 
Breaking data
Breaking dataBreaking data
Breaking data
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
Best Practices for Migrating Your Data Warehouse to Amazon Redshift
Best Practices for Migrating Your Data Warehouse to Amazon RedshiftBest Practices for Migrating Your Data Warehouse to Amazon Redshift
Best Practices for Migrating Your Data Warehouse to Amazon Redshift
 
Intro to Cassandra
Intro to CassandraIntro to Cassandra
Intro to Cassandra
 
Redshift overview
Redshift overviewRedshift overview
Redshift overview
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
AWS re:Invent 2016| DAT318 | Migrating from RDBMS to NoSQL: How Sony Moved fr...
 
Pre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctlyPre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctly
 
Best Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon RedshiftBest Practices for Supercharging Cloud Analytics on Amazon Redshift
Best Practices for Supercharging Cloud Analytics on Amazon Redshift
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
 
PostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FuturePostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The Future
 
Dynamics ax performance tuning
Dynamics ax performance tuningDynamics ax performance tuning
Dynamics ax performance tuning
 
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesMySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
 
Design Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System ArchitectureDesign Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System Architecture
 

Último

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
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
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Último (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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
 
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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

30334823 my sql-cluster-performance-tuning-best-practices

  • 1. <Insert Picture Here> MySQL Cluster – Performance Tuning Johan Andersson Principal Field Technologist
  • 2. The presentation is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 3. General Design Principles •  MySQL Cluster is designed for •  Short transactions •  Many parallel transactions •  Utilize Simple access patterns to fetch data •  Solution that scales! •  Analyze what your most typical use cases are •  optimize for those Overall design goal Minimize network roundtrips for your most important requests!
  • 4. General Design Principles •  Application spaces where Cluster is being used heavily •  Subscriber databases (telecom) •  Session management •  Online gaming •  Finance •  E-commerce •  As a Shard catalog in web 2.0 shops •  The key denominator for all these applications are: •  high throughput, low response times, high-availability, and simple access patterns. •  Reporting is typically performed on a subsystem •  Replicate to a slave (e.g, MYISAM or INNODB database)
  • 5. Tuning Options •  e-normalization D Schema •  ptimize data types O Optimization •  atching B Query Tuning •  ewrite slow queries R • ndex Tuning I Parameter •  se a good Configuration (affects mostly stability) U Tuning •  ainly MySQL server parameters M Network / OS •  une Network (TCP) buffers (not the scope of this presentation) T Tuning •  luster Interconnects C Hardware •  aster CPU/Disk (not the scope of this presentation) F Tuning
  • 6. Detecting Problems – PT 101 •  Enable the slow query log! •  set global slow_query_log=1; •  set global long_query_time=3; //3 seconds •  set global log_queries_not_using_indexes=1; •  Slow queries will be written in the slow query log: mysql> show global variables like 'slow_query_log_file'; +---------------------+------------------------------+ | Variable_name | Value | +---------------------+------------------------------+ | slow_query_log_file | /data1/mysql/mysqld-slow.log | +---------------------+------------------------------+ 1 row in set (0.00 sec) •  Slow Queries will be written in plain text. •  Or use MEM (but MEM cannot monitor data nodes)
  • 7. Detecting Problems – PT 101 BEGIN 1.  Start by analyzing the slow query log Change long_query_time if needed 2.  Use EXPLAIN to figure out if the query is • Using the correct indexes • JOINing the tables in the wrong order • so bad it needs to be rewritten. 3.  Re-run the optimized typical use cases using mysqlslap 4.  GOTO BEGIN; END; •  Other tools such as mysqlsla can also be used •  Performance tuning is a never-ending task. •  Never tune unless you can measure and test •  Don't optimize unless you have a problem
  • 8. Tuning Options •  e-normalization D Schema •  ptimize data types O Optimization •  atching B Query Tuning •  ewrite slow queries R • ndex Tuning I Parameter •  se a good Configuration (affects mostly stability) U Tuning •  ainly MySQL server parameters M Network / OS •  une Network (TCP) buffers (not the scope of this presentation) T Tuning •  luster Interconnects C Hardware •  aster CPU/Disk (not the scope of this presentation) F Tuning
  • 9. Schema Optimization - Data Types •  Denormalize tables •  Tables having the same PRIMARY KEY can be denormalized •  Change Data Types •  Does an EMAIL need to be a TEXT?
  • 10. Schema Optimization - Denormalization •  Two tables with the same PRIMARY KEY can be denormalized into a single table: •  SER_SVC_VOIP U •  SER_SVC_BROADBAND U •  Requires two roundtrips to get data •  Denormalize: •  SER_SVC_VOIP_ BB U
  • 11. Schema Optimization - Denormalization •  Normalized: •  SELECT * FROM USER_SVC_BROADBAND AS bb, USER_SVC_VOIP AS voip WHERE bb.id=voip.id AND bb.id=1; •  Total throughput = 12623.09 tps •  Average response time=658us •  Denormalized: •  SELECT * FROM USER_SVC_VOIP_BB AS bb_voip WHERE bb_voip=1; •  Total throughput = 21591.64 tps •  Average response time=371us
  • 12. Schema Optimization – Data Types •  BLOB/TEXT columns are stored in an external hidden table. •  First 255B are stored inline in main table •  Reading a BLOB/TEXT requires two reads •  Read without lock will be upgraded to shared lock! •  Reading/Writing a VARCHAR/VARBINARY is less expensive. •  Change to VARBINARY/VARCHAR if: •  Your BLOBs/TEXTs can fit within an 8052B record (and you need a 4B PK as well) •  (record size is currently 8052 Bytes)
  • 13. Schema Optimization – Data Types •  SELECT data1, data2 FROM t1 WHERE id=<rand> •  sizeof(data1) = 1024B, sizeof(data2) = 1024B. •  1 App - 8 Threads , 1 MySQLD, 2 Data nodes •  data1 and data2 represented as BLOBs •  5844 TPS •  data1 and data2 represented as VARBINARYs •  19206 TPS •  Note 1: BLOB/TEXT are also more expensive in Innodb as BLOB/ TEXT data is not inlined with the table. Thus, two disk seeks are needed to read a BLOB. •  Note 2: We recommend (for any storage engine) to store images, movies etc outside the database on the filesystem.
  • 14. Schema Optimzation - PK selection •  Engineer your schema for the problem you need to solve! •  Call setup? Locate all friends of a user? •  Very common… UNIQUE KEY PK ID (auto_inc) USER_ID FRIEND_ID 1 10001 11000 2 10001 11001 3 10001 11002 4 10002 12022 •  Better: •  Introduce PK <USER_ID, FRIEND_ID> •  Get rid of column ID •  Get rid of the UNIQUE (as it is now the PK)
  • 15. Tuning Options •  e-normalization D Schema •  ptimize data types O Optimization •  atching B Query Tuning •  ewrite slow queries R • ndex Tuning I Parameter •  se a good Configuration (affects mostly stability) U Tuning •  ainly MySQL server parameters M Network / OS •  une Network (TCP) buffers (not the scope of this presentation) T Tuning •  luster Interconnects C Hardware •  aster CPU/Disk (not the scope of this presentation) F Tuning
  • 16. Simple Access Patterns •  Simple Access Patterns are key to build scalable and high performing solutions (this is not subject to Cluster only) •  PRIMARY KEY lookups are done in constant time O(1 •  Fastest way to access data in MySQL Cluster •  INDEX searches are done in O(log n) time. •  JOINs are ok if you understand what can make them slow. •  If your most important requests are 10-way JOINs with huge result sets then Cluster may not be for you. •  Or use scale out (write to cluster read from innodb): http:// johanandersson.blogspot.com/2009/05/ha-mysql-write-scaling- using-cluster-to.html
  • 17. Operation Cost •  Cost of typical operations (depends on HW/Network) •  Synchronous replication adds ~2.1x - 2.8x for writes compared to reads •  Index scan takes 2.4x longer than PK read •  Test was with 8 threads connecting to one mysqld •  'bencher' was used to generate the load. (Xeon 5160 @ 3.00GHz)
  • 18. Batching •  MySQL Cluster allows batching on •  INSERT (PK) •  Most PK UPDATE •  DELETE (PK) •  SELECT (PK and some INDEX scans and not in JOINs) •  Batching means •  One transaction with >1 operation are executed in one round- trip
  • 19. Batching •  Example – Insert 1M records •  No batching: • INSERT INTO t1(data) VALUES (<data>); •  Batching (batches of 16): • INSERT INTO t1(<columns>) VALUES (<data0>), (<data1>)..., (<data15>) •  50 seconds to insert 1M records •  15 times faster!
  • 20. Batching •  Read 10 records services for a user: •  PK is <userid, friend_id> •  Batching (batches of 10): •  SELECT * FROM t1 WHERE user_id=1 AND friend_id IN (1,2,3,4,5,7,8,9,10); • 0.001s •  No batching: • 10 x SELECT * FROM t1 WHERE user_id=1 AND friend_id={ id }; • 0.006s
  • 21. Batching •  Another way – batching on different tables SET transaction_allow_batching=1; /set on the connection BEGIN; INSERT INTO user(uid, fname, lname, email) VALUES ( … ); 10 x INSERT INTO service(uid, sid, data ) VALUES ( … ); COMMIT; •  The above will be executed in one batch (one roundtrip) •  transaction_allow_batching=0: 1223 TPS •  transaction_allow_batching=1: 2204 TPS ( 80% faster) •  Batching using transaction_allow_batching does not work with •  UPDATE .. SET X=X+1 .. , JOINs, REPLACE
  • 22. Efficient Scanning – Partition Pruning •  Scanning only one partition is sometimes better than scanning all partitions (all nodes). –  By default, all index scans hit all data nodes – good if big result set. –  User-defined partitioning can help to improve equality index scans on part of a primary key. –  CREATE TABLE user_friends (user_id, friend_id, data, PRIMARY KEY(user_id, friend_id)) PARTITION BY KEY(user_id); •  All data belonging to a particular user_id will be on the same partition. –  SELECT * FROM user_friends WHERE user_id=1; •  Only one data node will be scanned (no matter how many nodes you have)
  • 23. Efficient Scanning – Partition Pruning •  You can verify if you got it correct checking the Ndb_pruned_scan_count status variable •  Increases when a pruned scan occurs mysql> select * from user_friend where user_id=1; mysql> show global status like 'ndb_pruned_scan_count'; +-----------------------+-------+ | Ndb_pruned_scan_count | 1 | +-----------------------+-------+ 1 row in set (0.00 sec)
  • 24. Efficient Scanning – Partition Pruning •  Partition Pruning is better up to a certain point –  Depends on number of data nodes and records retrieved (shorter bars are better)
  • 25. Query Optimization – JOINs •  JOINs are executed in the MySQL server. •  The OPTIMIZER in MYSQL only knows one algorithm –  Nested Loop Join –  This algorithm is not brilliant in its effectiveness •  If we have the following query: –  SELECT fname, lname, title FROM a,b WHERE b.id=a.id AND a.country='France'; •  uthor a A •  uthorBook b A
  • 26. Query Optimization - JOINs •  SELECT fname, lname, title FROM a,b WHERE b.id=a.id AND a.country='France'; 2 1 •  uthor a A •  uthorBook b A •  1. Index scan left table to find matches. •  2. For each match in 'a', find matches in 'b' •  In this an index scan on the right table on b.id for each matching record in 'a’ •  This could be very expensive if there are many records matching a.country='France'
  • 27. Query Optimization - jOIN •  The main performance limiter for JOINs are –  Number of tables in JOIN –  Number of Records matching the JOIN criteria •  In general –  JOINs are limiting scalability even for INNODB/MYISAM •  It is a complex access pattern –  JOINs should be as simple as possible •  WHERE – conditions should be as limiting as possible •  Consider this: •  Every inspected record costs about 200us for a PK join •  A join hitting 2000 (2000 x 200 us) records → 0.4seconds •  A join hitting 2 000 000 records → 40 seconds –  Using SCI/DX can help a lot as JOINs are subject to network latency that is problematic.
  • 28. Query Optimization - jOIN •  Make sure the tables are joined in the correct order •  Check with EXPLAIN! •  Sometime the order is screwed up •  Make sure you have the necessary indexes •  Make sure tables are JOINed with the table having the best/ most conditions comes first in the JOIN. •  Preferably take the smallest table first in the JOIN • STRAIGHT_JOIN can help a lot
  • 29. Query Optimization - SUB-SELECT •  Rewrite SUB-SELECTS as JOINs • SELECT x FROM t1 WHERE t1.id IN (SELECT t2.id FROM t2 WHERE t2.y>10 Becomes • SELECT x FROM t1,t2 WHERE t1.id=t2.id AND t2.y>10;
  • 30. Indexes •  Don't trust the OPTIMIZER! •  Statistics gathering is very bad •  Optimizer thinks there are only 10 rows to examine in each table! •  If you have two similar indexes on a table •  index(a) •  index(a,ts) •  Use FORCE INDEX to use the correct index •  Don’t use USE INDEX! •  Check with EXPLAIN!
  • 31. Tuning Options •  e-normalization D Schema •  ptimize data types O Optimization •  atching B Query Tuning •  ewrite slow queries R • ndex Tuning I Parameter •  se a good Configuration (affects mostly stability) U Tuning •  ainly MySQL server parameters M Network / OS •  une Network (TCP) buffers (not the scope of this presentation) T Tuning •  luster Interconnects C Hardware •  aster CPU/Disk (not the scope of this presentation) F Tuning
  • 32. Parameter Tuning – ndb_cluster_connection_pool •  Problem: •  A mutex on the connection from the mysqld to the data nodes prevents scalability. •  Many threads → contention on the mutex •  Must have many mysqld processes running... •  Solution: •  Ndb_cluster_connection_pool (in my.cnf) creates more connections from one mysqld to the data nodes •  One free [mysqld] slot is required in config.ini for each connection. •  Threads load balance on the connections→ less contention on mutex → increased scalabilty
  • 33. Parameter Tuning – Ndb_cluster_connection_pool •  Gives at least 70% better performance •  >70% better perf • Ndb_cluster_connection_pool=2x<CPU cores> is a good starting point. •  www.severalnines.com/config allows you to specify this
  • 34. Parameter Tuning – auto_increments •  A range of auto_increments are cached in the MySQL Server •  ServerA gets 1..1024 , serverB gets 1025-2048 •  When out of values in range → go to data nodes, lock, fetch next range, unlock → serialization! •  ndb_autoincrement_prefetch_sz=1 (default - too small) •  Must fetch new ranges all the time from data nodes! Round- trip! •  16 BATCHED INSERTS / 8 THREADS / 1 APP Default=1: 1211.91TPS 256: 3471.71TPS 1024 : 3659.52TPS •  Increase ndb_auto_increment_prefetch_sz depending on INSERT load.
  • 35. Parameter Tuning - Misc •  Don't forget to set: •  thread_cache_size = <max_connections> •  table_open_cache=512 •  Use SHOW GLOBAL STATUS; •  If Threads_created increases -> increase thread_cache_size! •  If Opened_tables increases -> increase table_open_cache! •  Please note that www.severalnines.com/config sets great default values! (the best in the industry actually)
  • 36. Tuning Options •  e-normalization D Schema •  ptimize data types O Optimization •  atching B Query Tuning •  ewrite slow queries R • ndex Tuning I Parameter •  se a good Configuration (affects mostly stability) U Tuning •  ainly MySQL server parameters M Network / OS •  une Network (TCP) buffers T (not the scope of this presentation) Tuning •  luster Interconnects C Hardware •  aster CPU/Disk (not the scope of this presentation) F Tuning
  • 37. Network – Cluster Interconnects •  Cluster Interconnects •  Instead of spending $$$ on application tuning/development •  Also great for DRBD! •  DX (SCI) is a Cluster Interconnect offering: •  High Bandwidth ( 20 Gb/sec full duplex), Low latency (<2us) •  Offers a socket interface – any socket based application benefits from it •  10 Gig-E form factor on cabling •  Seamless fallback to Gig-E •  >2x more performance just plugging it in. •  DXH510 PCI Express Host Adapter (600USD list price Oct 2008) DXS410 DX 10 Port Switch (4200USD list price Oct 2008) •  Read more at http://www.dolphinics.com
  • 38. Other things •  Make sure you never: •  Run in SWAP – the data nodes will be sub-performing and you will have an unstable system. •  Make sure you do: •  Lock data nodes threads to CPUs not handling interrupts for ETH. •  Vm.swappiness=0 •  Mount with noatime •  On SUN CMT (T5240 etc) it is very important to create processor sets and bind interrupt handling to particular Core (HW Thread)
  • 39. Tools •  Third party tools at www.severalnines.com •  Configurator •  Uses best practices for setting up a good config.ini and my.cnf •  Scripts to control cluster from one single location. •  CMON – Cluster Monitor •  Monitor X number of Clusters (and mysqld statistics) from a single web interface •  Sizer – Capacity Planning •  Sandbox – Development package (localhost) for Cluster