10x Performance Improvements - A Case Study

Ronald Bradford
Ronald BradfordPrincipal - Data architecture, performance and scalability for MySQL solutions.
10x Performance Improvements
                                 in 10 steps
                               A Case Study
                                     Ronald Bradford
                                http://ronaldbradford.com

                                   FOSDEM - 2010.02
Sunday, February 7, 2010
Application
              Typical Web 2.0 social media site (Europe based)

              • Users - Visitors, Free Members, Paying Members
              • Friends
              • User Content - Video, Pictures
              • Forums, Chat, Email

Sunday, February 7, 2010
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

Sunday, February 7, 2010
Step 1


                    Monitor, Monitor, Monitor



Sunday, February 7, 2010
1. Monitor, Monitor, Monitor
              • What’s happened?
              • What’s happening now?
              • What’s going to happen?

                           Past, Present, Future

Sunday, February 7, 2010
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/




Sunday, February 7, 2010
1. Monitor, Monitor, Monitor
                                                          Action 2
              Custom Dashboard

              • Most important - The state of NOW
              • Single Page Alerts - GREEN YELLOW   RED




Sunday, February 7, 2010
Screen print goes here




                                                    Dashboard
                                                     Example
Sunday, February 7, 2010
1. Monitor, Monitor, Monitor
                                                                Action 3
              Alerting Software

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



              • MONyog also has some DB specific alerts




Sunday, February 7, 2010
1. Monitor, Monitor, Monitor
                                             Action 4
              Application Metrics

              • Total page generation time




Sunday, February 7, 2010
Step 2


                             Identify problem SQL



Sunday, February 7, 2010
2. Identify Problem SQL
              Identify SQL Statements

              • Slow Query Log
              • Processlist
              • Binary Log
              • Status Statistics

Sunday, February 7, 2010
2. Identify Problem SQL
              Problems

              • Sampling
              • Granularity
              Solution

              • tcpdump + mk-query-digest

Sunday, February 7, 2010
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/




Sunday, February 7, 2010
# 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




Sunday, February 7, 2010
# 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
Sunday, February 7, 2010
2. Identify Problem SQL
                                                        Action 2
              • Wrappers to capture SQL
              • Re-run on single/multiple servers
                • e.g. Different slave configurations




Sunday, February 7, 2010
2. Identify Problem SQL
                                                                  Tip

              • Enable General Query Log in Development/Testing
              • Great for testing Batch Jobs




Sunday, February 7, 2010
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

Sunday, February 7, 2010
Step 3


                             Analyze problem SQL



Sunday, February 7, 2010
3. Analyze Problem SQL
              • Query Execution Plan (QEP)
                • EXPLAIN [EXTENDED] SELECT ...
              • Table/Index Structure
                • SHOW CREATE TABLE <tablename>
              • Table Statistics
                • SHOW TABLE STATUS <tablename>
Sunday, February 7, 2010
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


Sunday, February 7, 2010
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: 59
                      Extra:


Sunday, February 7, 2010
3. Analyze Problem SQL                       Tip

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

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

Sunday, February 7, 2010
Step 4


                               The Art of Indexes



Sunday, February 7, 2010
4. The Art of Indexes
              • Different Types
                • Column
                • Concatenated
                • Covering
                • Partial
              http://ronaldbradford.com/blog/understanding-different-mysql-index-implementations-2009-07-22/

Sunday, February 7, 2010
4. The Art of Indexes
                                      Action 1
              • EXPLAIN Output
                • Possible keys
                • Key used
                • Key length
                • Using Index

Sunday, February 7, 2010
4. The Art of Indexes                     Tip

              • Generally only 1 index used per table
              • Make column NOT NULL when possible
              • Statistics affects indexes
              • Storage engines affect operations


Sunday, February 7, 2010
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);


Sunday, February 7, 2010
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)

Sunday, February 7, 2010
4. The Art of Indexes



                           Indexes can hurt performance


Sunday, February 7, 2010
Step 5


                            Offloading Master Load



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



                     Single point v scalable solution

Sunday, February 7, 2010
Step 6


                                    Improving SQL



Sunday, February 7, 2010
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
Sunday, February 7, 2010
Step 7


                                Storage Engines



Sunday, February 7, 2010
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
Sunday, February 7, 2010
7. Storage Engines
              • InnoDB supports transactions
              • Row level locking with MVCC
              • Does not support FULLTEXT
              • Different memory management
              • Different system variables

Sunday, February 7, 2010
7. Storage Engines
              • There are other storage engines
                • Memory
                • Archive
                • Blackhole
                • Third party

Sunday, February 7, 2010
7. Storage Engines
              Using Multiple Engines

              • Different memory management
              • Different system variables
              • Different monitoring
              • Affects backup strategy

Sunday, February 7, 2010
7. Storage Engines
                                                   Action 1
              • Configure InnoDB correctly
                • innodb_buffer_pool_size
                • innodb_log_file_size
                • innodb_flush_log_at_trx_commit



Sunday, February 7, 2010
7. Storage Engines
                                                   Action 2
              • Converted the two primary tables
                 • Users
                 • Content

                            Locking eliminated

Sunday, February 7, 2010
Step 8


                                    Caching



Sunday, February 7, 2010
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)
Sunday, February 7, 2010
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;




Sunday, February 7, 2010
8. Caching                                   Tip




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


Sunday, February 7, 2010
Step 9


                                    Sharding



Sunday, February 7, 2010
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%)

Sunday, February 7, 2010
9. Sharding
                                                                Action 1
              • Separate Logging
                 • Reduced replication load on primary server




Sunday, February 7, 2010
Step 10


                            Database Management



Sunday, February 7, 2010
10. Database Management
              Database Maintenance

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

                           Blocking Operations
Sunday, February 7, 2010
10. Database Maintenance
                                                        Action 1
              • Automate slave inclusion/exclusion
              • Ability to apply DB changes to slaves
              • Master still a problem




Sunday, February 7, 2010
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
Sunday, February 7, 2010
10. Database Maintenance

                              Higher Availability
                                      &
                           Testing Disaster Recovery

Sunday, February 7, 2010
Bonus




                           Front End Improvements



Sunday, February 7, 2010
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)
Sunday, February 7, 2010
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


Sunday, February 7, 2010
Conclusion



Sunday, February 7, 2010
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


Sunday, February 7, 2010
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

Sunday, February 7, 2010
Consulting Available Now


                           http://ronaldbradford.com



Sunday, February 7, 2010
1 of 61

Recommended

10x Performance Improvements by
10x Performance Improvements10x Performance Improvements
10x Performance ImprovementsRonald Bradford
3.9K views61 slides
Capturing, Analyzing, and Optimizing your SQL by
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLPadraig O'Sullivan
3.9K views102 slides
Summary tables with flexviews by
Summary tables with flexviewsSummary tables with flexviews
Summary tables with flexviewsJustin Swanhart
6.1K views51 slides
MySQL JSON Functions by
MySQL JSON FunctionsMySQL JSON Functions
MySQL JSON FunctionsSveta Smirnova
18.3K views58 slides
Mysql 56-experiences-bugs-solutions-50mins by
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsValeriy Kravchuk
3.3K views58 slides
MySQL 5.7 + JSON by
MySQL 5.7 + JSONMySQL 5.7 + JSON
MySQL 5.7 + JSONMorgan Tocker
13.6K views40 slides

More Related Content

What's hot

My sql tutorial-oscon-2012 by
My sql tutorial-oscon-2012My sql tutorial-oscon-2012
My sql tutorial-oscon-2012John David Duncan
1K views142 slides
Optimizing MySQL by
Optimizing MySQLOptimizing MySQL
Optimizing MySQLMorgan Tocker
2.4K views12 slides
MySQL Performance schema missing_manual_flossuk by
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukValeriy Kravchuk
4.2K views48 slides
MySQL Replication Update - DEbconf 2020 presentation by
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationDave Stokes
283 views45 slides
Performance schema in_my_sql_5.6_pluk2013 by
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Valeriy Kravchuk
6.2K views49 slides
UKOUG 2011: Practical MySQL Tuning by
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningFromDual GmbH
1.4K views33 slides

What's hot(20)

MySQL Performance schema missing_manual_flossuk by Valeriy Kravchuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk4.2K views
MySQL Replication Update - DEbconf 2020 presentation by Dave Stokes
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentation
Dave Stokes283 views
Performance schema in_my_sql_5.6_pluk2013 by Valeriy Kravchuk
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
Valeriy Kravchuk6.2K views
UKOUG 2011: Practical MySQL Tuning by FromDual GmbH
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
FromDual GmbH1.4K views
Perf Tuning Best Practices by guest01bbdd
Perf Tuning Best PracticesPerf Tuning Best Practices
Perf Tuning Best Practices
guest01bbdd967 views
Performance Schema for MySQL Troubleshooting by Sveta Smirnova
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova746 views
Mini Session - Using GDB for Profiling by Enkitec
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for Profiling
Enkitec904 views
Troubleshooting MySQL Performance by Sveta Smirnova
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
Sveta Smirnova853 views
Flexviews materialized views for my sql by Justin Swanhart
Flexviews materialized views for my sqlFlexviews materialized views for my sql
Flexviews materialized views for my sql
Justin Swanhart4.6K views
MySQL 8.0 Operational Changes by Dave Stokes
MySQL 8.0 Operational ChangesMySQL 8.0 Operational Changes
MySQL 8.0 Operational Changes
Dave Stokes158 views
In Search of Plan Stability - Part 1 by Enkitec
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
Enkitec1.1K views
Developing Information Schema Plugins by Mark Leith
Developing Information Schema PluginsDeveloping Information Schema Plugins
Developing Information Schema Plugins
Mark Leith4.1K views
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit by Dave Stokes
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Dave Stokes182 views
Second Step to the NoSQL Side: MySQL JSON Functions by Sveta Smirnova
Second Step to the NoSQL Side: MySQL JSON FunctionsSecond Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON Functions
Sveta Smirnova1.1K views
Highload Perf Tuning by HighLoad2009
Highload Perf TuningHighload Perf Tuning
Highload Perf Tuning
HighLoad20091.3K views
Open Source World June '21 -- JSON Within a Relational Database by Dave Stokes
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational Database
Dave Stokes128 views
MySQL8.0.22リリースノートをみてわいわい言う勉強会 by sakaik
MySQL8.0.22リリースノートをみてわいわい言う勉強会 MySQL8.0.22リリースノートをみてわいわい言う勉強会
MySQL8.0.22リリースノートをみてわいわい言う勉強会
sakaik198 views

Viewers also liked

Using Apache Spark and MySQL for Data Analysis by
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisSveta Smirnova
2.8K views27 slides
Mysql For Developers by
Mysql For DevelopersMysql For Developers
Mysql For DevelopersCarol McDonald
17.9K views77 slides
Capturing, Analyzing and Optimizing MySQL by
Capturing, Analyzing and Optimizing MySQLCapturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLRonald Bradford
5K views102 slides
淘宝数据库架构演进历程 by
淘宝数据库架构演进历程淘宝数据库架构演进历程
淘宝数据库架构演进历程zhaolinjnu
5K views42 slides
Load Data Fast! by
Load Data Fast!Load Data Fast!
Load Data Fast!Karwin Software Solutions LLC
10.2K views53 slides
SQL Outer Joins for Fun and Profit by
SQL Outer Joins for Fun and ProfitSQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and ProfitKarwin Software Solutions LLC
18.8K views43 slides

Viewers also liked(20)

Using Apache Spark and MySQL for Data Analysis by Sveta Smirnova
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data Analysis
Sveta Smirnova2.8K views
Capturing, Analyzing and Optimizing MySQL by Ronald Bradford
Capturing, Analyzing and Optimizing MySQLCapturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQL
Ronald Bradford5K views
淘宝数据库架构演进历程 by zhaolinjnu
淘宝数据库架构演进历程淘宝数据库架构演进历程
淘宝数据库架构演进历程
zhaolinjnu5K views
MySQL High Availability and Disaster Recovery with Continuent, a VMware company by Continuent
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyMySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
Continuent1.8K views
Мониторинг и отладка MySQL: максимум информации при минимальных потерях by Sveta Smirnova
Мониторинг и отладка MySQL: максимум информации при минимальных потеряхМониторинг и отладка MySQL: максимум информации при минимальных потерях
Мониторинг и отладка MySQL: максимум информации при минимальных потерях
Sveta Smirnova871 views
MySQL InnoDB 源码实现分析(一) by frogd
MySQL InnoDB 源码实现分析(一)MySQL InnoDB 源码实现分析(一)
MySQL InnoDB 源码实现分析(一)
frogd7.6K views
MySQL High Availability Solutions by Lenz Grimmer
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability Solutions
Lenz Grimmer7.2K views
Mysql参数-GDB by zhaolinjnu
Mysql参数-GDBMysql参数-GDB
Mysql参数-GDB
zhaolinjnu898 views
MySQL InnoDB Cluster - A complete High Availability solution for MySQL by Olivier DASINI
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
Olivier DASINI7.4K views
MySQL High Availability with Group Replication by Nuno Carvalho
MySQL High Availability with Group ReplicationMySQL High Availability with Group Replication
MySQL High Availability with Group Replication
Nuno Carvalho3.1K views
MySQL Replication Performance Tuning for Fun and Profit! by Vitor Oliveira
MySQL Replication Performance Tuning for Fun and Profit!MySQL Replication Performance Tuning for Fun and Profit!
MySQL Replication Performance Tuning for Fun and Profit!
Vitor Oliveira2.9K views
MySQL Group Replication - HandsOn Tutorial by Kenny Gryp
MySQL Group Replication - HandsOn TutorialMySQL Group Replication - HandsOn Tutorial
MySQL Group Replication - HandsOn Tutorial
Kenny Gryp2.2K views
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ... by Frederic Descamps
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
Frederic Descamps2.4K views
The nightmare of locking, blocking and isolation levels! by Boris Hristov
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
Boris Hristov1.2K views
Mastering InnoDB Diagnostics by guest8212a5
Mastering InnoDB DiagnosticsMastering InnoDB Diagnostics
Mastering InnoDB Diagnostics
guest8212a53.4K views
MySQL aio by zhaolinjnu
MySQL aioMySQL aio
MySQL aio
zhaolinjnu1.8K views
Mysql high availability and scalability by yin gong
Mysql high availability and scalabilityMysql high availability and scalability
Mysql high availability and scalability
yin gong1.8K views

Similar to 10x Performance Improvements - A Case Study

10x improvement-mysql-100419105218-phpapp02 by
10x improvement-mysql-100419105218-phpapp0210x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp02promethius
495 views61 slides
AtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas Knecht by
AtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas KnechtAtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas Knecht
AtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas KnechtAtlassian
1.3K views28 slides
Noit ocon-2010 by
Noit ocon-2010Noit ocon-2010
Noit ocon-2010Theo Schlossnagle
1.7K views12 slides
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015 by
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015Jeremy Brown
1.6K views55 slides
MySQL DW Breakfast by
MySQL DW BreakfastMySQL DW Breakfast
MySQL DW BreakfastIvan Zoratti
1.5K views28 slides
What you wanted to know about MySQL, but could not find using inernal instrum... by
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
2.2K views70 slides

Similar to 10x Performance Improvements - A Case Study(20)

10x improvement-mysql-100419105218-phpapp02 by promethius
10x improvement-mysql-100419105218-phpapp0210x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp02
promethius495 views
AtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas Knecht by Atlassian
AtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas KnechtAtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas Knecht
AtlasCamp 2010: Implementing a custom JIRA UI using plugins 2.0 - Andreas Knecht
Atlassian1.3K views
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015 by Jeremy Brown
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015
Jeremy Brown1.6K views
MySQL DW Breakfast by Ivan Zoratti
MySQL DW BreakfastMySQL DW Breakfast
MySQL DW Breakfast
Ivan Zoratti1.5K views
What you wanted to know about MySQL, but could not find using inernal instrum... by Sveta Smirnova
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 Smirnova2.2K views
State of the Framework Address: Recent Developments in the Metasploit Framework by egypt
State of the Framework Address: Recent Developments in the Metasploit FrameworkState of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit Framework
egypt609 views
Dev and Ops Collaboration and Awareness at Etsy and Flickr by John Allspaw
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and Flickr
John Allspaw35.6K views
WordCamp Fukuoka 2010 by Naoko Takano
WordCamp Fukuoka 2010WordCamp Fukuoka 2010
WordCamp Fukuoka 2010
Naoko Takano7.9K views
Lecture 10 slides (february 4, 2010) by Bruce Lee
Lecture 10 slides (february 4, 2010)Lecture 10 slides (february 4, 2010)
Lecture 10 slides (february 4, 2010)
Bruce Lee421 views
State of jQuery June 2013 - Portland by dmethvin
State of jQuery June 2013 - PortlandState of jQuery June 2013 - Portland
State of jQuery June 2013 - Portland
dmethvin6.4K views
jQuery Conference 2012 keynote by dmethvin
jQuery Conference 2012 keynotejQuery Conference 2012 keynote
jQuery Conference 2012 keynote
dmethvin20.4K views
Application Performance Troubleshooting 1x1 - Part 2 - Noch mehr Schweine und... by rschuppe
Application Performance Troubleshooting 1x1 - Part 2 - Noch mehr Schweine und...Application Performance Troubleshooting 1x1 - Part 2 - Noch mehr Schweine und...
Application Performance Troubleshooting 1x1 - Part 2 - Noch mehr Schweine und...
rschuppe647 views
Innodb plugin in MySQL 5.1 by Giuseppe Maxia
Innodb plugin in MySQL 5.1Innodb plugin in MySQL 5.1
Innodb plugin in MySQL 5.1
Giuseppe Maxia1.2K views
Kubernetes at Telekom Austria Group by Oliver Moser
Kubernetes at Telekom Austria Group Kubernetes at Telekom Austria Group
Kubernetes at Telekom Austria Group
Oliver Moser163 views
Red Dirt Ruby Conference by John Woodell
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby Conference
John Woodell1.1K views
Introducing OWASP OWTF Workshop BruCon 2012 by Abraham Aranguren
Introducing OWASP OWTF Workshop BruCon 2012Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012
Abraham Aranguren6.4K views

More from Ronald Bradford

Successful Scalability Principles - Part 1 by
Successful Scalability Principles - Part 1Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Ronald Bradford
9.8K views94 slides
MySQL Backup and Recovery Essentials by
MySQL Backup and Recovery EssentialsMySQL Backup and Recovery Essentials
MySQL Backup and Recovery EssentialsRonald Bradford
11.7K views50 slides
The History and Future of the MySQL ecosystem by
The History and Future of the MySQL ecosystemThe History and Future of the MySQL ecosystem
The History and Future of the MySQL ecosystemRonald Bradford
9.1K views60 slides
Lessons Learned Managing Large AWS Environments by
Lessons Learned Managing Large AWS EnvironmentsLessons Learned Managing Large AWS Environments
Lessons Learned Managing Large AWS EnvironmentsRonald Bradford
8K views74 slides
Monitoring your technology stack with New Relic by
Monitoring your technology stack with New RelicMonitoring your technology stack with New Relic
Monitoring your technology stack with New RelicRonald Bradford
15K views100 slides
MySQL Best Practices - OTN by
MySQL Best Practices - OTNMySQL Best Practices - OTN
MySQL Best Practices - OTNRonald Bradford
2.4K views100 slides

More from Ronald Bradford(20)

Successful Scalability Principles - Part 1 by Ronald Bradford
Successful Scalability Principles - Part 1Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1
Ronald Bradford9.8K views
MySQL Backup and Recovery Essentials by Ronald Bradford
MySQL Backup and Recovery EssentialsMySQL Backup and Recovery Essentials
MySQL Backup and Recovery Essentials
Ronald Bradford11.7K views
The History and Future of the MySQL ecosystem by Ronald Bradford
The History and Future of the MySQL ecosystemThe History and Future of the MySQL ecosystem
The History and Future of the MySQL ecosystem
Ronald Bradford9.1K views
Lessons Learned Managing Large AWS Environments by Ronald Bradford
Lessons Learned Managing Large AWS EnvironmentsLessons Learned Managing Large AWS Environments
Lessons Learned Managing Large AWS Environments
Ronald Bradford8K views
Monitoring your technology stack with New Relic by Ronald Bradford
Monitoring your technology stack with New RelicMonitoring your technology stack with New Relic
Monitoring your technology stack with New Relic
Ronald Bradford15K views
MySQL Scalability Mistakes - OTN by Ronald Bradford
MySQL Scalability Mistakes - OTNMySQL Scalability Mistakes - OTN
MySQL Scalability Mistakes - OTN
Ronald Bradford9.2K views
My SQL Idiosyncrasies That Bite OTN by Ronald Bradford
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
Ronald Bradford2.9K views
MySQL Best Practices - OTN LAD Tour by Ronald Bradford
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
Ronald Bradford9.5K views
MySQL Idiosyncrasies That Bite 2010.07 by Ronald Bradford
MySQL Idiosyncrasies That Bite 2010.07MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07
Ronald Bradford2.1K views
MySQL Idiosyncrasies That Bite by Ronald Bradford
MySQL Idiosyncrasies That BiteMySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That Bite
Ronald Bradford7.6K views
LIFTOFF - MySQLCamp for the Oracle DBA by Ronald Bradford
LIFTOFF - MySQLCamp for the Oracle DBALIFTOFF - MySQLCamp for the Oracle DBA
LIFTOFF - MySQLCamp for the Oracle DBA
Ronald Bradford1.5K views
IGNITION - MySQLCamp for the Oracle DBA by Ronald Bradford
IGNITION - MySQLCamp for the Oracle DBAIGNITION - MySQLCamp for the Oracle DBA
IGNITION - MySQLCamp for the Oracle DBA
Ronald Bradford1.7K views
Dolphins Now And Beyond - FOSDEM 2010 by Ronald Bradford
Dolphins Now And Beyond - FOSDEM 2010Dolphins Now And Beyond - FOSDEM 2010
Dolphins Now And Beyond - FOSDEM 2010
Ronald Bradford2.2K views
Drizzle - Status, Principles and Ecosystem by Ronald Bradford
Drizzle - Status, Principles and EcosystemDrizzle - Status, Principles and Ecosystem
Drizzle - Status, Principles and Ecosystem
Ronald Bradford1K views
MySQL for the Oracle DBA - Object Management by Ronald Bradford
MySQL for the Oracle DBA - Object ManagementMySQL for the Oracle DBA - Object Management
MySQL for the Oracle DBA - Object Management
Ronald Bradford1.9K views
Know Your Competitor - Oracle 10g Express Edition by Ronald Bradford
Know Your Competitor - Oracle 10g Express EditionKnow Your Competitor - Oracle 10g Express Edition
Know Your Competitor - Oracle 10g Express Edition
Ronald Bradford3.5K views

Recently uploaded

Piloting & Scaling Successfully With Microsoft Viva by
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
12 views160 slides
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Safe Software
280 views86 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
41 views73 slides
6g - REPORT.pdf by
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdfLiveplex
10 views23 slides
Vertical User Stories by
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
14 views16 slides
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 slide

Recently uploaded(20)

Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software280 views
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex10 views
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely25 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
Powerful Google developer tools for immediate impact! (2023-24) by wesley chun
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)
wesley chun10 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab21 views

10x Performance Improvements - A Case Study

  • 1. 10x Performance Improvements in 10 steps A Case Study Ronald Bradford http://ronaldbradford.com FOSDEM - 2010.02 Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 4. Step 1 Monitor, Monitor, Monitor Sunday, February 7, 2010
  • 5. 1. Monitor, Monitor, Monitor • What’s happened? • What’s happening now? • What’s going to happen? Past, Present, Future Sunday, February 7, 2010
  • 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/ Sunday, February 7, 2010
  • 7. 1. Monitor, Monitor, Monitor Action 2 Custom Dashboard • Most important - The state of NOW • Single Page Alerts - GREEN YELLOW RED Sunday, February 7, 2010
  • 8. Screen print goes here Dashboard Example Sunday, February 7, 2010
  • 9. 1. Monitor, Monitor, Monitor Action 3 Alerting Software • Installation of Nagios http://www.nagios.org/ - • MONyog also has some DB specific alerts Sunday, February 7, 2010
  • 10. 1. Monitor, Monitor, Monitor Action 4 Application Metrics • Total page generation time Sunday, February 7, 2010
  • 11. Step 2 Identify problem SQL Sunday, February 7, 2010
  • 12. 2. Identify Problem SQL Identify SQL Statements • Slow Query Log • Processlist • Binary Log • Status Statistics Sunday, February 7, 2010
  • 13. 2. Identify Problem SQL Problems • Sampling • Granularity Solution • tcpdump + mk-query-digest Sunday, February 7, 2010
  • 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/ Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 17. 2. Identify Problem SQL Action 2 • Wrappers to capture SQL • Re-run on single/multiple servers • e.g. Different slave configurations Sunday, February 7, 2010
  • 18. 2. Identify Problem SQL Tip • Enable General Query Log in Development/Testing • Great for testing Batch Jobs Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 20. Step 3 Analyze problem SQL Sunday, February 7, 2010
  • 21. 3. Analyze Problem SQL • Query Execution Plan (QEP) • EXPLAIN [EXTENDED] SELECT ... • Table/Index Structure • SHOW CREATE TABLE <tablename> • Table Statistics • SHOW TABLE STATUS <tablename> Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 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: 59 Extra: Sunday, February 7, 2010
  • 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 */ .... Sunday, February 7, 2010
  • 25. Step 4 The Art of Indexes Sunday, February 7, 2010
  • 26. 4. The Art of Indexes • Different Types • Column • Concatenated • Covering • Partial http://ronaldbradford.com/blog/understanding-different-mysql-index-implementations-2009-07-22/ Sunday, February 7, 2010
  • 27. 4. The Art of Indexes Action 1 • EXPLAIN Output • Possible keys • Key used • Key length • Using Index Sunday, February 7, 2010
  • 28. 4. The Art of Indexes Tip • Generally only 1 index used per table • Make column NOT NULL when possible • Statistics affects indexes • Storage engines affect operations Sunday, February 7, 2010
  • 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); Sunday, February 7, 2010
  • 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) Sunday, February 7, 2010
  • 31. 4. The Art of Indexes Indexes can hurt performance Sunday, February 7, 2010
  • 32. Step 5 Offloading Master Load Sunday, February 7, 2010
  • 33. 5. Offloading Master Load • Identify statements for READ ONLY slave(s) • e.g. Long running batch statements Single point v scalable solution Sunday, February 7, 2010
  • 34. Step 6 Improving SQL Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 36. Step 7 Storage Engines Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 38. 7. Storage Engines • InnoDB supports transactions • Row level locking with MVCC • Does not support FULLTEXT • Different memory management • Different system variables Sunday, February 7, 2010
  • 39. 7. Storage Engines • There are other storage engines • Memory • Archive • Blackhole • Third party Sunday, February 7, 2010
  • 40. 7. Storage Engines Using Multiple Engines • Different memory management • Different system variables • Different monitoring • Affects backup strategy Sunday, February 7, 2010
  • 41. 7. Storage Engines Action 1 • Configure InnoDB correctly • innodb_buffer_pool_size • innodb_log_file_size • innodb_flush_log_at_trx_commit Sunday, February 7, 2010
  • 42. 7. Storage Engines Action 2 • Converted the two primary tables • Users • Content Locking eliminated Sunday, February 7, 2010
  • 43. Step 8 Caching Sunday, February 7, 2010
  • 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) Sunday, February 7, 2010
  • 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; Sunday, February 7, 2010
  • 46. 8. Caching Tip The best performance improvement for an SQL statement is to eliminate it. Sunday, February 7, 2010
  • 47. Step 9 Sharding Sunday, February 7, 2010
  • 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%) Sunday, February 7, 2010
  • 49. 9. Sharding Action 1 • Separate Logging • Reduced replication load on primary server Sunday, February 7, 2010
  • 50. Step 10 Database Management Sunday, February 7, 2010
  • 51. 10. Database Management Database Maintenance • Adding indexes (e.g. ALTER) • OPTIMIZE TABLE • Archive/purging data (e.g DELETE) Blocking Operations Sunday, February 7, 2010
  • 52. 10. Database Maintenance Action 1 • Automate slave inclusion/exclusion • Ability to apply DB changes to slaves • Master still a problem Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 54. 10. Database Maintenance Higher Availability & Testing Disaster Recovery Sunday, February 7, 2010
  • 55. Bonus Front End Improvements Sunday, February 7, 2010
  • 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) Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 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 Sunday, February 7, 2010
  • 61. Consulting Available Now http://ronaldbradford.com Sunday, February 7, 2010