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

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 

Recently uploaded (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 

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