SlideShare a Scribd company logo

Mysql Optimization

Apresentação sobre Otimização de Banco de dados Mysql

1 of 66
Download to read offline
MySQL Optimization
    MySQL User Conference

        Jeremy Zawodny
            Yahoo!

        April 12th, 2003
      San Jose, California

http://jeremy.zawodny.com/mysql/
          Copyright 2003, Jeremy Zawodny
About Me
•   Engineer in Y! Search (prev. Y! Finance)
•   MySQL user for over 5 years
•   Active in MySQL community
•   Write about LAMP for Linux Magazine
•   MySQL advocacy & support at Yahoo!

Home: Jeremy@Zawodny.com
Work: jzawodn@yahoo-inc.com
http://jeremy.zawodny.com/mysql/


                  Copyright 2003, Jeremy Zawodny
Outline
•   Introduction
•   Why Optimize?
•   Goals
•   Database Design
•   Application Design
•   Writing Fast Queries
•   MySQL Server Tuning
•   Operating System Tuning
•   Hardware Tuning
•   Network & Replication
•   Where to Learn More
•   Questions and Answers
                   Copyright 2003, Jeremy Zawodny
Starting Questions
•   What version of MySQL are you using?
•   What languages are being used?
•   Which operating systems?
•   Familiarity with other RDBMS servers?
•   Role? DBA? Developer? SysAdmin?
•   MySQL dedicated or shared servers?
•   How fast is your growth?
    – Transaction rates
    – Data volume

                    Copyright 2003, Jeremy Zawodny
What you Need to Know
• You should ask questions at any time
  – There should be sufficient time
• MySQL usage
  – Basic queries (SELECT, UPDATE, INSERT)
  – Installation or where files are located
• Basic programming concepts
  – Any language will do
• Operating system basics
  – Memory usage, swapping, etc.

                  Copyright 2003, Jeremy Zawodny
MySQL at Yahoo!
•   Roughly 200-400 servers world-wide
•   FreeBSD and Linux
•   Commodity hardware
•   Replaces home-grown “database” systems
•   Replaces Oracle in a few cases
•   Typical install uses between 1-20GB
•   Used both “live” and in batch processing
•   Replication and load-balancing


                  Copyright 2003, Jeremy Zawodny

Recommended

MySQL Architecture and Engine
MySQL Architecture and EngineMySQL Architecture and Engine
MySQL Architecture and EngineAbdul Manaf
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
 
MySQL Cluster performance best practices
MySQL Cluster performance best practicesMySQL Cluster performance best practices
MySQL Cluster performance best practicesMat Keep
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsOSSCube
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Mydbops
 

More Related Content

What's hot

Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)Jean-François Gagné
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB plc
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJoel Brewer
 
MySQL Failover and Orchestrator
MySQL Failover and OrchestratorMySQL Failover and Orchestrator
MySQL Failover and OrchestratorSimon J Mudd
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performanceoysteing
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바NeoClova
 
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!Frederic Descamps
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performancejkeriaki
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsTuyen Vuong
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlAimal Miakhel
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)Aurimas Mikalauskas
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorAlmost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorJean-François Gagné
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101MongoDB
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction ManagementMark Ginnebaugh
 
PL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptxPL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptxVinicius M Grippa
 

What's hot (20)

Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
MySQL Failover and Orchestrator
MySQL Failover and OrchestratorMySQL Failover and Orchestrator
MySQL Failover and Orchestrator
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바
 
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and Concepts
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorAlmost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction Management
 
PL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptxPL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptx
 

Similar to Mysql Optimization

Greatdebate Postgres vs Mysql
Greatdebate Postgres vs MysqlGreatdebate Postgres vs Mysql
Greatdebate Postgres vs MysqlKrishna Infosoft
 
The Great Debate: PostgreSQL vs MySQL
The Great Debate: PostgreSQL vs MySQLThe Great Debate: PostgreSQL vs MySQL
The Great Debate: PostgreSQL vs MySQLEDB
 
My S Q L Replication Getting The Most From Slaves
My S Q L  Replication  Getting  The  Most  From  SlavesMy S Q L  Replication  Getting  The  Most  From  Slaves
My S Q L Replication Getting The Most From SlavesPerconaPerformance
 
Under the Hood with MySQL
Under the Hood with MySQLUnder the Hood with MySQL
Under the Hood with MySQLohiocore
 
Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009Andrei Gheorghe
 
Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Marco Tusa
 
Storage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems PresentationStorage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems Presentationandyman3000
 
Optimizing MySQL for Cascade Server
Optimizing MySQL for Cascade ServerOptimizing MySQL for Cascade Server
Optimizing MySQL for Cascade Serverhannonhill
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersSeveralnines
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Clusterguestd34230
 
[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practicejavablend
 
Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive WritesLiran Zelkha
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010jbellis
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014marvin herrera
 
Scalabe MySQL Infrastructure
Scalabe MySQL InfrastructureScalabe MySQL Infrastructure
Scalabe MySQL InfrastructureBalazs Pocze
 
Scaling Drupal: Not IF... HOW
Scaling Drupal: Not IF... HOWScaling Drupal: Not IF... HOW
Scaling Drupal: Not IF... HOWTreehouse Agency
 

Similar to Mysql Optimization (20)

Greatdebate Postgres vs Mysql
Greatdebate Postgres vs MysqlGreatdebate Postgres vs Mysql
Greatdebate Postgres vs Mysql
 
The Great Debate: PostgreSQL vs MySQL
The Great Debate: PostgreSQL vs MySQLThe Great Debate: PostgreSQL vs MySQL
The Great Debate: PostgreSQL vs MySQL
 
My S Q L Replication Getting The Most From Slaves
My S Q L  Replication  Getting  The  Most  From  SlavesMy S Q L  Replication  Getting  The  Most  From  Slaves
My S Q L Replication Getting The Most From Slaves
 
Under the Hood with MySQL
Under the Hood with MySQLUnder the Hood with MySQL
Under the Hood with MySQL
 
Practical MySQL
Practical MySQLPractical MySQL
Practical MySQL
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009
 
Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2
 
Storage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems PresentationStorage Systems for High Scalable Systems Presentation
Storage Systems for High Scalable Systems Presentation
 
Optimizing MySQL for Cascade Server
Optimizing MySQL for Cascade ServerOptimizing MySQL for Cascade Server
Optimizing MySQL for Cascade Server
 
Advanced Deployment
Advanced DeploymentAdvanced Deployment
Advanced Deployment
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB Clusters
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
 
[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice
 
Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
 
Scalabe MySQL Infrastructure
Scalabe MySQL InfrastructureScalabe MySQL Infrastructure
Scalabe MySQL Infrastructure
 
Scaling Drupal: Not IF... HOW
Scaling Drupal: Not IF... HOWScaling Drupal: Not IF... HOW
Scaling Drupal: Not IF... HOW
 
MySQL Aquarium Paris
MySQL Aquarium ParisMySQL Aquarium Paris
MySQL Aquarium Paris
 

More from Renato Shirakashi

Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...
Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...
Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...Renato Shirakashi
 
A riqueza das Redes - segundo Yochai Benkler
A riqueza das Redes - segundo Yochai BenklerA riqueza das Redes - segundo Yochai Benkler
A riqueza das Redes - segundo Yochai BenklerRenato Shirakashi
 
Sistemas Baseados em Conhecimento
Sistemas Baseados em ConhecimentoSistemas Baseados em Conhecimento
Sistemas Baseados em ConhecimentoRenato Shirakashi
 
Comparação entre frameworks PHP
Comparação entre frameworks PHPComparação entre frameworks PHP
Comparação entre frameworks PHPRenato Shirakashi
 
Desenvolva rapidamente utilizando o framework Desenvolva rapidamente utiliz...
Desenvolva rapidamente
utilizando o framework
Desenvolva rapidamente utiliz...Desenvolva rapidamente
utilizando o framework
Desenvolva rapidamente utiliz...
Desenvolva rapidamente utilizando o framework Desenvolva rapidamente utiliz...Renato Shirakashi
 
Via6 - Assinantes e Minha Rede
Via6 - Assinantes e Minha RedeVia6 - Assinantes e Minha Rede
Via6 - Assinantes e Minha RedeRenato Shirakashi
 

More from Renato Shirakashi (9)

Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...
Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...
Direct Labs - 4 erros estratégicos simples que arruinam projetos de criação d...
 
Avaliação Heurística
Avaliação HeurísticaAvaliação Heurística
Avaliação Heurística
 
Naked Objects
Naked ObjectsNaked Objects
Naked Objects
 
A riqueza das Redes - segundo Yochai Benkler
A riqueza das Redes - segundo Yochai BenklerA riqueza das Redes - segundo Yochai Benkler
A riqueza das Redes - segundo Yochai Benkler
 
Sistemas de Recomendação
Sistemas de Recomendação Sistemas de Recomendação
Sistemas de Recomendação
 
Sistemas Baseados em Conhecimento
Sistemas Baseados em ConhecimentoSistemas Baseados em Conhecimento
Sistemas Baseados em Conhecimento
 
Comparação entre frameworks PHP
Comparação entre frameworks PHPComparação entre frameworks PHP
Comparação entre frameworks PHP
 
Desenvolva rapidamente utilizando o framework Desenvolva rapidamente utiliz...
Desenvolva rapidamente
utilizando o framework
Desenvolva rapidamente utiliz...Desenvolva rapidamente
utilizando o framework
Desenvolva rapidamente utiliz...
Desenvolva rapidamente utilizando o framework Desenvolva rapidamente utiliz...
 
Via6 - Assinantes e Minha Rede
Via6 - Assinantes e Minha RedeVia6 - Assinantes e Minha Rede
Via6 - Assinantes e Minha Rede
 

Recently uploaded

My Journey towards Artificial Intelligence
My Journey towards Artificial IntelligenceMy Journey towards Artificial Intelligence
My Journey towards Artificial IntelligenceVijayananda Mohire
 
IT Nation Evolve event 2024 - Quarter 1
IT Nation Evolve event 2024  - Quarter 1IT Nation Evolve event 2024  - Quarter 1
IT Nation Evolve event 2024 - Quarter 1Inbay UK
 
"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura Rochniak"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura RochniakFwdays
 
Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...
Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...
Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...Product School
 
How to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response PlanHow to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response PlanDatabarracks
 
Relationship Counselling: From Disjointed Features to Product-First Thinking ...
Relationship Counselling: From Disjointed Features to Product-First Thinking ...Relationship Counselling: From Disjointed Features to Product-First Thinking ...
Relationship Counselling: From Disjointed Features to Product-First Thinking ...Product School
 
Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)
Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)
Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)François
 
Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...
Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...
Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...UiPathCommunity
 
Leveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docx
Leveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docxLeveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docx
Leveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docxVotarikari Shravan
 
Dynamical systems simulation in Python for science and engineering
Dynamical systems simulation in Python for science and engineeringDynamical systems simulation in Python for science and engineering
Dynamical systems simulation in Python for science and engineeringMassimo Talia
 
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...Neo4j
 
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Umar Saif
 
Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?MENGSAYLOEM1
 
Act Like an Owner, Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner,  Challenge Like a VC by former CPO, TripadvisorAct Like an Owner,  Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner, Challenge Like a VC by former CPO, TripadvisorProduct School
 
From Challenger to Champion: How SpiraPlan Outperforms JIRA+Plugins
From Challenger to Champion: How SpiraPlan Outperforms JIRA+PluginsFrom Challenger to Champion: How SpiraPlan Outperforms JIRA+Plugins
From Challenger to Champion: How SpiraPlan Outperforms JIRA+PluginsInflectra
 
"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor FesenkoFwdays
 
The Future of Product, by Founder & CEO, Product School
The Future of Product, by Founder & CEO, Product SchoolThe Future of Product, by Founder & CEO, Product School
The Future of Product, by Founder & CEO, Product SchoolProduct School
 
Roundtable_-_API_Research__Testing_Tools.pdf
Roundtable_-_API_Research__Testing_Tools.pdfRoundtable_-_API_Research__Testing_Tools.pdf
Roundtable_-_API_Research__Testing_Tools.pdfMostafa Higazy
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17Ana-Maria Mihalceanu
 
LF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIELF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIEDanBrown980551
 

Recently uploaded (20)

My Journey towards Artificial Intelligence
My Journey towards Artificial IntelligenceMy Journey towards Artificial Intelligence
My Journey towards Artificial Intelligence
 
IT Nation Evolve event 2024 - Quarter 1
IT Nation Evolve event 2024  - Quarter 1IT Nation Evolve event 2024  - Quarter 1
IT Nation Evolve event 2024 - Quarter 1
 
"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura Rochniak"Testing of Helm Charts or There and Back Again", Yura Rochniak
"Testing of Helm Charts or There and Back Again", Yura Rochniak
 
Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...
Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...
Cultivating Entrepreneurial Mindset in Product Management: Strategies for Suc...
 
How to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response PlanHow to write an effective Cyber Incident Response Plan
How to write an effective Cyber Incident Response Plan
 
Relationship Counselling: From Disjointed Features to Product-First Thinking ...
Relationship Counselling: From Disjointed Features to Product-First Thinking ...Relationship Counselling: From Disjointed Features to Product-First Thinking ...
Relationship Counselling: From Disjointed Features to Product-First Thinking ...
 
Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)
Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)
Mind your App Footprint 🐾⚡️🌱 (@FlutterHeroes 2024)
 
Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...
Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...
Dev Dives: Leverage APIs and Gen AI to power automations for RPA and software...
 
Leveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docx
Leveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docxLeveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docx
Leveraging SLF4j for Effective Logging in IBM App Connect Enterprise.docx
 
Dynamical systems simulation in Python for science and engineering
Dynamical systems simulation in Python for science and engineeringDynamical systems simulation in Python for science and engineering
Dynamical systems simulation in Python for science and engineering
 
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
ASTRAZENECA. Knowledge Graphs Powering a Fast-moving Global Life Sciences Org...
 
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
 
Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?
 
Act Like an Owner, Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner,  Challenge Like a VC by former CPO, TripadvisorAct Like an Owner,  Challenge Like a VC by former CPO, Tripadvisor
Act Like an Owner, Challenge Like a VC by former CPO, Tripadvisor
 
From Challenger to Champion: How SpiraPlan Outperforms JIRA+Plugins
From Challenger to Champion: How SpiraPlan Outperforms JIRA+PluginsFrom Challenger to Champion: How SpiraPlan Outperforms JIRA+Plugins
From Challenger to Champion: How SpiraPlan Outperforms JIRA+Plugins
 
"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko
 
The Future of Product, by Founder & CEO, Product School
The Future of Product, by Founder & CEO, Product SchoolThe Future of Product, by Founder & CEO, Product School
The Future of Product, by Founder & CEO, Product School
 
Roundtable_-_API_Research__Testing_Tools.pdf
Roundtable_-_API_Research__Testing_Tools.pdfRoundtable_-_API_Research__Testing_Tools.pdf
Roundtable_-_API_Research__Testing_Tools.pdf
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
 
LF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIELF Energy Webinar: Introduction to TROLIE
LF Energy Webinar: Introduction to TROLIE
 

Mysql Optimization

  • 1. MySQL Optimization MySQL User Conference Jeremy Zawodny Yahoo! April 12th, 2003 San Jose, California http://jeremy.zawodny.com/mysql/ Copyright 2003, Jeremy Zawodny
  • 2. About Me • Engineer in Y! Search (prev. Y! Finance) • MySQL user for over 5 years • Active in MySQL community • Write about LAMP for Linux Magazine • MySQL advocacy & support at Yahoo! Home: Jeremy@Zawodny.com Work: jzawodn@yahoo-inc.com http://jeremy.zawodny.com/mysql/ Copyright 2003, Jeremy Zawodny
  • 3. Outline • Introduction • Why Optimize? • Goals • Database Design • Application Design • Writing Fast Queries • MySQL Server Tuning • Operating System Tuning • Hardware Tuning • Network & Replication • Where to Learn More • Questions and Answers Copyright 2003, Jeremy Zawodny
  • 4. Starting Questions • What version of MySQL are you using? • What languages are being used? • Which operating systems? • Familiarity with other RDBMS servers? • Role? DBA? Developer? SysAdmin? • MySQL dedicated or shared servers? • How fast is your growth? – Transaction rates – Data volume Copyright 2003, Jeremy Zawodny
  • 5. What you Need to Know • You should ask questions at any time – There should be sufficient time • MySQL usage – Basic queries (SELECT, UPDATE, INSERT) – Installation or where files are located • Basic programming concepts – Any language will do • Operating system basics – Memory usage, swapping, etc. Copyright 2003, Jeremy Zawodny
  • 6. MySQL at Yahoo! • Roughly 200-400 servers world-wide • FreeBSD and Linux • Commodity hardware • Replaces home-grown “database” systems • Replaces Oracle in a few cases • Typical install uses between 1-20GB • Used both “live” and in batch processing • Replication and load-balancing Copyright 2003, Jeremy Zawodny
  • 7. Why Optimize? • You can do more with less – MySQL on “normal” hardware scales well – A little time can save thousands in hardware – The classic story goes… • As you data grows, you’ll need to – Performance will degrade over time – You’re probably not monitoring it anyway • It is easier than re-coding you apps • Your users will notice if you don’t! Copyright 2003, Jeremy Zawodny
  • 8. MySQL’s Defaults • Tuned for small and medium data sets • Uses very little memory even if available • Suitable for use in a shared environment • Assumes little about your hardware • Begins to slow as growth continues • Uses non-transactional tables (MyISAM) – That’s what most people need (90%) – Very low overhead Copyright 2003, Jeremy Zawodny
  • 9. Scaling MySQL • Like Linux, MySQL scales up and down • Can run many MySQL instances at once • Can run one very big MySQL instance • Can run with only a few MB of memory – Suitable for small devices – Will be disk-bound • Can embed using libmysqld (MySQL 4.x) • Can recompile to add/remove features – Table types, query cache, etc. Copyright 2003, Jeremy Zawodny
  • 10. Using Less Hardware • Hardware is rarely the bottleneck – Well-tuned servers are often disk-bound • MySQL isn’t using it aggressively – You must configure it • Modern CPUs are very fast – What you have is probably sufficient • Memory is plentiful – You’re probably not using what you have • Upgrades do little to solve most problems! Copyright 2003, Jeremy Zawodny
  • 11. Goals • Learn to write fast queries and applications • Learn to design and use the right tables • Know where to look for bottlenecks • Predict behavior as load increases • Understand what to monitor over time • Understand how MySQL uses system resources • Learn what settings you can adjust – In your operating system – In MySQL – In your applications • Know where to learn more… Copyright 2003, Jeremy Zawodny
  • 12. Database Design • Normalize your data by default – Sometime you need to de-normalize – When in doubt, benchmark • MySQL super-smack • MySQL benchmark suite • Home-grown tools • Use your real apps! Copyright 2003, Jeremy Zawodny
  • 13. Database Design • Select the right column types – No bigger than you need – MySQL provides a ton of column types – Use NOT NULL where it makes sense – Use fixed column sizes if you can • MyISAM tables with fixed rows are faster • Concurrency improvements – Store compressed data when possible See: http://www.mysql.com/doc/S/t/Storage_requirements.html Copyright 2003, Jeremy Zawodny
  • 14. Database Design • Select the right table types – What locking model do you need? • Table (MyISAM) • Row (InnoDB) • Page (BDB) – Consider ratio of reads to writes – Foreign key constraints? – Do you need transactions? – Can you afford to lose records in a crash? – Do you know MySQL’s table types? Copyright 2003, Jeremy Zawodny
  • 15. Database Design • MyISAM Tables – Very efficient – Compact storage – In-memory key cache for index data – Table locking – No transactions – Good for • High volume logging (write) • High volume reads • Not both – Variations: Compressed, RAID, Merge Copyright 2003, Jeremy Zawodny
  • 16. Database Design • Compressed MyISAM Tables – Read-only – Good for CD-ROMs and archives • MyISAM RAID Tables – Break the 2GB/4GB/whatever barrier • MyISAM Merge Tables – Many physically identical MyISAM tables – Can treat as a single table (or not) Copyright 2003, Jeremy Zawodny
  • 17. Database Design • HEAP Tables – Stored in memory • They will vanish at server shutdown – Very fast hash-based lookups • Limited index use • Range queries are slower – B-Tree available in 4.1 – Table locking – Great for static lookups – Size can be limited to prevent disaster Copyright 2003, Jeremy Zawodny
  • 18. Database Design • BDB Tables – Transactional – Automatic recovery – Tables grow as needed – Page-level locking (8KB page) • Single READ-COMMITTED isolation level – Uses Berkeley DB under the hood – Few users actually use BDB – Works well for small - medium transaction rate – Locking on the last page can be a problem Copyright 2003, Jeremy Zawodny
  • 19. Database Design • InnoDB Tables – Modeled after Oracle • Row-level locking • Non-locking SELECTs • Uses pre-allocated tablespace files – Multiple isolation levels • Easily changed with a SET command – Referential integrity - foreign keys – High performance – Very high concurrency – Automatic recovery after crash Copyright 2003, Jeremy Zawodny
  • 20. Database Design • Use Indexes wisely – Don’t use several indexes when one will do – Understand the “leftmost prefix” rule • Index on (col1, col2, col3) vs. 3 indexes – Don’t index columns until you need to – Verify that indexes are used (difficult) – Use partial indexes on large (text) fields – Index a hash rather than a large value (URL) • MD5 is an excellent choice • It’s even built-in Copyright 2003, Jeremy Zawodny
  • 21. Database Design • Use full-text indexing if you need it – MyISAM tables only – Very fast – Excellent in MySQL 4.x – Results are ranked (like a search engine might) – Boolean queries • Flexible • Mostly feature-complete – Works on any textual data • Other character sets will need 4.1 or 5.0 Copyright 2003, Jeremy Zawodny
  • 22. Full-Text Search • Use 4.0 if possible – Indexing is much faster – Stop word list customization – Min word size easily changed • Remember to rebuild indexes after changing • In 5.0 we should see – Per-table stop word lists – Per-table word length options – Per-table word characters lists – These might be per-index! Copyright 2003, Jeremy Zawodny
  • 23. Application Design • Don’t store data you don’t need – Compress it – Get rid of it • Don’t store computable data – MySQL can do it – Your app can do it • Don’t ask for data you don’t need… – Do you really need all fields? SELECT * FROM… Copyright 2003, Jeremy Zawodny
  • 24. Application Design • Use MySQL extensions for speed – REPLACE queries Bundled INSERT queries – – Multi-table deletes – User variables • Use logging to track bottlenecks • Don’t perform unnecessary queries – Cache data (static lookup tables) – Use the Query Cache if you must • Benchmark your application – Know where the bottlenecks are – Know how a slow db affects your application Copyright 2003, Jeremy Zawodny
  • 25. Application Design • Use transactions – Prevents data loss – Server does less random I/O – Performance and reliability • Keep the clients “near” the server – Network latency is a killer – Replication can solve geography problems – Can also help solve geology problems (quake) – Running app and MySQL on same hardware Copyright 2003, Jeremy Zawodny
  • 26. Application Design • Think about growth – There are size limits that you might hit – InnoDB and MyISAM both have them (sort of) • Keep primary keys short for InnoDB Copyright 2003, Jeremy Zawodny
  • 27. Application Design • Use prepared queries and placeholders – MySQL doesn’t yet support them – Your API may – When MySQL does, you benefit! – The API may be more efficient anyway – MySQL 4.1 and PHP 5.0 benefit SELECT name, address, state, zip FROM customers WHERE id = ? Copyright 2003, Jeremy Zawodny
  • 28. Application Design • Web apps – Use (but don’t over-use) connection pooling – Use middleware to abstract the database • May also provide caching and pooling – Don’t keep everything in the database! • Images can live on the file system • But you might want to replicate them – Pick the fastest driver you can • Java has several, Perl has two • On Windows, use the “most native” Copyright 2003, Jeremy Zawodny
  • 30. Writing Fast Queries • Use Indexes Use EXPLAIN SELECT • • Simplify where clause • Watch Slow query log • Bundle INSERTs • UNIONs Copyright 2003, Jeremy Zawodny
  • 31. Writing Fast Queries • Understanding how MySQL runs queries • You need to think like MySQL does • Some of its goals are… – Eliminate as many rows as possible – Use indexes where possible – Avoid table scans – Consider many join orders – Avoid hitting the disk – Avoid using the data records if the index has it Copyright 2003, Jeremy Zawodny
  • 32. Writing Fast Queries • EXPLAIN SELECT – Tells you what MySQL is thinking – Which keys (indexes) can it use – Which keys will it use – How many rows must it examine (roughly) • ANALYZE TABLE can help – How hard must MySQL work? Copyright 2003, Jeremy Zawodny
  • 33. Writing Fast Queries • EXPLAIN SELECT mysql> EXPLAIN SELECT * FROM Headlines H, S2H S WHERE S.Symbol = 'YHOO' and H.Id = S.HeadlineId; +-------+--------+-------------------+---------+---------+--------------+------+-------------------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------+--------+-------------------+---------+---------+--------------+------+-------------------------+ |S | ref | HeadlineId,Symbol | Symbol | 75 | const | 383 | where used; Using index | |H | eq_ref | PRIMARY | PRIMARY | 4 | S.HeadlineId | 1 | where used | +-------+--------+-------------------+---------+---------+--------------+------+-------------------------+ 2 rows in set (0.00 sec) mysql> EXPLAIN SELECT * FROM Headlines H, S2H S WHERE S.Symbol = 'YHOO' and H.Id = S.HeadlineId ORDER BY Time DESC; +-------+--------+-------------------+---------+---------+--------------+------+-----------------------------------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------+--------+-------------------+---------+---------+--------------+------+-----------------------------------------+ |S | ref | HeadlineId,Symbol | Symbol | 75 | const | 383 | where used; Using index; Using temporary; Using filesort |H | eq_ref | PRIMARY | PRIMARY | 4 | S.HeadlineId | 1 | where used | +-------+--------+-------------------+---------+---------+--------------+------+-----------------------------------------+ Copyright 2003, Jeremy Zawodny
  • 34. Writing Fast Queries • EXPLAIN SELECT – Table • Order is significant • Aliases appear – Type • System – Table has one row – Easily optimized • Const – Only a single row matches – Read once Copyright 2003, Jeremy Zawodny
  • 35. Writing Fast Queries • EXPLAIN SELECT (continued) – Type (continued) • eq_ref – One row matches per combination – Unique index match • ref – Several matching rows per combination – Non-unique index • range – A range of rows will be retrieved • index – Index will be scanned for matches – Like a table scan, but faster • all – Full table scan – Worst case Copyright 2003, Jeremy Zawodny
  • 36. Writing Fast Queries • EXPLAIN SELECT (continued) – Possible keys • What MySQL had to choose from – Key • What it decided to use – Key length • Length (in bytes) of the longest key – Ref • Which column it will match with – Rows • Approximately how many rows must be examined Copyright 2003, Jeremy Zawodny
  • 37. Writing Fast Queries • EXPLAIN SELECT (continued) – Extra information • Using filesort – An extra pass is required to sort the records – This can be slow at times • Using index – Data will come from the index rather than rows – This can speed things up • Using temporary – MySQL will create a temporary table – It’ll be a disk-based table if it’s too large • Where used – The where clause will be applied to this table Copyright 2003, Jeremy Zawodny
  • 38. Writing Fast Queries • Optimizer tips and tricks – It’s smart, but not perfect – Only one index per table per query • You may need to de-normalize to get performance • You may need to write two queries instead of one – Don’t compute in the WHERE • MySQL doesn’t know how to optimize constant expressions SELECT * FROM Headlines WHERE Time > SUBDATE(NOW(), INTERVAL 7 DAY); Copyright 2003, Jeremy Zawodny
  • 39. Insert Speed • In 4.1 and beyond, use prepared statements • In older versions – Single inserts are the slowest – Multi-rows inserts are faster – Bulk-loading (LOAD DATA or mysqlimport) are very, very, very fast • Using InnoDB, use transactions wisely – Many inserts in AUTOCOMMIT mode are very, very slow Copyright 2003, Jeremy Zawodny
  • 40. Query Cache • Part of MySQL 4.0 • Can seriously boost performance • Might save legacy apps you can’t change • Use query cache selectively if you have lots of writes – SELECT SQL_CACHE … • Use mytop to watch query cache stats – Version 1.3 and 1.4 will have more stats Copyright 2003, Jeremy Zawodny
  • 41. MySQL Server Tuning • Watching performance • Benchmarking • Tunable Parameters – Most bang, least effort – Incremental gains • Methodology – Iterative testing – Long-term monitoring Copyright 2003, Jeremy Zawodny
  • 42. MySQL Server Tuning Watching Performance Copyright 2003, Jeremy Zawodny
  • 43. MySQL Server Tuning • Key Performance Numbers – Queries per second • Min, Max, Short-term, Long-Term – Bytes per second • Inbound vs. Outbound – New connections per second – Idle vs. Active clients – Key cache efficiency – Query cache efficiency Copyright 2003, Jeremy Zawodny
  • 44. MySQL Server Tuning • How MySQL uses memory – Main Global Caches and Buffers • Query cache • Key buffer • Table cache • InnoDB buffer pool • InnoDB log buffer – Main Thread-specific Caches and Buffers • Record buffer • Sort buffer • Join buffer Copyright 2003, Jeremy Zawodny
  • 45. MySQL Server Tuning • SHOW STAUTS – Created_tmp_disk_tables • If large, increase temp table size – Handler_* • Determine key buffer effectiveness – Com_* • Find the commands that are most often run – Questions and Uptime • Compute queries/second – Select_* • How many types of each SELECT are executed – Qcache_* • Query cache performance Copyright 2003, Jeremy Zawodny
  • 46. On-the-Fly Tuning • Use MySQL’s SET syntax to change parameters on the fly (new in 4.0) – max_connections – wait_timeout – thread_cache – key_buffer_size – table_cache • Don’t change too much at once • Persistent connections aren’t always fast! • Changes may take time to notice Copyright 2003, Jeremy Zawodny
  • 47. MySQL Server Tuning • SHOW STATUS – Table_locks_* • How many times are queries waiting for locks? • Concurrency problems show up here – Bytes_* • How much data are you pumping out • Compare with inbound traffic – Qcache_* • Query cache performance • Memory usage Copyright 2003, Jeremy Zawodny
  • 48. MySQL Server Tuning • my.cnf file parameters – key_buffer – tmp_table_size – Table_cache – Max_connections – Max_user_connections – Long_query_time – Thread_concurrency Copyright 2003, Jeremy Zawodny
  • 49. MySQL Server Tuning • my.cnf file parameters – innodb_buffer_pool_size – innodb_log_file_size – innodb_file_io_threads – innodb_flush_log_at_trx_commit – innodb_log_buffer_size – innodb_flush_method • fdatasync • O_DSYNC Copyright 2003, Jeremy Zawodny
  • 50. InnoDB Performance • Transaction log flushing has three options – (1) Flush on commit – (0) Never flush – (2) Flush once per second Copyright 2003, Jeremy Zawodny
  • 51. MySQL Server Tuning • Fileysystem Issues – Spread data among disks • Put heavily used and lightly used databases together • RAID-5 or RAID-10 for data (w/batter-backed cache) • RAID-1 for logs New CREATE TABLE makes this easier • – Logs separate from data • Logs are mostly serialized writes • Tables are updated and used in mostly random fashion – If you have a lot of tables in a database • Use a filesystem designed to handle it • ResiserFS is a good choice – A journaling filesystem • Makes crash recovery faster • Better utilizes disk I/O (usually) Copyright 2003, Jeremy Zawodny
  • 52. MySQL Server Tuning • Upgrade once in a while – New versions are often faster – Better optimizations in query parser – New and enhanced caching • Convert older tables to newer format – ISAM to MyISAM – BDB to InnoDB (or not) – ALTER TABLE my_table TYPE=InnoDB • Don’t flush the transaction logs on commit Copyright 2003, Jeremy Zawodny
  • 53. Upgrade Testing • It’s often a good idea to keep up-to-date • Performance tweaks and optimizations are introduced during the maintenance process • Be sure to test your critical queries carefully • Always use a real load test or read the EXPLAIN output • Without load, “slow” queries are often fast Copyright 2003, Jeremy Zawodny
  • 54. Operating System Tuning • Virtual Memory Use – FreeBSD - excellent – Linux - varies wildly • 2.4.9 good • >= 2.4.16 good • Others not good • Per-process limits on: – Memory – File descriptors • Network duplex settings • Competing processes on the machine? Copyright 2003, Jeremy Zawodny
  • 55. Operating System Tuning • Key Metrics – Memory used/free/cache/buffer • Swapping is very bad • You might even disable swap – Paging and page faults • Make sure there’s no memory pressure • Server variables might be wrong if many page faults – Disk I/O • Make sure the I/O is where you expect • Disk I/O tuning (see your OS docs) – Processes running, sleeping, blocked/waiting – Actual CPU usage (might be too low) Copyright 2003, Jeremy Zawodny
  • 56. Operating System Tuning • Useful Unix Tools – top, ps, vmstat – iostat, sar – mrtg, rrdtool • Windows Tools – Performance Monitor (perfmeter) – Task Manager – Others I don’t know (not a Windows guy) Copyright 2003, Jeremy Zawodny
  • 57. Hardware Tuning • CPU Issues – Speed – Single vs. Dual • RAM Issues • Disks – IDE vs. SCSI – RAID (hardware or software) – Battery-backed cache on controller is best Copyright 2003, Jeremy Zawodny
  • 58. Hardware Tuning • Network – The faster the better (watch latency) – Duplex settings • I/O Channels – The more the merrier – Most PC motherboards suck – Server-class boards are better – High-end hardware (IBM, Sun) are best – You’ll be lucky to have this problem! Copyright 2003, Jeremy Zawodny
  • 59. Network & Replication • Put clients near servers • Redundancy is very good • Put slaves near master(s) – Unless that’s stupid • Use load-balancing technology – High(er) availability MySQL – Easy scaling of traffic • Pick the correct replication topology • Backup slaves instead of the master Copyright 2003, Jeremy Zawodny
  • 60. Network & Replication • Replication is quite flexible • Can build a topology to solve most problems • Only a few nagging issues – Auto-increment fields – Automatic Fail-over – Need to build health checks • Performance/Latency • Slave stopped? • Come to my replication talk to learn more! Copyright 2003, Jeremy Zawodny
  • 61. Stupid Query Tricks • Use SQL_CALC_ROWS and FOUND_ROWS() rather than double- queries: – SELECT … LIMIT N, M – SELECT COUNT(*) • Instead: – SELECT … LIMIT N, M – SELECT FOUND_ROWS() • Requires far less overhead on MySQL Copyright 2003, Jeremy Zawodny
  • 62. Stupid Query Tricks • Use a UNION to re-write a slow OR query SELECT * FROM mytable WHERE col1 = ‘foo’ OR col2 = ‘bar’ (SELECT * FROM mytable WHERE col1 = ‘foo’) UNION (SELECT * FROM mytable WHERE col2 = ‘bar’) Copyright 2003, Jeremy Zawodny
  • 63. Stupid Query Tricks • Ordering, limiting, and ordering again (SELECT * FROM mytable WHERE col1 = ‘foo’ ORDER BY col2 LIMIT 50) ORDER BY col3 Copyright 2003, Jeremy Zawodny
  • 64. Final Advice • Read • Learn • Test • Ask • Monitor • Benchmark Copyright 2003, Jeremy Zawodny
  • 65. For More Info… • MySQL mailing lists – Visit lists.mysql.com • Books – MySQL Manual – MySQL (Paul’s Book) – Managing & Using MySQL • Web searching Copyright 2003, Jeremy Zawodny
  • 66. Questions and Answers Copyright 2003, Jeremy Zawodny