SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Using flash on the server side
Using flash on the server sideUsing flash on the server side
Using flash on the server side
Howard Marks
 
Application Development with Apache Cassandra as a Service
Application Development with Apache Cassandra as a ServiceApplication Development with Apache Cassandra as a Service
Application Development with Apache Cassandra as a Service
WSO2
 
iMobileMagic Teck Talk Scale Up
iMobileMagic Teck Talk Scale UpiMobileMagic Teck Talk Scale Up
iMobileMagic Teck Talk Scale Up
Pedro Machado
 
Geek Sync | Successfully Migrating Existing Databases to Azure SQL Database
Geek Sync | Successfully Migrating Existing Databases to Azure SQL DatabaseGeek Sync | Successfully Migrating Existing Databases to Azure SQL Database
Geek Sync | Successfully Migrating Existing Databases to Azure SQL Database
IDERA Software
 

Tendances (20)

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

Similaire à Optimize MySQL performance for developers

Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
Liran Zelkha
 
NoSQLDatabases
NoSQLDatabasesNoSQLDatabases
NoSQLDatabases
Adi Challa
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
Don Demcsak
 
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
Qian Lin
 
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Manik Surtani
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
Don Demcsak
 
Building a highly scalable and available cloud application
Building a highly scalable and available cloud applicationBuilding a highly scalable and available cloud application
Building a highly scalable and available cloud application
Noam Sheffer
 

Similaire à Optimize MySQL performance for developers (20)

Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
 
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
 
Sql vs nosql
Sql vs nosqlSql vs nosql
Sql vs nosql
 
NoSQLDatabases
NoSQLDatabasesNoSQLDatabases
NoSQLDatabases
 
Evolution of Distributed Database Technologies in the Digital era
Evolution of Distributed Database Technologies in the Digital eraEvolution of Distributed Database Technologies in the Digital era
Evolution of Distributed Database Technologies in the Digital era
 
Introduction to no sql database
Introduction to no sql databaseIntroduction to no sql database
Introduction to no sql database
 
Webinar: Migrating from RDBMS to MongoDB
Webinar: Migrating from RDBMS to MongoDBWebinar: Migrating from RDBMS to MongoDB
Webinar: Migrating from RDBMS to MongoDB
 
Navigating NoSQL in cloudy skies
Navigating NoSQL in cloudy skiesNavigating NoSQL in cloudy skies
Navigating NoSQL in cloudy skies
 
Cassandra training
Cassandra trainingCassandra training
Cassandra training
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
 
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
 
Einführung in RavenDB
Einführung in RavenDBEinführung in RavenDB
Einführung in RavenDB
 
Building a highly scalable and available cloud application
Building a highly scalable and available cloud applicationBuilding a highly scalable and available cloud application
Building a highly scalable and available cloud application
 
How to use Big Data and Data Lake concept in business using Hadoop and Spark...
 How to use Big Data and Data Lake concept in business using Hadoop and Spark... How to use Big Data and Data Lake concept in business using Hadoop and Spark...
How to use Big Data and Data Lake concept in business using Hadoop and Spark...
 
The No SQL Principles and Basic Application Of Casandra Model
The No SQL Principles and Basic Application Of Casandra ModelThe No SQL Principles and Basic Application Of Casandra Model
The No SQL Principles and Basic Application Of Casandra Model
 
NoSQL.pptx
NoSQL.pptxNoSQL.pptx
NoSQL.pptx
 
No SQL
No SQLNo SQL
No SQL
 
Introduction to SharePoint for SQLserver DBAs
Introduction to SharePoint for SQLserver DBAsIntroduction to SharePoint for SQLserver DBAs
Introduction to SharePoint for SQLserver DBAs
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

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