SlideShare a Scribd company logo
1 of 20
Download to read offline
Two database findings
        Tobias Schmidt
          @dagrobie
      github.com/grobie




                          Lightning talk @ Railsberry, Kraków - 19 April 2012
Know your usage patterns
pt-query-digest

# Profile
# Rank Query ID             Response time Calls R/Call Apdx V/M    Item
# ==== ==================   ============== ===== ====== ==== ===== =========
#    1 0x5E796D5A4A7D1CA9   449.4200 40.6% 4763 0.0944 0.99 1.32 ADMIN STATISTICS
#    2 0xDEA06A23CC92009D   101.0927 9.1%    352 0.2872 0.95 1.00 SELECT users
#    3 0xE320654019E45018    99.4647 9.0%    648 0.1535 0.98 1.15 SELECT users
#    4 0x813031B8BBC3B329    28.6658 2.6%    192 0.1493 0.99 16.10 COMMIT
#    5 0xB7CFCFF53D7D16A7    25.2505 2.3%    278 0.0908 0.99 1.90 SELECT oauth2...
# ...
pt-query-digest

# Profile
# Rank Query ID             Response time Calls R/Call Apdx V/M    Item
# ==== ==================   ============== ===== ====== ==== ===== =========
#    1 0x5E796D5A4A7D1CA9   449.4200 40.6% 4763 0.0944 0.99 1.32 ADMIN STATISTICS
#    2 0xDEA06A23CC92009D   101.0927 9.1%    352 0.2872 0.95 1.00 SELECT users
#    3 0xE320654019E45018    99.4647 9.0%    648 0.1535 0.98 1.15 SELECT users
#    4 0x813031B8BBC3B329    28.6658 2.6%    192 0.1493 0.99 16.10 COMMIT
#    5 0xB7CFCFF53D7D16A7    25.2505 2.3%    278 0.0908 0.99 1.90 SELECT oauth2...
# ...



              40% of the time for
             “ADMIN STATISTICS”
COM_STATISTICS

Asks the MySQL server to compile a text
message with some server statistics (uptime,
queries per second, etc.).This packet can be sent
with mysqladmin status. No arguments.

$ mysqladmin status
Uptime: 41729399 Threads: 892 Questions: ... Slow queries: ... ...



                      http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#COM_STATISTICS
ActiveRecord
# active_record/connection_adapters/mysql_adapter.rb
class ActiveRecord::ConnectionAdapters::MysqlAdapter
  def active?
    @connection.stat

    if @connection.respond_to?(:errno)
      @connection.errno.zero?
    else
      true
    end
  end
end
ActiveRecord
# ar/connection_adapters/abstract_adapter.rb
class AR::ConnectionAdapters::AbstractAdapter
  # Checks whether the connection to the database is
  # still active (i.e. not stale). This is done under
  # the hood by calling <tt>active?</tt>.
  # If the connection is no longer active, then this
  # method will reconnect to the database.
  def verify!(*ignored)
    reconnect! unless active?
  end
end
ActiveRecord

# action_controller/dispatcher.rb
class ActionController::Dispatcher
  def self.cleanup_application
    # ...

    ActiveRecord::Base.clear_reloadable_connections!
  end
end
Optimistic health check

# config/initializers/active_record_extensions.rb
class ActiveRecord::ConnectionAdapters::MysqlAdapter
  def active?
    true
  end
end




 additional info: http://www.mysqlperformanceblog.com/2010/05/05/checking-for-a-live-database-connection-considered-harmful/
Know your tools
Lhm
       Large hadron migrator
github.com/soundcloud/large-hadron-migrator
Lhm

• Online schema change tool
• migrate tables with (almost) no downtime
• Replication safe
• Ruby 1.8 / 1.9, ActiveRecord 2.3 / 3.x and
  mysql / mysql2 compatible
Lhm


users
Lhm - prepare

            create temporary table


users            lhmn_users
Lhm - alter

require "lhm"
                                                         alter table
class AddRailsberryToUsers < ActiveRecord::Migration
  def up
    Lhm.change_table :users do |u|
      u.add_column :railsberry, "BOOLEAN DEFAULT true"   lhmn_users
      u.add_index :railsberry
    end
  end
end
Lhm - entangle


        create trigger
users                    lhmn_users
         after insert
         after update
         after delete
Lhm - copy


          copy all rows
users                     lhmn_users
Lhm - rename


             rename
lhma_users            users
Know your usage patterns
    Know your tools
soundcloud.com/jobs

More Related Content

Viewers also liked (10)

Resume 09 3
Resume 09 3Resume 09 3
Resume 09 3
 
Conectivismo
ConectivismoConectivismo
Conectivismo
 
High Frequency Words 1
High Frequency Words 1High Frequency Words 1
High Frequency Words 1
 
Greece bilateral report
Greece bilateral reportGreece bilateral report
Greece bilateral report
 
Shapes presentation
Shapes presentationShapes presentation
Shapes presentation
 
Cz pl meeting
Cz  pl meetingCz  pl meeting
Cz pl meeting
 
Sistemas Operativos
Sistemas OperativosSistemas Operativos
Sistemas Operativos
 
11704
1170411704
11704
 
Algo grande
Algo grandeAlgo grande
Algo grande
 
البورصة المصرية | شركة عربية اون لاين | التحليل الفني | 8-2-2017 | بورصة | ...
البورصة المصرية |  شركة عربية اون لاين | التحليل الفني |  8-2-2017 | بورصة | ...البورصة المصرية |  شركة عربية اون لاين | التحليل الفني |  8-2-2017 | بورصة | ...
البورصة المصرية | شركة عربية اون لاين | التحليل الفني | 8-2-2017 | بورصة | ...
 

Similar to Two database findings

Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails Mohit Jain
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
Palestra "Do PHP ao Rails" - FOCAI
Palestra "Do PHP ao Rails" - FOCAIPalestra "Do PHP ao Rails" - FOCAI
Palestra "Do PHP ao Rails" - FOCAIAlmir Mendes
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deploymentsOdoo
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2rowensCap
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Plataformatec
 
Rooted 2010 ppp
Rooted 2010 pppRooted 2010 ppp
Rooted 2010 pppnoc_313
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperfNew Relic
 
MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...
MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...
MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...MITRE - ATT&CKcon
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiMuhammed Thanveer M
 

Similar to Two database findings (20)

Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
Palestra "Do PHP ao Rails" - FOCAI
Palestra "Do PHP ao Rails" - FOCAIPalestra "Do PHP ao Rails" - FOCAI
Palestra "Do PHP ao Rails" - FOCAI
 
Rails3 way
Rails3 wayRails3 way
Rails3 way
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 
Ruby meetup-dry
Ruby meetup-dryRuby meetup-dry
Ruby meetup-dry
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
Intro to Rails 4
Intro to Rails 4Intro to Rails 4
Intro to Rails 4
 
Rooted 2010 ppp
Rooted 2010 pppRooted 2010 ppp
Rooted 2010 ppp
 
Undrop for InnoDB
Undrop for InnoDBUndrop for InnoDB
Undrop for InnoDB
 
Wikilims Road4
Wikilims Road4Wikilims Road4
Wikilims Road4
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 
MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...
MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...
MITRE ATT&CKcon 2018: From Technique to Detection, Paul Ewing and Ross Wolf, ...
 
Pl sql using_xml
Pl sql using_xmlPl sql using_xml
Pl sql using_xml
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Sherlock holmes for dba’s
Sherlock holmes for dba’sSherlock holmes for dba’s
Sherlock holmes for dba’s
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayi
 

More from Tobias Schmidt

Monitoring microservices with Prometheus
Monitoring microservices with PrometheusMonitoring microservices with Prometheus
Monitoring microservices with PrometheusTobias Schmidt
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusTobias Schmidt
 
The history of Prometheus at SoundCloud
The history of Prometheus at SoundCloudThe history of Prometheus at SoundCloud
The history of Prometheus at SoundCloudTobias Schmidt
 
Efficient monitoring and alerting
Efficient monitoring and alertingEfficient monitoring and alerting
Efficient monitoring and alertingTobias Schmidt
 
Moving to Kubernetes - Tales from SoundCloud
Moving to Kubernetes - Tales from SoundCloudMoving to Kubernetes - Tales from SoundCloud
Moving to Kubernetes - Tales from SoundCloudTobias Schmidt
 
Prometheus loves Grafana
Prometheus loves GrafanaPrometheus loves Grafana
Prometheus loves GrafanaTobias Schmidt
 
16 months @ SoundCloud
16 months @ SoundCloud16 months @ SoundCloud
16 months @ SoundCloudTobias Schmidt
 

More from Tobias Schmidt (7)

Monitoring microservices with Prometheus
Monitoring microservices with PrometheusMonitoring microservices with Prometheus
Monitoring microservices with Prometheus
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with Prometheus
 
The history of Prometheus at SoundCloud
The history of Prometheus at SoundCloudThe history of Prometheus at SoundCloud
The history of Prometheus at SoundCloud
 
Efficient monitoring and alerting
Efficient monitoring and alertingEfficient monitoring and alerting
Efficient monitoring and alerting
 
Moving to Kubernetes - Tales from SoundCloud
Moving to Kubernetes - Tales from SoundCloudMoving to Kubernetes - Tales from SoundCloud
Moving to Kubernetes - Tales from SoundCloud
 
Prometheus loves Grafana
Prometheus loves GrafanaPrometheus loves Grafana
Prometheus loves Grafana
 
16 months @ SoundCloud
16 months @ SoundCloud16 months @ SoundCloud
16 months @ SoundCloud
 

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Two database findings

  • 1. Two database findings Tobias Schmidt @dagrobie github.com/grobie Lightning talk @ Railsberry, Kraków - 19 April 2012
  • 2. Know your usage patterns
  • 3. pt-query-digest # Profile # Rank Query ID Response time Calls R/Call Apdx V/M Item # ==== ================== ============== ===== ====== ==== ===== ========= # 1 0x5E796D5A4A7D1CA9 449.4200 40.6% 4763 0.0944 0.99 1.32 ADMIN STATISTICS # 2 0xDEA06A23CC92009D 101.0927 9.1% 352 0.2872 0.95 1.00 SELECT users # 3 0xE320654019E45018 99.4647 9.0% 648 0.1535 0.98 1.15 SELECT users # 4 0x813031B8BBC3B329 28.6658 2.6% 192 0.1493 0.99 16.10 COMMIT # 5 0xB7CFCFF53D7D16A7 25.2505 2.3% 278 0.0908 0.99 1.90 SELECT oauth2... # ...
  • 4. pt-query-digest # Profile # Rank Query ID Response time Calls R/Call Apdx V/M Item # ==== ================== ============== ===== ====== ==== ===== ========= # 1 0x5E796D5A4A7D1CA9 449.4200 40.6% 4763 0.0944 0.99 1.32 ADMIN STATISTICS # 2 0xDEA06A23CC92009D 101.0927 9.1% 352 0.2872 0.95 1.00 SELECT users # 3 0xE320654019E45018 99.4647 9.0% 648 0.1535 0.98 1.15 SELECT users # 4 0x813031B8BBC3B329 28.6658 2.6% 192 0.1493 0.99 16.10 COMMIT # 5 0xB7CFCFF53D7D16A7 25.2505 2.3% 278 0.0908 0.99 1.90 SELECT oauth2... # ... 40% of the time for “ADMIN STATISTICS”
  • 5. COM_STATISTICS Asks the MySQL server to compile a text message with some server statistics (uptime, queries per second, etc.).This packet can be sent with mysqladmin status. No arguments. $ mysqladmin status Uptime: 41729399 Threads: 892 Questions: ... Slow queries: ... ... http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#COM_STATISTICS
  • 6. ActiveRecord # active_record/connection_adapters/mysql_adapter.rb class ActiveRecord::ConnectionAdapters::MysqlAdapter def active? @connection.stat if @connection.respond_to?(:errno) @connection.errno.zero? else true end end end
  • 7. ActiveRecord # ar/connection_adapters/abstract_adapter.rb class AR::ConnectionAdapters::AbstractAdapter # Checks whether the connection to the database is # still active (i.e. not stale). This is done under # the hood by calling <tt>active?</tt>. # If the connection is no longer active, then this # method will reconnect to the database. def verify!(*ignored) reconnect! unless active? end end
  • 8. ActiveRecord # action_controller/dispatcher.rb class ActionController::Dispatcher def self.cleanup_application # ... ActiveRecord::Base.clear_reloadable_connections! end end
  • 9. Optimistic health check # config/initializers/active_record_extensions.rb class ActiveRecord::ConnectionAdapters::MysqlAdapter def active? true end end additional info: http://www.mysqlperformanceblog.com/2010/05/05/checking-for-a-live-database-connection-considered-harmful/
  • 11. Lhm Large hadron migrator github.com/soundcloud/large-hadron-migrator
  • 12. Lhm • Online schema change tool • migrate tables with (almost) no downtime • Replication safe • Ruby 1.8 / 1.9, ActiveRecord 2.3 / 3.x and mysql / mysql2 compatible
  • 14. Lhm - prepare create temporary table users lhmn_users
  • 15. Lhm - alter require "lhm" alter table class AddRailsberryToUsers < ActiveRecord::Migration def up Lhm.change_table :users do |u| u.add_column :railsberry, "BOOLEAN DEFAULT true" lhmn_users u.add_index :railsberry end end end
  • 16. Lhm - entangle create trigger users lhmn_users after insert after update after delete
  • 17. Lhm - copy copy all rows users lhmn_users
  • 18. Lhm - rename rename lhma_users users
  • 19. Know your usage patterns Know your tools