SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Profiling and monitoring
        ruby/rails

        JÁN SUCHAL
         @JSUCHAL
Optimalization

 “If you can’t measure it, you can’t improve it.” – Lord Kelvin
 Environment
   development vs. production (hw, sw, load)
   data (synthetic vs. real)
 Bottlenecks
   10sec * 1 run vs. 0.5s * 100 runs
   run time * runs vs. development time
 Microbenchmarks
   waste of time vs. 20 * 1% = 20%
 “There are three kinds of lies: lies, damned lies, and statistics.” –
  Benjamin Disraeli
     single run vs. multiple runs
     average vs. standard deviance, percentiles
     cold vs. hot cache
Profiler - Example

# profiler/dates.rb

require 'date'

def create_days_after(date_str, n)
  after = Date.strptime(date_str) + n
  after.strftime("%Y-%m-%d")
end

1000.times do
  create_days_after("1982-10-27", 5)
end
Ruby Profiler

 $ gem install ruby-prof
 $ ruby-prof dates.rb
   How long does each method take?

 $ ruby-prof dates.rb –m 3
   Just methods above 3% time

  Thread ID: 7749480
  Total: 0.653076

  %self     total      self   wait   child    calls   name
  12.97      0.19      0.08   0.00    0.18     2000   String#scan
  11.57      0.08      0.08   0.00    0.00   205000   String#===
   6.87      0.18      0.04   0.00    0.14     1000   String#gsub
   6.28      0.05      0.04   0.00    0.01    14000   Hash#values_at
   4.08      0.03      0.03   0.00    0.00    80470   Hash#default
   3.21      0.03      0.02   0.00    0.01     3000   Date#emit
Ruby Profiler

Thread ID: 7749480
Total: 0.653076

%self     total      self    wait   child    calls   name
12.97      0.19      0.08    0.00    0.18     2000   String#scan
11.57      0.08      0.08    0.00    0.00   205000   String#===
 6.87      0.18      0.04    0.00    0.14     1000   String#gsub
 6.28      0.05      0.04    0.00    0.01    14000   Hash#values_at
 4.08      0.03      0.03    0.00    0.00    80470   Hash#default
 3.21      0.03      0.02    0.00    0.01     3000   Date#emit

 total – time in method and children calls
 self – time in method call
 wait – wait time
 child – time in child calls
 call – number of times method invoked
Ruby Profiler

 $ ruby-prof dates.rb -m 3 -p graph
   Which method calls what and how many times?

Thread ID: 15523700
Total Time: 0.675587048

%total    %self    total   self    wait   child           calls   Name
                   0.20    0.10    0.00   0.20        2000/2000   <Class::Date>#_strptime_i
30.28%   14.70%    0.20    0.10    0.00   0.20             2000   String#scan
                   0.04    0.04    0.00   0.00    110000/205000   String#===
                   0.02    0.01    0.00   0.01        3000/5000   Date::Format::Bag#method_...
                   0.02    0.00    0.00   0.01        2000/3005   Class#new
                   0.01    0.01    0.00   0.00        5000/5000   String#sub!
                   0.01    0.00    0.00   0.01        2000/2000   Range#===
                   0.00    0.00    0.00   0.00        3000/3000   String#to_i
                   0.00    0.00    0.00   0.00        2000/2000   <Class::Regexp>#quote
                   0.00    0.00    0.00   0.00        2000/2000   Regexp#===
                   0.00    0.00    0.00   0.00        1000/1000   <Class::Date>#num_pattern?
                   0.00    0.00    0.00   0.00        1000/2000   <Class::Date>#_strptime_i
Ruby Profiler

Thread ID: 15523700
Total Time: 0.675587048

%total    %self    total   self    wait   child           calls   Name
                   0.20    0.10    0.00   0.20        2000/2000   <Class::Date>#_strptime_i
30.28%   14.70%    0.20    0.10    0.00   0.20             2000   String#scan
                   0.04    0.04    0.00   0.00    110000/205000   String#===
                   0.02    0.01    0.00   0.01        3000/5000   Date::Format::Bag#method_..



 three parts
   parent calls
   method

   children calls

 calls – number of calls from method/total number of calls
Ruby Profiler

 $ ruby-prof dates.rb -p graph_html -m 3 > graph.html
 $ ruby-prof dates.rb -p graph_html -m 3 –s self > graph.html
Profiler - KCacheGrind

 $ ruby-prof dates.rb -p call_tree -m 3 > dates1.grind
 $ kcachegrind dates1.grind
benchmark-ips

 require   'benchmark/ips'
 require   'ostruct'
 require   'hashr'
 require   'hashugar'

 SMALL_HASH = {:a => 1, :b => 2}

 Benchmark.ips do |x|
   x.report 'OpenStruct create small hash and access once', 'OpenStruct.new(SMALL_HASH).item5'
   x.report 'Hashr create small hash and access once', 'Hashr.new(SMALL_HASH).item5'
   x.report 'Hashugar create small hash and access once', 'Hashugar.new(SMALL_HASH).item5‘
 end


OpenStruct create small hash and access once
  43858.0 (±5.5%) i/s - 221820 in 5.074250s (cycle=3697)
Hashr create small hash and access once
  67408.9 (±5.0%) i/s - 339780 in 5.053728s (cycle=5663)
Hashugar create small hash and access once
 230217.9 (±4.2%) i/s - 1152670 in 5.015705s (cycle=15790)
Memory profiling

 Patched ruby
 $ rvm install 1.9.3 --patch railsexpress --name gc
 $ ruby-prof --mode=allocations dates.rb –m 3


%self      total      self   wait     child   calls   name
59.23    6004.00   6004.00   0.00      0.00    1000   <Class::Date>#strptime
 9.87    1000.00   1000.00   0.00      0.00    1000   Date#strftime
 9.87    9004.00   1000.00   0.00   8004.00    1000   Object#create_days_after
 9.87    1000.00   1000.00   0.00      0.00    1000   Date#+
 9.87   10004.00   1000.00   0.00   9004.00       1   Integer#times
Rails / NewRelic Developer mode

 gem 'newrelic_rpm‘
 http://localhost:3000/newrelic
 gem 'newrelic_rpm', git:
 'git://github.com/jsuchal/rpm.git',
 branch: 'feature-profile-sorting'
NewRelic Developer mode
Rails / NewRelic Developer mode
NewRelic Developer mode
NewRelic Developer mode Profiler
Custom Method Tracers

# initializers/elastic_search_traces.rb

require 'new_relic/agent/method_tracer‘

ElasticSearch.class_eval do
  include NewRelic::Agent::MethodTracer

  add_method_tracer :search, 'Custom/elasticsearch/search'
  add_method_tracer :index, 'Custom/elasticsearch/index'
end
NewRelic Production Monitoring

 Web Transactions – controller actions drilldown
 Transaction Traces – detailed slow requests
 Slow SQL – slow queries
 Background job monitoring
 Availabality monitoring
 Deployment tracking
 Scalability analysis
 ...
 Server monitoring (load, disks, …)
Error tracking

 ExceptionNotifier
 www.airbrake.io
Most common performance problems

 “1 + N query problem”
   joins FTW!

 Lack of proper indexing
 Unnecessary ActiveRecord loading
   e.g. count vs. size vs. length

 Default GC parameters
    37signals params
    RUBY_HEAP_MIN_SLOTS=600000 # This is 60(!) times larger than default
    RUBY_GC_MALLOC_LIMIT=59000000 # This is 7 times larger than default
    RUBY_HEAP_FREE_MIN=100000 # This is 24 times larger than default

 Unknown abstraction internals
   e.g. OpenStruct

Contenu connexe

Tendances

Haskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesHaskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesKatie Ots
 
Solr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanSolr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanGregg Donovan
 
7주 JavaScript 실습
7주 JavaScript 실습7주 JavaScript 실습
7주 JavaScript 실습지수 윤
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...Matthew Tovbin
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...Databricks
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and NagiosNagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and NagiosNagios
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::ManagerJay Shirley
 
Nodejs mongoose
Nodejs mongooseNodejs mongoose
Nodejs mongooseFin Chen
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module DevelopmentJay Harris
 
rsyslog v8: more than just syslog!
rsyslog v8: more than just syslog!rsyslog v8: more than just syslog!
rsyslog v8: more than just syslog!Yury Bushmelev
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitmfrost503
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Rolessartak
 

Tendances (20)

Haskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesHaskell is Not For Production and Other Tales
Haskell is Not For Production and Other Tales
 
Solr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanSolr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg Donovan
 
7주 JavaScript 실습
7주 JavaScript 실습7주 JavaScript 실습
7주 JavaScript 실습
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and NagiosNagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
 
Living with garbage
Living with garbageLiving with garbage
Living with garbage
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
Nodejs mongoose
Nodejs mongooseNodejs mongoose
Nodejs mongoose
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 
rsyslog v8: more than just syslog!
rsyslog v8: more than just syslog!rsyslog v8: more than just syslog!
rsyslog v8: more than just syslog!
 
19. CodeIgniter imagini in mysql
19. CodeIgniter imagini in mysql19. CodeIgniter imagini in mysql
19. CodeIgniter imagini in mysql
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Roles
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 

Similaire à Profiling and monitoring ruby & rails applications

performance vamos dormir mais?
performance vamos dormir mais?performance vamos dormir mais?
performance vamos dormir mais?tdc-globalcode
 
D Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance ProblemsD Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance ProblemsMySQLConference
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Servicevvatikiotis
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeWim Godden
 
Dynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteDynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteSriram Natarajan
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsSerge Smetana
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeWim Godden
 
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
Практический опыт профайлинга и оптимизации производительности Ruby-приложенийПрактический опыт профайлинга и оптимизации производительности Ruby-приложений
Практический опыт профайлинга и оптимизации производительности Ruby-приложенийOlga Lavrentieva
 
Ruby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinRuby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinLauree R
 
Distributed Load Testing with k6 - DevOps Barcelona
Distributed Load Testing with k6 - DevOps BarcelonaDistributed Load Testing with k6 - DevOps Barcelona
Distributed Load Testing with k6 - DevOps BarcelonaThijs Feryn
 
Distributed load testing with K6 - NDC London 2024
Distributed load testing with K6 - NDC London 2024Distributed load testing with K6 - NDC London 2024
Distributed load testing with K6 - NDC London 2024Thijs Feryn
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularErik Guzman
 
Profiling ruby
Profiling rubyProfiling ruby
Profiling rubynasirj
 
(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014
(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014
(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014Amazon Web Services
 

Similaire à Profiling and monitoring ruby & rails applications (20)

performance vamos dormir mais?
performance vamos dormir mais?performance vamos dormir mais?
performance vamos dormir mais?
 
D Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance ProblemsD Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance Problems
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
Dynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteDynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web site
 
Top Node.js Metrics to Watch
Top Node.js Metrics to WatchTop Node.js Metrics to Watch
Top Node.js Metrics to Watch
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
Практический опыт профайлинга и оптимизации производительности Ruby-приложенийПрактический опыт профайлинга и оптимизации производительности Ruby-приложений
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
 
Ruby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinRuby on Rails Developer - Allerin
Ruby on Rails Developer - Allerin
 
Distributed Load Testing with k6 - DevOps Barcelona
Distributed Load Testing with k6 - DevOps BarcelonaDistributed Load Testing with k6 - DevOps Barcelona
Distributed Load Testing with k6 - DevOps Barcelona
 
Distributed load testing with K6 - NDC London 2024
Distributed load testing with K6 - NDC London 2024Distributed load testing with K6 - NDC London 2024
Distributed load testing with K6 - NDC London 2024
 
Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
 
Profiling ruby
Profiling rubyProfiling ruby
Profiling ruby
 
(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014
(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014
(SDD402) Amazon ElastiCache Deep Dive | AWS re:Invent 2014
 

Plus de Jano Suchal

Slovensko.Digital: Čo ďalej?
Slovensko.Digital: Čo ďalej?Slovensko.Digital: Čo ďalej?
Slovensko.Digital: Čo ďalej?Jano Suchal
 
Improving code quality
Improving code qualityImproving code quality
Improving code qualityJano Suchal
 
Beyond search queries
Beyond search queriesBeyond search queries
Beyond search queriesJano Suchal
 
Rank all the things!
Rank all the things!Rank all the things!
Rank all the things!Jano Suchal
 
Rank all the (geo) things!
Rank all the (geo) things!Rank all the (geo) things!
Rank all the (geo) things!Jano Suchal
 
Ako si vybrať programovácí jazyk alebo framework?
Ako si vybrať programovácí jazyk alebo framework?Ako si vybrať programovácí jazyk alebo framework?
Ako si vybrať programovácí jazyk alebo framework?Jano Suchal
 
Bonetics: Mastering Puppet Workshop
Bonetics: Mastering Puppet WorkshopBonetics: Mastering Puppet Workshop
Bonetics: Mastering Puppet WorkshopJano Suchal
 
Peter Mihalik: Puppet
Peter Mihalik: PuppetPeter Mihalik: Puppet
Peter Mihalik: PuppetJano Suchal
 
Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3Jano Suchal
 
Ako si vybrať programovací jazyk a framework?
Ako si vybrať programovací jazyk a framework?Ako si vybrať programovací jazyk a framework?
Ako si vybrať programovací jazyk a framework?Jano Suchal
 
SQL: Query optimization in practice
SQL: Query optimization in practiceSQL: Query optimization in practice
SQL: Query optimization in practiceJano Suchal
 
Garelic: Google Analytics as App Performance monitoring
Garelic: Google Analytics as App Performance monitoringGarelic: Google Analytics as App Performance monitoring
Garelic: Google Analytics as App Performance monitoringJano Suchal
 
Miroslav Šimulčík: Temporálne databázy
Miroslav Šimulčík: Temporálne databázyMiroslav Šimulčík: Temporálne databázy
Miroslav Šimulčík: Temporálne databázyJano Suchal
 
Vojtech Rinik: Internship v USA - moje skúsenosti
Vojtech Rinik: Internship v USA - moje skúsenostiVojtech Rinik: Internship v USA - moje skúsenosti
Vojtech Rinik: Internship v USA - moje skúsenostiJano Suchal
 
Aký programovací jazyk a framework si vybrať a prečo?
Aký programovací jazyk a framework si vybrať a prečo?Aký programovací jazyk a framework si vybrať a prečo?
Aký programovací jazyk a framework si vybrať a prečo?Jano Suchal
 
Petr Joachim: Redis na Super.cz
Petr Joachim: Redis na Super.czPetr Joachim: Redis na Super.cz
Petr Joachim: Redis na Super.czJano Suchal
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
PostgreSQL: Advanced features in practice
PostgreSQL: Advanced features in practicePostgreSQL: Advanced features in practice
PostgreSQL: Advanced features in practiceJano Suchal
 

Plus de Jano Suchal (20)

Slovensko.Digital: Čo ďalej?
Slovensko.Digital: Čo ďalej?Slovensko.Digital: Čo ďalej?
Slovensko.Digital: Čo ďalej?
 
Datanest 3.0
Datanest 3.0Datanest 3.0
Datanest 3.0
 
Improving code quality
Improving code qualityImproving code quality
Improving code quality
 
Beyond search queries
Beyond search queriesBeyond search queries
Beyond search queries
 
Rank all the things!
Rank all the things!Rank all the things!
Rank all the things!
 
Rank all the (geo) things!
Rank all the (geo) things!Rank all the (geo) things!
Rank all the (geo) things!
 
Ako si vybrať programovácí jazyk alebo framework?
Ako si vybrať programovácí jazyk alebo framework?Ako si vybrať programovácí jazyk alebo framework?
Ako si vybrať programovácí jazyk alebo framework?
 
Bonetics: Mastering Puppet Workshop
Bonetics: Mastering Puppet WorkshopBonetics: Mastering Puppet Workshop
Bonetics: Mastering Puppet Workshop
 
Peter Mihalik: Puppet
Peter Mihalik: PuppetPeter Mihalik: Puppet
Peter Mihalik: Puppet
 
Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3Tomáš Čorej: Configuration management & CFEngine3
Tomáš Čorej: Configuration management & CFEngine3
 
Ako si vybrať programovací jazyk a framework?
Ako si vybrať programovací jazyk a framework?Ako si vybrať programovací jazyk a framework?
Ako si vybrať programovací jazyk a framework?
 
SQL: Query optimization in practice
SQL: Query optimization in practiceSQL: Query optimization in practice
SQL: Query optimization in practice
 
Garelic: Google Analytics as App Performance monitoring
Garelic: Google Analytics as App Performance monitoringGarelic: Google Analytics as App Performance monitoring
Garelic: Google Analytics as App Performance monitoring
 
Miroslav Šimulčík: Temporálne databázy
Miroslav Šimulčík: Temporálne databázyMiroslav Šimulčík: Temporálne databázy
Miroslav Šimulčík: Temporálne databázy
 
Vojtech Rinik: Internship v USA - moje skúsenosti
Vojtech Rinik: Internship v USA - moje skúsenostiVojtech Rinik: Internship v USA - moje skúsenosti
Vojtech Rinik: Internship v USA - moje skúsenosti
 
Aký programovací jazyk a framework si vybrať a prečo?
Aký programovací jazyk a framework si vybrať a prečo?Aký programovací jazyk a framework si vybrať a prečo?
Aký programovací jazyk a framework si vybrať a prečo?
 
Čo po GAMČI?
Čo po GAMČI?Čo po GAMČI?
Čo po GAMČI?
 
Petr Joachim: Redis na Super.cz
Petr Joachim: Redis na Super.czPetr Joachim: Redis na Super.cz
Petr Joachim: Redis na Super.cz
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
PostgreSQL: Advanced features in practice
PostgreSQL: Advanced features in practicePostgreSQL: Advanced features in practice
PostgreSQL: Advanced features in practice
 

Dernier

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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Dernier (20)

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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Profiling and monitoring ruby & rails applications

  • 1. Profiling and monitoring ruby/rails JÁN SUCHAL @JSUCHAL
  • 2. Optimalization  “If you can’t measure it, you can’t improve it.” – Lord Kelvin  Environment  development vs. production (hw, sw, load)  data (synthetic vs. real)  Bottlenecks  10sec * 1 run vs. 0.5s * 100 runs  run time * runs vs. development time  Microbenchmarks  waste of time vs. 20 * 1% = 20%  “There are three kinds of lies: lies, damned lies, and statistics.” – Benjamin Disraeli  single run vs. multiple runs  average vs. standard deviance, percentiles  cold vs. hot cache
  • 3. Profiler - Example # profiler/dates.rb require 'date' def create_days_after(date_str, n) after = Date.strptime(date_str) + n after.strftime("%Y-%m-%d") end 1000.times do create_days_after("1982-10-27", 5) end
  • 4. Ruby Profiler  $ gem install ruby-prof  $ ruby-prof dates.rb  How long does each method take?  $ ruby-prof dates.rb –m 3  Just methods above 3% time Thread ID: 7749480 Total: 0.653076 %self total self wait child calls name 12.97 0.19 0.08 0.00 0.18 2000 String#scan 11.57 0.08 0.08 0.00 0.00 205000 String#=== 6.87 0.18 0.04 0.00 0.14 1000 String#gsub 6.28 0.05 0.04 0.00 0.01 14000 Hash#values_at 4.08 0.03 0.03 0.00 0.00 80470 Hash#default 3.21 0.03 0.02 0.00 0.01 3000 Date#emit
  • 5. Ruby Profiler Thread ID: 7749480 Total: 0.653076 %self total self wait child calls name 12.97 0.19 0.08 0.00 0.18 2000 String#scan 11.57 0.08 0.08 0.00 0.00 205000 String#=== 6.87 0.18 0.04 0.00 0.14 1000 String#gsub 6.28 0.05 0.04 0.00 0.01 14000 Hash#values_at 4.08 0.03 0.03 0.00 0.00 80470 Hash#default 3.21 0.03 0.02 0.00 0.01 3000 Date#emit  total – time in method and children calls  self – time in method call  wait – wait time  child – time in child calls  call – number of times method invoked
  • 6. Ruby Profiler  $ ruby-prof dates.rb -m 3 -p graph  Which method calls what and how many times? Thread ID: 15523700 Total Time: 0.675587048 %total %self total self wait child calls Name 0.20 0.10 0.00 0.20 2000/2000 <Class::Date>#_strptime_i 30.28% 14.70% 0.20 0.10 0.00 0.20 2000 String#scan 0.04 0.04 0.00 0.00 110000/205000 String#=== 0.02 0.01 0.00 0.01 3000/5000 Date::Format::Bag#method_... 0.02 0.00 0.00 0.01 2000/3005 Class#new 0.01 0.01 0.00 0.00 5000/5000 String#sub! 0.01 0.00 0.00 0.01 2000/2000 Range#=== 0.00 0.00 0.00 0.00 3000/3000 String#to_i 0.00 0.00 0.00 0.00 2000/2000 <Class::Regexp>#quote 0.00 0.00 0.00 0.00 2000/2000 Regexp#=== 0.00 0.00 0.00 0.00 1000/1000 <Class::Date>#num_pattern? 0.00 0.00 0.00 0.00 1000/2000 <Class::Date>#_strptime_i
  • 7. Ruby Profiler Thread ID: 15523700 Total Time: 0.675587048 %total %self total self wait child calls Name 0.20 0.10 0.00 0.20 2000/2000 <Class::Date>#_strptime_i 30.28% 14.70% 0.20 0.10 0.00 0.20 2000 String#scan 0.04 0.04 0.00 0.00 110000/205000 String#=== 0.02 0.01 0.00 0.01 3000/5000 Date::Format::Bag#method_..  three parts  parent calls  method  children calls  calls – number of calls from method/total number of calls
  • 8. Ruby Profiler  $ ruby-prof dates.rb -p graph_html -m 3 > graph.html  $ ruby-prof dates.rb -p graph_html -m 3 –s self > graph.html
  • 9. Profiler - KCacheGrind  $ ruby-prof dates.rb -p call_tree -m 3 > dates1.grind  $ kcachegrind dates1.grind
  • 10. benchmark-ips require 'benchmark/ips' require 'ostruct' require 'hashr' require 'hashugar' SMALL_HASH = {:a => 1, :b => 2} Benchmark.ips do |x| x.report 'OpenStruct create small hash and access once', 'OpenStruct.new(SMALL_HASH).item5' x.report 'Hashr create small hash and access once', 'Hashr.new(SMALL_HASH).item5' x.report 'Hashugar create small hash and access once', 'Hashugar.new(SMALL_HASH).item5‘ end OpenStruct create small hash and access once 43858.0 (±5.5%) i/s - 221820 in 5.074250s (cycle=3697) Hashr create small hash and access once 67408.9 (±5.0%) i/s - 339780 in 5.053728s (cycle=5663) Hashugar create small hash and access once 230217.9 (±4.2%) i/s - 1152670 in 5.015705s (cycle=15790)
  • 11. Memory profiling  Patched ruby  $ rvm install 1.9.3 --patch railsexpress --name gc  $ ruby-prof --mode=allocations dates.rb –m 3 %self total self wait child calls name 59.23 6004.00 6004.00 0.00 0.00 1000 <Class::Date>#strptime 9.87 1000.00 1000.00 0.00 0.00 1000 Date#strftime 9.87 9004.00 1000.00 0.00 8004.00 1000 Object#create_days_after 9.87 1000.00 1000.00 0.00 0.00 1000 Date#+ 9.87 10004.00 1000.00 0.00 9004.00 1 Integer#times
  • 12. Rails / NewRelic Developer mode  gem 'newrelic_rpm‘  http://localhost:3000/newrelic  gem 'newrelic_rpm', git: 'git://github.com/jsuchal/rpm.git', branch: 'feature-profile-sorting'
  • 14. Rails / NewRelic Developer mode
  • 17. Custom Method Tracers # initializers/elastic_search_traces.rb require 'new_relic/agent/method_tracer‘ ElasticSearch.class_eval do include NewRelic::Agent::MethodTracer add_method_tracer :search, 'Custom/elasticsearch/search' add_method_tracer :index, 'Custom/elasticsearch/index' end
  • 18. NewRelic Production Monitoring  Web Transactions – controller actions drilldown  Transaction Traces – detailed slow requests  Slow SQL – slow queries  Background job monitoring  Availabality monitoring  Deployment tracking  Scalability analysis  ...  Server monitoring (load, disks, …)
  • 19.
  • 20.
  • 21.
  • 22.
  • 24. Most common performance problems  “1 + N query problem”  joins FTW!  Lack of proper indexing  Unnecessary ActiveRecord loading  e.g. count vs. size vs. length  Default GC parameters  37signals params  RUBY_HEAP_MIN_SLOTS=600000 # This is 60(!) times larger than default  RUBY_GC_MALLOC_LIMIT=59000000 # This is 7 times larger than default  RUBY_HEAP_FREE_MIN=100000 # This is 24 times larger than default  Unknown abstraction internals  e.g. OpenStruct