SlideShare a Scribd company logo
Optimize MySQL For Developers


                YangHaichao
        Senior MySQL DBA@SINA
        http://weibo.com/jackbillow


         QCon Beijing 2011
Agenda

• Architecture of Database-related
• Scaling your Database
• Schema Design
• Optimize Access
Performance vs Architecture
Datastore

• Relational Databases
  • MySQL
• Non Relational Databases
  • Memcached
  • Redis
  • MongoDB
• RD and NRD is Friends or Foes?
  • MySQL + Memcached
  • MySQL + Redis
Caching

• Put a cache in front of your database
  •   Distribute
  •   Write-through for scaling reads
  •   Write-back for scaling reads and writes
• Cache tier
Principles

• Nothing’s perfect but some solutions are
  good enough for a while
• Scalability involve partitioning, indexing and
  replication
• All data for real-time queries MUST be in
  memory. Disk is for writes only
Scaling your database
Replication

• Master - Slave
  • Only scaling reads
• Master - Master
  • Scaling reads and writes but many limits
Functional Segmentation

Segment databases into functional areas
• User
• Feed
• Comment
• Attention
• Fans
• …
Horizontal Split

• Hash
• Range
• Lookup table
• Middle layer
Minimize Database

• No business logic
• No distributed transactions
• No joins and sorting
Schema Design
CAP & BASE


Consistency:    Oracle      Availability
   ACID          RAC          (Total
Transactions               Redundancy)
                  NO
                  GO
                         NoSQL
                          DB


                Partition
              Tolerance:
           Infinite scaleout
The Schema

• Best stage for optimize performance
• Improve performance is bigest
• Divide and conquer
• Normalize & de-normalize
Data type

• Small is usually better
• Use INT UNSIGNED for IPv4 addresses
• Use TEXT or BLOB sparingly
  • Consider separate tables
Index

• Over indexing can be an overhead
• On multiple column indexes the order fields
  within the index definition is important
• Poor indexes are same as not having any
  indexes
• Good selectivity on index fields
Storage Engine

• Understanding benefits and drawbacks of
  each storage engine
• Different storage engine has different index
  capability
Optimization Access
Thinking in Access

• Any interaction with the database are the
  high cost
• Decrease data access is better than SQL
  tuning
SQL is not C or C++
Reduce Access to data

• Must specity column in select
• Only use index in query
• Assumsing success
Reduce the Number of Interactions

• Pushing control structures into SQL
• Combining statements
• Fetching all you need at once
Reduce the Number of Interactions

• INSERT ... ON DUPLICATE KEY UPDATE
• REPLACE
• INSERT IGNORE
Reduce CPU computing

• Extensive use of prepared statements and
  bind variables
• Column not calculate as far as possible
• Move cpu-intensive work to application
Parallelism

• Reorganizing processing
• Isolating hot spots
• Shortening critical sections
• Dealing with multiple queues
Last, but not least…

• Architecture and design is in the best stages
  of improving performance
• Develop huge application you mush keep
  scaling data in mind at first
• Perform SQL in very few data accesses is
  increasingly important
• Performance tuning is an trade-off and
  iterative process
Thank you for coming


       Q&A


     @jackbillow

More Related Content

PPTX
NoSQL - Not Only SQL
PDF
Supercharge your RDBMS with Elasticsearch
PDF
Nosql primer
PPTX
FatDB Intro
PDF
Oracle Week 2016 - Modern Data Architecture
PPTX
In Memory Cahce Structure
PPT
Choosing the Right Big Data Tools for the Job - A Polyglot Approach
PDF
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...
NoSQL - Not Only SQL
Supercharge your RDBMS with Elasticsearch
Nosql primer
FatDB Intro
Oracle Week 2016 - Modern Data Architecture
In Memory Cahce Structure
Choosing the Right Big Data Tools for the Job - A Polyglot Approach
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...

What's hot (20)

PPTX
UNC Chapel Hill Ctc Retreat 2014 SAS Visual Analytics and Business Intelligence
PPTX
Using flash on the server side
PPTX
SPA vs. MPA
PDF
Application Development with Apache Cassandra as a Service
PPT
SQL Server Database as a Cloud Service
PDF
DBaaS with EDB Postgres on AWS
 
PPTX
iMobileMagic Teck Talk Scale Up
KEY
North Bay Ruby Meetup 101911
PPTX
AWS Database Services
PPTX
Cosmosdb graph
PPT
Student projects with open source CSQL
PPTX
SQL 2014 In-Memory OLTP
PPTX
Meta cloud architecture for the mobile agile enterprise
PPTX
SQL Azure for ISUG(SQL Server Israeli User Group)
PDF
Running MySQL in AWS
PDF
MongoDB and DynamoDB
PDF
Java scalability considerations yogesh deshpande
PDF
Maximizing performance via tuning and optimization
PPT
Schema Design
PDF
Geek Sync | Successfully Migrating Existing Databases to Azure SQL Database
UNC Chapel Hill Ctc Retreat 2014 SAS Visual Analytics and Business Intelligence
Using flash on the server side
SPA vs. MPA
Application Development with Apache Cassandra as a Service
SQL Server Database as a Cloud Service
DBaaS with EDB Postgres on AWS
 
iMobileMagic Teck Talk Scale Up
North Bay Ruby Meetup 101911
AWS Database Services
Cosmosdb graph
Student projects with open source CSQL
SQL 2014 In-Memory OLTP
Meta cloud architecture for the mobile agile enterprise
SQL Azure for ISUG(SQL Server Israeli User Group)
Running MySQL in AWS
MongoDB and DynamoDB
Java scalability considerations yogesh deshpande
Maximizing performance via tuning and optimization
Schema Design
Geek Sync | Successfully Migrating Existing Databases to Azure SQL Database
Ad

Similar to Optimize MySQL performance for developers (20)

PPTX
Handling Massive Writes
PPTX
No SQL DATABASE Description about 4 no sql database.pptx
PPTX
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
PPTX
Sql vs nosql
PPTX
NoSQLDatabases
PDF
Evolution of Distributed Database Technologies in the Digital era
PPTX
Introduction to no sql database
PPTX
Webinar: Migrating from RDBMS to MongoDB
PPTX
Navigating NoSQL in cloudy skies
PPTX
Introduction to Data Science NoSQL.pptx
PPTX
Cassandra training
PPTX
Intro to Big Data and NoSQL
PPTX
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
KEY
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
PPTX
Big Data (NJ SQL Server User Group)
PPTX
Einführung in RavenDB
PPTX
Building a highly scalable and available cloud application
PPSX
How to use Big Data and Data Lake concept in business using Hadoop and Spark...
PPTX
cours database pour etudiant NoSQL (1).pptx
PPT
The No SQL Principles and Basic Application Of Casandra Model
Handling Massive Writes
No SQL DATABASE Description about 4 no sql database.pptx
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Sql vs nosql
NoSQLDatabases
Evolution of Distributed Database Technologies in the Digital era
Introduction to no sql database
Webinar: Migrating from RDBMS to MongoDB
Navigating NoSQL in cloudy skies
Introduction to Data Science NoSQL.pptx
Cassandra training
Intro to Big Data and NoSQL
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Big Data (NJ SQL Server User Group)
Einführung in RavenDB
Building a highly scalable and available cloud application
How to use Big Data and Data Lake concept in business using Hadoop and Spark...
cours database pour etudiant NoSQL (1).pptx
The No SQL Principles and Basic Application Of Casandra Model
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Per capita expenditure prediction using model stacking based on satellite ima...

Optimize MySQL performance for developers

  • 1. Optimize MySQL For Developers YangHaichao Senior MySQL DBA@SINA http://weibo.com/jackbillow QCon Beijing 2011
  • 2. Agenda • Architecture of Database-related • Scaling your Database • Schema Design • Optimize Access
  • 4. Datastore • Relational Databases • MySQL • Non Relational Databases • Memcached • Redis • MongoDB • RD and NRD is Friends or Foes? • MySQL + Memcached • MySQL + Redis
  • 5. Caching • Put a cache in front of your database • Distribute • Write-through for scaling reads • Write-back for scaling reads and writes • Cache tier
  • 6. Principles • Nothing’s perfect but some solutions are good enough for a while • Scalability involve partitioning, indexing and replication • All data for real-time queries MUST be in memory. Disk is for writes only
  • 8. Replication • Master - Slave • Only scaling reads • Master - Master • Scaling reads and writes but many limits
  • 9. Functional Segmentation Segment databases into functional areas • User • Feed • Comment • Attention • Fans • …
  • 10. Horizontal Split • Hash • Range • Lookup table • Middle layer
  • 11. Minimize Database • No business logic • No distributed transactions • No joins and sorting
  • 13. CAP & BASE Consistency: Oracle Availability ACID RAC (Total Transactions Redundancy) NO GO NoSQL DB Partition Tolerance: Infinite scaleout
  • 14. The Schema • Best stage for optimize performance • Improve performance is bigest • Divide and conquer • Normalize & de-normalize
  • 15. Data type • Small is usually better • Use INT UNSIGNED for IPv4 addresses • Use TEXT or BLOB sparingly • Consider separate tables
  • 16. Index • Over indexing can be an overhead • On multiple column indexes the order fields within the index definition is important • Poor indexes are same as not having any indexes • Good selectivity on index fields
  • 17. Storage Engine • Understanding benefits and drawbacks of each storage engine • Different storage engine has different index capability
  • 19. Thinking in Access • Any interaction with the database are the high cost • Decrease data access is better than SQL tuning
  • 20. SQL is not C or C++
  • 21. Reduce Access to data • Must specity column in select • Only use index in query • Assumsing success
  • 22. Reduce the Number of Interactions • Pushing control structures into SQL • Combining statements • Fetching all you need at once
  • 23. Reduce the Number of Interactions • INSERT ... ON DUPLICATE KEY UPDATE • REPLACE • INSERT IGNORE
  • 24. Reduce CPU computing • Extensive use of prepared statements and bind variables • Column not calculate as far as possible • Move cpu-intensive work to application
  • 25. Parallelism • Reorganizing processing • Isolating hot spots • Shortening critical sections • Dealing with multiple queues
  • 26. Last, but not least… • Architecture and design is in the best stages of improving performance • Develop huge application you mush keep scaling data in mind at first • Perform SQL in very few data accesses is increasingly important • Performance tuning is an trade-off and iterative process
  • 27. Thank you for coming Q&A @jackbillow