SlideShare ist ein Scribd-Unternehmen logo
1 von 61
10x Performance Improvements
          in 10 steps
    A MySQL Case Study
                Ronald Bradford
           http://ronaldbradford.com

       MySQL Users Conference - 2010.04
Application
Typical Web 2.0 social media site (Europe based)

• Users - Visitors, Free Members, Paying Members
• Friends
• User Content - Video, Pictures
• Forums, Chat, Email
Server Environment
• 1 Master Database Server (MySQL 5.0.x)
• 3 Slave Database Servers (MySQL 5.0.x)
• 5 Web Servers (Apache/PHP)
• 1 Static Content Server (Nginx)
• 1 Mail Server
Step 1


Monitor, Monitor, Monitor
1. Monitor, Monitor, Monitor
• What’s happened?
• What’s happening now?
• What’s going to happen?

             Past, Present, Future
1. Monitor, Monitor, Monitor
                                                            Action 1
Monitoring Software

• Installation of Cacti http://www.cacti.net/
                      -



• Installation of MySQL Cacti Templates     -
  http://code.google.com/p/mysql-cacti-templates/

• (Optional) Installation of MONyog   -   http://www.webyog.com/
1. Monitor, Monitor, Monitor
                                            Action 2
Custom Dashboard

• Most important - The state of NOW
• Single Page Alerts - GREEN YELLOW   RED
Screen print goes here




                         Dashboard
                          Example
1. Monitor, Monitor, Monitor
                                                  Action 3
Alerting Software

• Installation of Nagios http://www.nagios.org/
                       -



• MONyog also has some DB specific alerts
1. Monitor, Monitor, Monitor
                               Action 4
Application Metrics

• Total page generation time
Step 2


  Identify problem SQL
2. Identify Problem SQL
Identify SQL Statements

• Slow Query Log
• Processlist
• Binary Log
• Status Statistics
2. Identify Problem SQL
Problems

• Sampling
• Granularity
Solution

• tcpdump + mk-query-digest
2. Identify Problem SQL
                                                                Action 1
• Install maatkit - http://www.maatkit.org
• Install OS tcpdump (if necessary)
• Get sudo access to tcpdump

http://ronaldbradford.com/blog/take-a-look-at-mk-query-digest-2009-10-08/
# Rank Query ID           Response time    Calls    R/Call       Item
# ==== ================== ================ ======= ==========    ====
#    1 0xB8CE56EEC1A2FBA0    14.0830 26.8%       78   0.180552   SELECT   c u
#    2 0x195A4D6CB65C4C53     6.7800 12.9%     257    0.026381   SELECT   u
#    3 0xCD107808735A693C     3.7355 7.1%         8   0.466943   SELECT   c u
#    4 0xED55DD72AB650884     3.6225 6.9%        77   0.047046   SELECT   u
#    5 0xE817EFFFF5F6FFFD     3.3616 6.4%      147    0.022868   SELECT   UNION c
#    6 0x15FD03E7DB5F1B75     2.8842 5.5%         2   1.442116   SELECT   c u
#    7 0x83027CD415FADB8B     2.8676 5.5%        70   0.040965   SELECT   c u
#    8 0x1577013C472FD0C6     1.8703 3.6%        61   0.030660   SELECT   c
#    9 0xE565A2ED3959DF4E     1.3962 2.7%         5   0.279241   SELECT   c t u
#   10 0xE15AE2542D98CE76     1.3638 2.6%         6   0.227306   SELECT   c
#   11 0x8A94BB83CB730494     1.2523 2.4%      148    0.008461   SELECT   hv u
#   12 0x959C3B3A967928A6     1.1663 2.2%         5   0.233261   SELECT   c t u
#   13 0xBC6E3F701328E95E     1.1122 2.1%         4   0.278044   SELECT   c t u
# Query 2: 4.94 QPS, 0.13x concurrency, ID 0x195A4D6CB65C4C53 at byte 4851683
# This item is included in the report because it matches --limit.
#              pct   total     min     max     avg     95% stddev median
# Count          3      257
# Exec time     10       7s   35us   492ms    26ms   189ms    78ms    332us
# Time range 2009-10-16 11:48:55.896978 to 2009-10-16 11:49:47.760802
# bytes          2 10.75k       41      43   42.85   42.48    0.67    42.48
# Errors                  1   none
# Rows affe      0        0       0      0       0       0        0       0
# Warning c      0        0       0      0       0       0        0       0
# Query_time distribution
#   1us
# 10us #
# 100us ################################################################
#   1ms ####
# 10ms ###
# 100ms ########
#    1s
# 10s+
# Tables
#    SHOW TABLE STATUS LIKE 'u'G
#    SHOW CREATE TABLE `u`G
# EXPLAIN
SELECT ... FROM u ...G
2. Identify Problem SQL
                                          Action 2
• Wrappers to capture SQL
• Re-run on single/multiple servers
  • e.g. Different slave configurations
2. Identify Problem SQL
                                                    Tip

• Enable General Query Log in Development/Testing
• Great for testing Batch Jobs
2. Identify Problem SQL
                                                       Action 3
Application Logic

• Show total master/slave SQL statements executed
• Show all SQL with execution time (admin user only)
                                                        Tip

• Have abstracted class/method to execute ALL SQL
Step 3


  Analyze problem SQL
3. Analyze Problem SQL
• Query Execution Plan (QEP)
  • EXPLAIN [EXTENDED] SELECT ...
• Table/Index Structure
  • SHOW CREATE TABLE <tablename>G
• Table Statistics
  • SHOW TABLE STATUS LIKE ‘<tablename>’G
3. Analyze Problem SQL                                Good

mysql> EXPLAIN SELECT id FROM example_table WHERE id=1G

*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: example_table
         type: const
possible_keys: PRIMARY
          key: PRIMARY
      key_len: 4
          ref: const
         rows: 1
        Extra: Using index
3. Analyze Problem SQL                                Bad

  mysql> EXPLAIN SELECT * FROM example_tableG

*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: example_table
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 659
        Extra:
3. Analyze Problem SQL                 Tip

• SQL Commenting
   • Identify batch statement SQL
   • Identify cached SQL

  SELECT /* Cache: 10m */ ....
  SELECT /* Batch: EOD report */ ...
  SELECT /* Func: 123 */        ....
Step 4


    The Art of Indexes
4. The Art of Indexes
• Different Types
  • Column
  • Concatenated
  • Covering
  • Partial
http://ronaldbradford.com/blog/understanding-different-mysql-index-implementations-2009-07-22/
4. The Art of Indexes
                        Action 1
• EXPLAIN Output
  • Possible keys
  • Key used
  • Key length
  • Using Index
4. The Art of Indexes                     Tip

• Generally only 1 index used per table
• Make column NOT NULL when possible
• Statistics affect index choices
• Storage engines affect operations
Before (7.88 seconds)                    After (0.04 seconds)
*************************** 2. row **   *************************** 2. row ***
           id: 2                                   id: 2
  select_type: DEPENDENT SUBQUERY         select_type: DEPENDENT SUBQUERY
        table: h_p                              table: h_p
         type: ALL                               type: index_subquery
possible_keys: NULL                     possible_keys: UId
          key: NULL                               key: UId
      key_len: NULL                           key_len: 4
          ref: NULL                               ref: func
         rows: 33789                             rows: 2
        Extra: Using where                      Extra: Using index



         ALTER TABLE h_p ADD INDEX (UId);
mysql> explain SELECT UID, FUID, COUNT(*) AS Count FROM f
               GROUP BY UID, FUID ORDER BY Count DESC LIMIT 2000G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: f
         type: index
possible_keys: NULL
          key: UID
      key_len: 8
          ref: NULL
         rows: 2151326
        Extra: Using index; Using temporary; Using filesort



ALTER TABLE f DROP INDEX UID,
ADD INDEX (UID,FUID)
4. The Art of Indexes



  Indexes can hurt performance
Step 5


 Offloading Master Load
5. Offloading Master Load
• Identify statements for READ ONLY slave(s)
  • e.g. Long running batch statements



  Single point v scalable solution
Step 6


         Improving SQL
6. Improving SQL
• Poor SQL Examples
   • ORDER BY RAND()
   • SELECT *
   • Lookup joins
   • ORDER BY
         The database is best for storing
          and retrieving data not logic
Step 7


     Storage Engines
7. Storage Engines
• MyISAM is default
• Table level locking
  • Concurrent SELECT statements
  • INSERT/UPDATE/DELETE blocked by long running SELECT
  • All SELECT’s blocked by INSERT/UPDATE/DELETE
• Supports FULLTEXT
7. Storage Engines
• InnoDB supports transactions
• Row level locking with MVCC
• Does not support FULLTEXT
• Different memory management
• Different system variables
7. Storage Engines
• There are other storage engines
  • Memory
  • Archive
  • Blackhole
  • Third party
7. Storage Engines
Using Multiple Engines

• Different memory management
• Different system variables
• Different monitoring
• Affects backup strategy
7. Storage Engines
                                     Action 1
• Configure InnoDB correctly
  • innodb_buffer_pool_size
  • innodb_log_file_size
  • innodb_flush_log_at_trx_commit
7. Storage Engines
                                     Action 2
• Converted the two primary tables
   • Users
   • Content

              Locking eliminated
Step 8


         Caching
8. Caching
                                                  Action 1
• Memcache is your friend http://memcached.org/
                         -



  • Cache query results
  • Cache lookup data (eliminate joins)
  • Cache aggregated per user information
• Caching Page Content
  • Top rated (e.g. for 5 minutes)
8. Caching
                                              Action 2
• MySQL has a Query Cache
  • Determine the real benefit
  • Turn on or off dynamically
  • SET GLOBAL query_cache_size   = 1024*1024*32;
8. Caching                        Tip




     The best performance
    improvement for an SQL
  statement is to eliminate it.
Step 9


         Sharding
9. Sharding
• Application level horizontal and vertical partitioning
• Vertical Partitioning
  • Grouping like structures together (e.g. logging, forums)
• Horizontal Partitioning
  • Affecting a smaller set of users (i.e. not 100%)
9. Sharding
                                                  Action 1
• Separate Logging
   • Reduced replication load on primary server
Step 10


 Database Management
10. Database Management
Database Maintenance

• Adding indexes (e.g. ALTER)
• OPTIMIZE TABLE
• Archive/purging data (e.g DELETE)

             Blocking Operations
10. Database Maintenance
                                          Action 1
• Automate slave inclusion/exclusion
• Ability to apply DB changes to slaves
• Master still a problem
10. Database Maintenance
                                             Action 2
• Install Fail-Over Master Server
  • Slave + Master features
  • Master extra configuration
• Scripts to switch slaves
• Scripts to enable/disable Master(s)
• Scripts to change application connection
10. Database Maintenance

      Higher Availability
              &
   Testing Disaster Recovery
Bonus




Front End Improvements
11. Front End Improvements
• Know your total website load time http://getfirebug.com/
                                   -



  • How much time is actually database related?
• Reduce HTML page size - 15% improvement
  • Remove full URL’s, inline css styles
• Reduce/combine css & js files
• Identify blocking elements (e.g. js)
11. Front End Improvements
• Split static content to different ServerName
• Spread static content over multiple ServerNames (e.g. 3)
• Sprites - Combining lightweight images http://spriteme.org/
                                        -



• Cookie-less domain name for static content
Conclusion
Before
• Users experienced slow or unreliable load times
• Management could observe, but no quantifiable details
• Concern over load for increased growth
• Release of some new features on hold
Now
• Users experienced consistent load times (~60ms)
 • Quantifiable and visible real-time results
• Far greater load now supported (Clients + DB)
• Better testability and verification for scaling
• New features can be deployed
Consulting Available Now


  http://ronaldbradford.com

Weitere ähnliche Inhalte

Was ist angesagt?

Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...Sveta Smirnova
 
Moving to the NoSQL side: MySQL JSON functions
 Moving to the NoSQL side: MySQL JSON functions Moving to the NoSQL side: MySQL JSON functions
Moving to the NoSQL side: MySQL JSON functionsSveta Smirnova
 
Flexviews materialized views for my sql
Flexviews materialized views for my sqlFlexviews materialized views for my sql
Flexviews materialized views for my sqlJustin Swanhart
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Explaining the MySQL Explain
Explaining the MySQL ExplainExplaining the MySQL Explain
Explaining the MySQL ExplainMYXPLAIN
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsSveta Smirnova
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)Valeriy Kravchuk
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsMikhail Egorov
 
Mini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingEnkitec
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Valeriy Kravchuk
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningFromDual GmbH
 
Sql injection 幼幼班
Sql injection 幼幼班Sql injection 幼幼班
Sql injection 幼幼班hugo lu
 
Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Valeriy Kravchuk
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukValeriy Kravchuk
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLPadraig O'Sullivan
 
Mysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsValeriy Kravchuk
 

Was ist angesagt? (20)

Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...
 
Moving to the NoSQL side: MySQL JSON functions
 Moving to the NoSQL side: MySQL JSON functions Moving to the NoSQL side: MySQL JSON functions
Moving to the NoSQL side: MySQL JSON functions
 
Flexviews materialized views for my sql
Flexviews materialized views for my sqlFlexviews materialized views for my sql
Flexviews materialized views for my sql
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Explaining the MySQL Explain
Explaining the MySQL ExplainExplaining the MySQL Explain
Explaining the MySQL Explain
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAs
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
The zen of async: Best practices for best performance
The zen of async: Best practices for best performanceThe zen of async: Best practices for best performance
The zen of async: Best practices for best performance
 
More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)
 
Library system project file
Library system project fileLibrary system project file
Library system project file
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
 
Mini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for Profiling
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
 
Sql injection 幼幼班
Sql injection 幼幼班Sql injection 幼幼班
Sql injection 幼幼班
 
Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQL
 
Not so blind SQL Injection
Not so blind SQL InjectionNot so blind SQL Injection
Not so blind SQL Injection
 
Mysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50mins
 

Andere mochten auch

My Interest Is India
My Interest Is IndiaMy Interest Is India
My Interest Is Indiaschool
 
Brooke Singer: "undesigning"
Brooke Singer: "undesigning"Brooke Singer: "undesigning"
Brooke Singer: "undesigning"Eyebeam
 
Stop throwing away your money! How to avoid duplicate payments without expens...
Stop throwing away your money! How to avoid duplicate payments without expens...Stop throwing away your money! How to avoid duplicate payments without expens...
Stop throwing away your money! How to avoid duplicate payments without expens...sharedserviceslink.com
 
Gotta Go (teen authored presentations from Eyebeam's Digital Day Camp)
Gotta Go  (teen authored presentations from Eyebeam's Digital Day Camp)Gotta Go  (teen authored presentations from Eyebeam's Digital Day Camp)
Gotta Go (teen authored presentations from Eyebeam's Digital Day Camp)Eyebeam
 
Agora (teen authored presentation from Eyebeam's Digital Day Camp)
Agora  (teen authored presentation from Eyebeam's Digital Day Camp)Agora  (teen authored presentation from Eyebeam's Digital Day Camp)
Agora (teen authored presentation from Eyebeam's Digital Day Camp)Eyebeam
 
Made in Midtown?
Made in Midtown?Made in Midtown?
Made in Midtown?Eyebeam
 
ElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online CollaborationElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online CollaborationEyebeam
 
Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...
Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...
Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...Eyebeam
 
Smoothly passing the baton from captive to outsourced service delivery in jus...
Smoothly passing the baton from captive to outsourced service delivery in jus...Smoothly passing the baton from captive to outsourced service delivery in jus...
Smoothly passing the baton from captive to outsourced service delivery in jus...sharedserviceslink.com
 
Touching your invoices? You don’t need to. 14 'how to’s' to touchless processing
Touching your invoices? You don’t need to. 14 'how to’s' to touchless processingTouching your invoices? You don’t need to. 14 'how to’s' to touchless processing
Touching your invoices? You don’t need to. 14 'how to’s' to touchless processingsharedserviceslink.com
 
Let your suppliers do the work: how to set up ERS/self-billing with your most...
Let your suppliers do the work: how to set up ERS/self-billing with your most...Let your suppliers do the work: how to set up ERS/self-billing with your most...
Let your suppliers do the work: how to set up ERS/self-billing with your most...sharedserviceslink.com
 
ElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online CollaborationElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online CollaborationEyebeam
 
Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...
Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...
Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...sharedserviceslink.com
 

Andere mochten auch (15)

My Interest Is India
My Interest Is IndiaMy Interest Is India
My Interest Is India
 
Brooke Singer: "undesigning"
Brooke Singer: "undesigning"Brooke Singer: "undesigning"
Brooke Singer: "undesigning"
 
Stop throwing away your money! How to avoid duplicate payments without expens...
Stop throwing away your money! How to avoid duplicate payments without expens...Stop throwing away your money! How to avoid duplicate payments without expens...
Stop throwing away your money! How to avoid duplicate payments without expens...
 
Gotta Go (teen authored presentations from Eyebeam's Digital Day Camp)
Gotta Go  (teen authored presentations from Eyebeam's Digital Day Camp)Gotta Go  (teen authored presentations from Eyebeam's Digital Day Camp)
Gotta Go (teen authored presentations from Eyebeam's Digital Day Camp)
 
A Shared World
A Shared WorldA Shared World
A Shared World
 
Agora (teen authored presentation from Eyebeam's Digital Day Camp)
Agora  (teen authored presentation from Eyebeam's Digital Day Camp)Agora  (teen authored presentation from Eyebeam's Digital Day Camp)
Agora (teen authored presentation from Eyebeam's Digital Day Camp)
 
Made in Midtown?
Made in Midtown?Made in Midtown?
Made in Midtown?
 
ElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online CollaborationElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online Collaboration
 
Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...
Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...
Off the Beaten Path (Teen authored presentations from Eyebeam's Digital Day C...
 
Smoothly passing the baton from captive to outsourced service delivery in jus...
Smoothly passing the baton from captive to outsourced service delivery in jus...Smoothly passing the baton from captive to outsourced service delivery in jus...
Smoothly passing the baton from captive to outsourced service delivery in jus...
 
Touching your invoices? You don’t need to. 14 'how to’s' to touchless processing
Touching your invoices? You don’t need to. 14 'how to’s' to touchless processingTouching your invoices? You don’t need to. 14 'how to’s' to touchless processing
Touching your invoices? You don’t need to. 14 'how to’s' to touchless processing
 
The Shared World
The Shared WorldThe Shared World
The Shared World
 
Let your suppliers do the work: how to set up ERS/self-billing with your most...
Let your suppliers do the work: how to set up ERS/self-billing with your most...Let your suppliers do the work: how to set up ERS/self-billing with your most...
Let your suppliers do the work: how to set up ERS/self-billing with your most...
 
ElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online CollaborationElectroSmog SkillShare: Tools and Models for Online Collaboration
ElectroSmog SkillShare: Tools and Models for Online Collaboration
 
Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...
Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...
Supply chain finance models Part 1: bank-agnostic models, bank-funded and man...
 

Ähnlich wie 10x improvement-mysql-100419105218-phpapp02

Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
10x Performance Improvements - A Case Study
10x Performance Improvements - A Case Study10x Performance Improvements - A Case Study
10x Performance Improvements - A Case StudyRonald Bradford
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The SequelSilicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The SequelDaniel Coupal
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionSveta Smirnova
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksMYXPLAIN
 
What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...Sveta Smirnova
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2Koen Van Hulle
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
sveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionsveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionDariia Seimova
 
Performance Schema in Action: demo
Performance Schema in Action: demoPerformance Schema in Action: demo
Performance Schema in Action: demoSveta Smirnova
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsPetr Dvorak
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the ServerdevObjective
 

Ähnlich wie 10x improvement-mysql-100419105218-phpapp02 (20)

Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
Quick Wins
Quick WinsQuick Wins
Quick Wins
 
10x Performance Improvements - A Case Study
10x Performance Improvements - A Case Study10x Performance Improvements - A Case Study
10x Performance Improvements - A Case Study
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The SequelSilicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New Tricks
 
What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2
 
Hack through Injections
Hack through InjectionsHack through Injections
Hack through Injections
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
Database training for developers
Database training for developersDatabase training for developers
Database training for developers
 
sveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionsveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in action
 
Performance Schema in Action: demo
Performance Schema in Action: demoPerformance Schema in Action: demo
Performance Schema in Action: demo
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS Topics
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 

Kürzlich hochgeladen

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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 StreamsRoshan Dwivedi
 
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 AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

10x improvement-mysql-100419105218-phpapp02

  • 1. 10x Performance Improvements in 10 steps A MySQL Case Study Ronald Bradford http://ronaldbradford.com MySQL Users Conference - 2010.04
  • 2. Application Typical Web 2.0 social media site (Europe based) • Users - Visitors, Free Members, Paying Members • Friends • User Content - Video, Pictures • Forums, Chat, Email
  • 3. Server Environment • 1 Master Database Server (MySQL 5.0.x) • 3 Slave Database Servers (MySQL 5.0.x) • 5 Web Servers (Apache/PHP) • 1 Static Content Server (Nginx) • 1 Mail Server
  • 5. 1. Monitor, Monitor, Monitor • What’s happened? • What’s happening now? • What’s going to happen? Past, Present, Future
  • 6. 1. Monitor, Monitor, Monitor Action 1 Monitoring Software • Installation of Cacti http://www.cacti.net/ - • Installation of MySQL Cacti Templates - http://code.google.com/p/mysql-cacti-templates/ • (Optional) Installation of MONyog - http://www.webyog.com/
  • 7. 1. Monitor, Monitor, Monitor Action 2 Custom Dashboard • Most important - The state of NOW • Single Page Alerts - GREEN YELLOW RED
  • 8. Screen print goes here Dashboard Example
  • 9. 1. Monitor, Monitor, Monitor Action 3 Alerting Software • Installation of Nagios http://www.nagios.org/ - • MONyog also has some DB specific alerts
  • 10. 1. Monitor, Monitor, Monitor Action 4 Application Metrics • Total page generation time
  • 11. Step 2 Identify problem SQL
  • 12. 2. Identify Problem SQL Identify SQL Statements • Slow Query Log • Processlist • Binary Log • Status Statistics
  • 13. 2. Identify Problem SQL Problems • Sampling • Granularity Solution • tcpdump + mk-query-digest
  • 14. 2. Identify Problem SQL Action 1 • Install maatkit - http://www.maatkit.org • Install OS tcpdump (if necessary) • Get sudo access to tcpdump http://ronaldbradford.com/blog/take-a-look-at-mk-query-digest-2009-10-08/
  • 15. # Rank Query ID Response time Calls R/Call Item # ==== ================== ================ ======= ========== ==== # 1 0xB8CE56EEC1A2FBA0 14.0830 26.8% 78 0.180552 SELECT c u # 2 0x195A4D6CB65C4C53 6.7800 12.9% 257 0.026381 SELECT u # 3 0xCD107808735A693C 3.7355 7.1% 8 0.466943 SELECT c u # 4 0xED55DD72AB650884 3.6225 6.9% 77 0.047046 SELECT u # 5 0xE817EFFFF5F6FFFD 3.3616 6.4% 147 0.022868 SELECT UNION c # 6 0x15FD03E7DB5F1B75 2.8842 5.5% 2 1.442116 SELECT c u # 7 0x83027CD415FADB8B 2.8676 5.5% 70 0.040965 SELECT c u # 8 0x1577013C472FD0C6 1.8703 3.6% 61 0.030660 SELECT c # 9 0xE565A2ED3959DF4E 1.3962 2.7% 5 0.279241 SELECT c t u # 10 0xE15AE2542D98CE76 1.3638 2.6% 6 0.227306 SELECT c # 11 0x8A94BB83CB730494 1.2523 2.4% 148 0.008461 SELECT hv u # 12 0x959C3B3A967928A6 1.1663 2.2% 5 0.233261 SELECT c t u # 13 0xBC6E3F701328E95E 1.1122 2.1% 4 0.278044 SELECT c t u
  • 16. # Query 2: 4.94 QPS, 0.13x concurrency, ID 0x195A4D6CB65C4C53 at byte 4851683 # This item is included in the report because it matches --limit. # pct total min max avg 95% stddev median # Count 3 257 # Exec time 10 7s 35us 492ms 26ms 189ms 78ms 332us # Time range 2009-10-16 11:48:55.896978 to 2009-10-16 11:49:47.760802 # bytes 2 10.75k 41 43 42.85 42.48 0.67 42.48 # Errors 1 none # Rows affe 0 0 0 0 0 0 0 0 # Warning c 0 0 0 0 0 0 0 0 # Query_time distribution # 1us # 10us # # 100us ################################################################ # 1ms #### # 10ms ### # 100ms ######## # 1s # 10s+ # Tables # SHOW TABLE STATUS LIKE 'u'G # SHOW CREATE TABLE `u`G # EXPLAIN SELECT ... FROM u ...G
  • 17. 2. Identify Problem SQL Action 2 • Wrappers to capture SQL • Re-run on single/multiple servers • e.g. Different slave configurations
  • 18. 2. Identify Problem SQL Tip • Enable General Query Log in Development/Testing • Great for testing Batch Jobs
  • 19. 2. Identify Problem SQL Action 3 Application Logic • Show total master/slave SQL statements executed • Show all SQL with execution time (admin user only) Tip • Have abstracted class/method to execute ALL SQL
  • 20. Step 3 Analyze problem SQL
  • 21. 3. Analyze Problem SQL • Query Execution Plan (QEP) • EXPLAIN [EXTENDED] SELECT ... • Table/Index Structure • SHOW CREATE TABLE <tablename>G • Table Statistics • SHOW TABLE STATUS LIKE ‘<tablename>’G
  • 22. 3. Analyze Problem SQL Good mysql> EXPLAIN SELECT id FROM example_table WHERE id=1G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: example_table type: const possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 1 Extra: Using index
  • 23. 3. Analyze Problem SQL Bad mysql> EXPLAIN SELECT * FROM example_tableG *************************** 1. row *************************** id: 1 select_type: SIMPLE table: example_table type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 659 Extra:
  • 24. 3. Analyze Problem SQL Tip • SQL Commenting • Identify batch statement SQL • Identify cached SQL SELECT /* Cache: 10m */ .... SELECT /* Batch: EOD report */ ... SELECT /* Func: 123 */ ....
  • 25. Step 4 The Art of Indexes
  • 26. 4. The Art of Indexes • Different Types • Column • Concatenated • Covering • Partial http://ronaldbradford.com/blog/understanding-different-mysql-index-implementations-2009-07-22/
  • 27. 4. The Art of Indexes Action 1 • EXPLAIN Output • Possible keys • Key used • Key length • Using Index
  • 28. 4. The Art of Indexes Tip • Generally only 1 index used per table • Make column NOT NULL when possible • Statistics affect index choices • Storage engines affect operations
  • 29. Before (7.88 seconds) After (0.04 seconds) *************************** 2. row ** *************************** 2. row *** id: 2 id: 2 select_type: DEPENDENT SUBQUERY select_type: DEPENDENT SUBQUERY table: h_p table: h_p type: ALL type: index_subquery possible_keys: NULL possible_keys: UId key: NULL key: UId key_len: NULL key_len: 4 ref: NULL ref: func rows: 33789 rows: 2 Extra: Using where Extra: Using index ALTER TABLE h_p ADD INDEX (UId);
  • 30. mysql> explain SELECT UID, FUID, COUNT(*) AS Count FROM f GROUP BY UID, FUID ORDER BY Count DESC LIMIT 2000G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: f type: index possible_keys: NULL key: UID key_len: 8 ref: NULL rows: 2151326 Extra: Using index; Using temporary; Using filesort ALTER TABLE f DROP INDEX UID, ADD INDEX (UID,FUID)
  • 31. 4. The Art of Indexes Indexes can hurt performance
  • 32. Step 5 Offloading Master Load
  • 33. 5. Offloading Master Load • Identify statements for READ ONLY slave(s) • e.g. Long running batch statements Single point v scalable solution
  • 34. Step 6 Improving SQL
  • 35. 6. Improving SQL • Poor SQL Examples • ORDER BY RAND() • SELECT * • Lookup joins • ORDER BY The database is best for storing and retrieving data not logic
  • 36. Step 7 Storage Engines
  • 37. 7. Storage Engines • MyISAM is default • Table level locking • Concurrent SELECT statements • INSERT/UPDATE/DELETE blocked by long running SELECT • All SELECT’s blocked by INSERT/UPDATE/DELETE • Supports FULLTEXT
  • 38. 7. Storage Engines • InnoDB supports transactions • Row level locking with MVCC • Does not support FULLTEXT • Different memory management • Different system variables
  • 39. 7. Storage Engines • There are other storage engines • Memory • Archive • Blackhole • Third party
  • 40. 7. Storage Engines Using Multiple Engines • Different memory management • Different system variables • Different monitoring • Affects backup strategy
  • 41. 7. Storage Engines Action 1 • Configure InnoDB correctly • innodb_buffer_pool_size • innodb_log_file_size • innodb_flush_log_at_trx_commit
  • 42. 7. Storage Engines Action 2 • Converted the two primary tables • Users • Content Locking eliminated
  • 43. Step 8 Caching
  • 44. 8. Caching Action 1 • Memcache is your friend http://memcached.org/ - • Cache query results • Cache lookup data (eliminate joins) • Cache aggregated per user information • Caching Page Content • Top rated (e.g. for 5 minutes)
  • 45. 8. Caching Action 2 • MySQL has a Query Cache • Determine the real benefit • Turn on or off dynamically • SET GLOBAL query_cache_size = 1024*1024*32;
  • 46. 8. Caching Tip The best performance improvement for an SQL statement is to eliminate it.
  • 47. Step 9 Sharding
  • 48. 9. Sharding • Application level horizontal and vertical partitioning • Vertical Partitioning • Grouping like structures together (e.g. logging, forums) • Horizontal Partitioning • Affecting a smaller set of users (i.e. not 100%)
  • 49. 9. Sharding Action 1 • Separate Logging • Reduced replication load on primary server
  • 50. Step 10 Database Management
  • 51. 10. Database Management Database Maintenance • Adding indexes (e.g. ALTER) • OPTIMIZE TABLE • Archive/purging data (e.g DELETE) Blocking Operations
  • 52. 10. Database Maintenance Action 1 • Automate slave inclusion/exclusion • Ability to apply DB changes to slaves • Master still a problem
  • 53. 10. Database Maintenance Action 2 • Install Fail-Over Master Server • Slave + Master features • Master extra configuration • Scripts to switch slaves • Scripts to enable/disable Master(s) • Scripts to change application connection
  • 54. 10. Database Maintenance Higher Availability & Testing Disaster Recovery
  • 56. 11. Front End Improvements • Know your total website load time http://getfirebug.com/ - • How much time is actually database related? • Reduce HTML page size - 15% improvement • Remove full URL’s, inline css styles • Reduce/combine css & js files • Identify blocking elements (e.g. js)
  • 57. 11. Front End Improvements • Split static content to different ServerName • Spread static content over multiple ServerNames (e.g. 3) • Sprites - Combining lightweight images http://spriteme.org/ - • Cookie-less domain name for static content
  • 59. Before • Users experienced slow or unreliable load times • Management could observe, but no quantifiable details • Concern over load for increased growth • Release of some new features on hold
  • 60. Now • Users experienced consistent load times (~60ms) • Quantifiable and visible real-time results • Far greater load now supported (Clients + DB) • Better testability and verification for scaling • New features can be deployed
  • 61. Consulting Available Now http://ronaldbradford.com

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. Server (Ping, Uptime)\nDatabase Processlist (Total/Active/Idle/Locked)\nDatabase Replication (Up,Lag)\nWeb Server (Page Load x 3, Page Size, http processes)\n
  8. \n
  9. \n
  10. \n
  11. \n
  12. Traditional Existing Methods\n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. InnoDb, the PK value is stored\n
  29. \n
  30. \n
  31. Too many indexes\nDisk volume\nSlows DML\nIndex with unused columns\n
  32. \n
  33. \n
  34. \n
  35. Text fields\nnetwork bandwidth\ntemporary tables\nfilesort\n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. Site is effectively unavailable\n
  52. DB Changes\n* Add indexes\n* Change Storage Engines\n* Change Table structure\n\n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n