SlideShare a Scribd company logo
Nov 19, 2008




  Scaling the Rails
How a little quiz achieved Olympic Glory




   Josh Schwartzman, Newzwag
Get Ready For:
• Database Enhancements & Gotchas
• Hardware Basics
• Load Testing
• Rails Backends & Web Servers
From Humble Beginnings:
(on limited hardware)




30,000 concurrent users     9 million pageviews/hour
[question]
[answer]
Find
   Your       MySQL


Bottlenecks
Analyze Your Logs
• Look for slowest requests
• Verbose Logging

• Detailed DB logging (a small script)
  Completed in 0.06763 (14 reqs/sec) | Rendering:
  0.01377 (20%) |
  DB: 0.00587 (8%) 2.6k, 54 rows, 7 queries |
  200 OK [http://url]
Database Enhancements
         (Reads)

• Index all of the keys you are going to use to
  find your data
  • Turn on debugging and check the slowest
    queries
  • Use EXPLAIN on your SQL statements

      (Some MySQL-specific enhancements)
Database Enhancements
         (Reads)

• Minimize your # of queries
• Use Eager Loading
Database Enhancements
         (Writes)

• Only save the data that has changed
• Rails 2.1: 2x faster on some actions, due to:
   • Partial Updates (automatic
      performance)
    • Dirty Tracking
Database Enhancements
         (Writes)

• Check your model validations

• Transactions w/InnoDB
Database Enhancements
         (Writes)

• Bulk Writes with AR-Extensions
 • 8-12x faster on InnoDB
 • 8-40x faster on MyISAM*
• Master/Slave Replication
 • Master DB for writes with replication to
    read slaves
 • Distributes load to multiple machines
          *40x if you don’t use validations
Useful Plugins
• ActiveRecord Extensions
 • Bulk writes
• Dr. Nic’s magic_multi_connections
 • Offload reads/writes to another DB
• Single-Write Multi-Read (SWMR)
 • Our plugin to write to one DB & use
    multiple read slaves
Hardware
  • Cache everything, so lots of RAM
  • Make your reads/writes fast
   • RAID helps:
                         RAID 10 - faster writes
RAID 5 - faster reads
Hardware
• Minimize hits to your Rails Stack
 • Cache images or use a fast web server
 • Move all your routes.rb routing logic to
    dedicated hardware (load balancer)
Hardware
• Keep App & DB on separate servers
 • Infrastructure specific to it’s purpose
 • Easy to isolate & debug bottlenecks:



                               Graph from Cacti
Load Testing
• Test the path a user will take
• One Tool: JMeter
 • Session and full hardware stack testing
 • jmeter-server
   • Distributed testing
   • Test from any computer @ ~1500
      threads per box
Load Testing
• You’ll always find new problems under
  load
 • We discovered issues with lots of
    new users: checking login twice
 • Simple queries (especially joins)
    became slow
 • Tweaking how often we wrote scores
    to the database, and how many at a
    time
Load Testing
                • The type and number of web servers*
                      is critical. Quick comparison:

Mongrel                                      Ebb                                         Thin
•Stable                                      •Some bugs                                  •Almost as stable
•RAM & CPU heavy                             •RAM & CPU light                            as Mongrel (it uses
•Slowest per action                          •Fastest per                                Mongrel’s parser)
                                                                                         •Lightest hardware
                                             action (uses C for
                                             heavy lifting)                              load
                                                                                         •Almost as fast as
                                                                                         Ebb
   *Yeah, you still need a web server like Lighttpd or Nginx to handle your static files and proxy to your Rails backends
Load Testing
                             Using 18 Mongrels
# of questions




                 1   2   3     4    5        6   7   8   9   10
                                   minutes


Gruff graphs from our
 custom user actions
Load Testing
                                 Using 18 Ebbs
# of questions




                   1   2     3    4    5         6   7   8   9      10
                                       minutes



                 949 questions / minute: 40% faster than mongrel!
When You Need a
     Little Help
• After all of that performance work...
 • Servers were crashing spontaneously
 • Nothing was apparent in the logs
 • Sleepless nights...
We Found Stability in God
    Simple monitoring for Rails apps:
What Was the
         Problem?
• Post requests on older browsers (Firefox
  1.5, Navigator 7)
• Killed our backends, and as each failed, it
  passed on the request to another server
• Solution: switch from Nginx to Lighttpd
A Summary
• 200   (scaling)   5000 simultaneous users

     a 25x performance gain


• Achieved by adding plugins, custom
  Memcached methods, optimizing the DB,
  changing to ebbs, and numerous other code
  tweaks (and a slight hardware upgrade)
Any Questions:

    Josh Schwartzman
Lead Developer, Newzwag

  josh@newzwag.com
Resources
•Active Record Extensions:
 http://www.continuousthinking.com/are/activerecord-extensions-0-0-5

•Detailed DB Logging: http://gurge.com/blog/2006/11/09/rails-sql-logging-improvements/
•Ebb: http://ebb.rubyforge.org/
•God (Monitoring): http://god.rubyforge.org/
•Gruff Graphs: http://nubyonrails.com/pages/gruff
•Jmeter: http://jakarta.apache.org/jmeter/
•Magic Multi Connections: http://magicmodels.rubyforge.org/magic_multi_connections/
•Seattle.rb’s Memcache Client: http://github.com/fiveruns/memcache-client/tree/master
•Thin: http://code.macournoyer.com/thin/

More Related Content

What's hot

Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Atwix
 
Application Caching: The Hidden Microservice (SAConf)
Application Caching: The Hidden Microservice (SAConf)Application Caching: The Hidden Microservice (SAConf)
Application Caching: The Hidden Microservice (SAConf)
Scott Mansfield
 
Veeam backup Oracle DB in a VM is easy and reliable way to protect data
Veeam backup Oracle DB in a VM is easy and reliable way to protect dataVeeam backup Oracle DB in a VM is easy and reliable way to protect data
Veeam backup Oracle DB in a VM is easy and reliable way to protect data
Aleks Y
 
Rails in the Cloud
Rails in the CloudRails in the Cloud
Rails in the Cloud
Jonathan Weiss
 
Scale Fail: How I Learned to Love the Downtime
Scale Fail: How I Learned to Love the DowntimeScale Fail: How I Learned to Love the Downtime
Scale Fail: How I Learned to Love the DowntimePostgreSQL Experts, Inc.
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
Command Prompt., Inc
 
Database and Public Endpoints redundancy on Azure (CloudBrew)
Database and Public Endpoints redundancy on Azure (CloudBrew)Database and Public Endpoints redundancy on Azure (CloudBrew)
Database and Public Endpoints redundancy on Azure (CloudBrew)
Radu Vunvulea
 
JVM Memory Management Details
JVM Memory Management DetailsJVM Memory Management Details
JVM Memory Management Details
Azul Systems Inc.
 
OSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration SummitOSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration Summit
Don Marti
 
3.2 Streaming and Messaging
3.2 Streaming and Messaging3.2 Streaming and Messaging
3.2 Streaming and Messaging
振东 刘
 
CNPM: Private NPM for Company / 企業級私有NPM
CNPM: Private NPM for Company / 企業級私有NPMCNPM: Private NPM for Company / 企業級私有NPM
CNPM: Private NPM for Company / 企業級私有NPM
Feng Yuan
 
Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012
eballisty
 
Cache hcm-topdev
Cache hcm-topdevCache hcm-topdev
Cache hcm-topdev
Thanh Chau
 
NVMe over Fabric
NVMe over FabricNVMe over Fabric
NVMe over Fabric
singh.gurjeet
 
Beyond 1000 bosh Deployments
Beyond 1000 bosh DeploymentsBeyond 1000 bosh Deployments
Beyond 1000 bosh Deployments
anynines GmbH
 
Erlang On Xen: Redefining the Cloud Software Stack
Erlang On Xen: Redefining the Cloud Software StackErlang On Xen: Redefining the Cloud Software Stack
Erlang On Xen: Redefining the Cloud Software StackViktor Sovietov
 
Demystifying postgres logical replication percona live sc
Demystifying postgres logical replication percona live scDemystifying postgres logical replication percona live sc
Demystifying postgres logical replication percona live sc
Emanuel Calvo
 

What's hot (19)

Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
 
Memcache d
Memcache dMemcache d
Memcache d
 
Application Caching: The Hidden Microservice (SAConf)
Application Caching: The Hidden Microservice (SAConf)Application Caching: The Hidden Microservice (SAConf)
Application Caching: The Hidden Microservice (SAConf)
 
Veeam backup Oracle DB in a VM is easy and reliable way to protect data
Veeam backup Oracle DB in a VM is easy and reliable way to protect dataVeeam backup Oracle DB in a VM is easy and reliable way to protect data
Veeam backup Oracle DB in a VM is easy and reliable way to protect data
 
Rails in the Cloud
Rails in the CloudRails in the Cloud
Rails in the Cloud
 
Scale Fail: How I Learned to Love the Downtime
Scale Fail: How I Learned to Love the DowntimeScale Fail: How I Learned to Love the Downtime
Scale Fail: How I Learned to Love the Downtime
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
Database and Public Endpoints redundancy on Azure (CloudBrew)
Database and Public Endpoints redundancy on Azure (CloudBrew)Database and Public Endpoints redundancy on Azure (CloudBrew)
Database and Public Endpoints redundancy on Azure (CloudBrew)
 
JVM Memory Management Details
JVM Memory Management DetailsJVM Memory Management Details
JVM Memory Management Details
 
OSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration SummitOSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration Summit
 
Netcf Gc
Netcf GcNetcf Gc
Netcf Gc
 
3.2 Streaming and Messaging
3.2 Streaming and Messaging3.2 Streaming and Messaging
3.2 Streaming and Messaging
 
CNPM: Private NPM for Company / 企業級私有NPM
CNPM: Private NPM for Company / 企業級私有NPMCNPM: Private NPM for Company / 企業級私有NPM
CNPM: Private NPM for Company / 企業級私有NPM
 
Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012
 
Cache hcm-topdev
Cache hcm-topdevCache hcm-topdev
Cache hcm-topdev
 
NVMe over Fabric
NVMe over FabricNVMe over Fabric
NVMe over Fabric
 
Beyond 1000 bosh Deployments
Beyond 1000 bosh DeploymentsBeyond 1000 bosh Deployments
Beyond 1000 bosh Deployments
 
Erlang On Xen: Redefining the Cloud Software Stack
Erlang On Xen: Redefining the Cloud Software StackErlang On Xen: Redefining the Cloud Software Stack
Erlang On Xen: Redefining the Cloud Software Stack
 
Demystifying postgres logical replication percona live sc
Demystifying postgres logical replication percona live scDemystifying postgres logical replication percona live sc
Demystifying postgres logical replication percona live sc
 

Viewers also liked

Olympics Quiz
Olympics QuizOlympics Quiz
Olympics Quiz
Diganto Sarkar
 
Cinema quiz - Aakash Vasa
Cinema quiz - Aakash VasaCinema quiz - Aakash Vasa
Cinema quiz - Aakash Vasa
Shashank Jogani
 
Olympics Quiz - Answers
Olympics Quiz  - AnswersOlympics Quiz  - Answers
Olympics Quiz - Answers
Rithwik K
 
OLYMPICS QUIZ 2012
OLYMPICS QUIZ 2012OLYMPICS QUIZ 2012
OLYMPICS QUIZ 2012
Rajan Thambehalli
 
KQA Cricket Quiz Finals 2011
KQA Cricket Quiz Finals 2011KQA Cricket Quiz Finals 2011
KQA Cricket Quiz Finals 2011
Manish Achuth
 
Quiz on connecting words and pictures
Quiz on connecting words and picturesQuiz on connecting words and pictures
Quiz on connecting words and pictures
pptmania
 

Viewers also liked (6)

Olympics Quiz
Olympics QuizOlympics Quiz
Olympics Quiz
 
Cinema quiz - Aakash Vasa
Cinema quiz - Aakash VasaCinema quiz - Aakash Vasa
Cinema quiz - Aakash Vasa
 
Olympics Quiz - Answers
Olympics Quiz  - AnswersOlympics Quiz  - Answers
Olympics Quiz - Answers
 
OLYMPICS QUIZ 2012
OLYMPICS QUIZ 2012OLYMPICS QUIZ 2012
OLYMPICS QUIZ 2012
 
KQA Cricket Quiz Finals 2011
KQA Cricket Quiz Finals 2011KQA Cricket Quiz Finals 2011
KQA Cricket Quiz Finals 2011
 
Quiz on connecting words and pictures
Quiz on connecting words and picturesQuiz on connecting words and pictures
Quiz on connecting words and pictures
 

Similar to Scaling the Rails

Rails Conf Europe 2007 Notes
Rails Conf  Europe 2007  NotesRails Conf  Europe 2007  Notes
Rails Conf Europe 2007 NotesRoss Lawley
 
Deploying and Scaling using AWS
Deploying and Scaling using AWSDeploying and Scaling using AWS
Deploying and Scaling using AWS
wr0ngway
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
Paul Pajo
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro MerbPaul Pajo
 
The Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With RubyThe Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With Ruby
mattmatt
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on Rails
Jonathan Weiss
 
saurabh soni rac
saurabh soni racsaurabh soni rac
saurabh soni rac
saurabh soni
 
Rails on JRuby
Rails on JRubyRails on JRuby
Rails on JRuby
Rob C
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB Clusters
Severalnines
 
MySQL Aquarium Paris
MySQL Aquarium ParisMySQL Aquarium Paris
MySQL Aquarium Paris
Alexis Moussine-Pouchkine
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival Skills
Evergreen ILS
 
How to build a state-of-the-art rails cluster
How to build a state-of-the-art rails clusterHow to build a state-of-the-art rails cluster
How to build a state-of-the-art rails cluster
Tim Lossen
 
Xen_and_Rails_deployment
Xen_and_Rails_deploymentXen_and_Rails_deployment
Xen_and_Rails_deploymentAbhishek Singh
 
Tricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The CloudTricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The CloudMySQLConference
 
Rails in the Cloud
Rails in the CloudRails in the Cloud
Rails in the Cloud
iwarshak
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring Rails
Jonathan Weiss
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyAmit Solanki
 
Galera Multi Master Synchronous My S Q L Replication Clusters
Galera  Multi Master  Synchronous  My S Q L  Replication  ClustersGalera  Multi Master  Synchronous  My S Q L  Replication  Clusters
Galera Multi Master Synchronous My S Q L Replication ClustersPerconaPerformance
 

Similar to Scaling the Rails (20)

Rails Conf Europe 2007 Notes
Rails Conf  Europe 2007  NotesRails Conf  Europe 2007  Notes
Rails Conf Europe 2007 Notes
 
Deploying and Scaling using AWS
Deploying and Scaling using AWSDeploying and Scaling using AWS
Deploying and Scaling using AWS
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
The Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With RubyThe Current State of Asynchronous Processing With Ruby
The Current State of Asynchronous Processing With Ruby
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on Rails
 
saurabh soni rac
saurabh soni racsaurabh soni rac
saurabh soni rac
 
Rails on JRuby
Rails on JRubyRails on JRuby
Rails on JRuby
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB Clusters
 
MySQL Aquarium Paris
MySQL Aquarium ParisMySQL Aquarium Paris
MySQL Aquarium Paris
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival Skills
 
How to build a state-of-the-art rails cluster
How to build a state-of-the-art rails clusterHow to build a state-of-the-art rails cluster
How to build a state-of-the-art rails cluster
 
Xen_and_Rails_deployment
Xen_and_Rails_deploymentXen_and_Rails_deployment
Xen_and_Rails_deployment
 
Tricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The CloudTricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
 
Rails in the Cloud
Rails in the CloudRails in the Cloud
Rails in the Cloud
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring Rails
 
re7jweiss
re7jweissre7jweiss
re7jweiss
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Galera Multi Master Synchronous My S Q L Replication Clusters
Galera  Multi Master  Synchronous  My S Q L  Replication  ClustersGalera  Multi Master  Synchronous  My S Q L  Replication  Clusters
Galera Multi Master Synchronous My S Q L Replication Clusters
 

More from elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
elliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de containerelliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Librarieselliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Webelliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduinoelliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorceryelliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Designelliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebookelliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Recently uploaded

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

Scaling the Rails

  • 1. Nov 19, 2008 Scaling the Rails How a little quiz achieved Olympic Glory Josh Schwartzman, Newzwag
  • 2. Get Ready For: • Database Enhancements & Gotchas • Hardware Basics • Load Testing • Rails Backends & Web Servers
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. (on limited hardware) 30,000 concurrent users 9 million pageviews/hour
  • 11. Find Your MySQL Bottlenecks
  • 12. Analyze Your Logs • Look for slowest requests • Verbose Logging • Detailed DB logging (a small script) Completed in 0.06763 (14 reqs/sec) | Rendering: 0.01377 (20%) | DB: 0.00587 (8%) 2.6k, 54 rows, 7 queries | 200 OK [http://url]
  • 13. Database Enhancements (Reads) • Index all of the keys you are going to use to find your data • Turn on debugging and check the slowest queries • Use EXPLAIN on your SQL statements (Some MySQL-specific enhancements)
  • 14. Database Enhancements (Reads) • Minimize your # of queries • Use Eager Loading
  • 15. Database Enhancements (Writes) • Only save the data that has changed • Rails 2.1: 2x faster on some actions, due to: • Partial Updates (automatic performance) • Dirty Tracking
  • 16. Database Enhancements (Writes) • Check your model validations • Transactions w/InnoDB
  • 17. Database Enhancements (Writes) • Bulk Writes with AR-Extensions • 8-12x faster on InnoDB • 8-40x faster on MyISAM* • Master/Slave Replication • Master DB for writes with replication to read slaves • Distributes load to multiple machines *40x if you don’t use validations
  • 18. Useful Plugins • ActiveRecord Extensions • Bulk writes • Dr. Nic’s magic_multi_connections • Offload reads/writes to another DB • Single-Write Multi-Read (SWMR) • Our plugin to write to one DB & use multiple read slaves
  • 19. Hardware • Cache everything, so lots of RAM • Make your reads/writes fast • RAID helps: RAID 10 - faster writes RAID 5 - faster reads
  • 20. Hardware • Minimize hits to your Rails Stack • Cache images or use a fast web server • Move all your routes.rb routing logic to dedicated hardware (load balancer)
  • 21. Hardware • Keep App & DB on separate servers • Infrastructure specific to it’s purpose • Easy to isolate & debug bottlenecks: Graph from Cacti
  • 22. Load Testing • Test the path a user will take • One Tool: JMeter • Session and full hardware stack testing • jmeter-server • Distributed testing • Test from any computer @ ~1500 threads per box
  • 23.
  • 24. Load Testing • You’ll always find new problems under load • We discovered issues with lots of new users: checking login twice • Simple queries (especially joins) became slow • Tweaking how often we wrote scores to the database, and how many at a time
  • 25. Load Testing • The type and number of web servers* is critical. Quick comparison: Mongrel Ebb Thin •Stable •Some bugs •Almost as stable •RAM & CPU heavy •RAM & CPU light as Mongrel (it uses •Slowest per action •Fastest per Mongrel’s parser) •Lightest hardware action (uses C for heavy lifting) load •Almost as fast as Ebb *Yeah, you still need a web server like Lighttpd or Nginx to handle your static files and proxy to your Rails backends
  • 26. Load Testing Using 18 Mongrels # of questions 1 2 3 4 5 6 7 8 9 10 minutes Gruff graphs from our custom user actions
  • 27. Load Testing Using 18 Ebbs # of questions 1 2 3 4 5 6 7 8 9 10 minutes 949 questions / minute: 40% faster than mongrel!
  • 28. When You Need a Little Help • After all of that performance work... • Servers were crashing spontaneously • Nothing was apparent in the logs • Sleepless nights...
  • 29.
  • 30. We Found Stability in God Simple monitoring for Rails apps:
  • 31. What Was the Problem? • Post requests on older browsers (Firefox 1.5, Navigator 7) • Killed our backends, and as each failed, it passed on the request to another server • Solution: switch from Nginx to Lighttpd
  • 32. A Summary • 200 (scaling) 5000 simultaneous users a 25x performance gain • Achieved by adding plugins, custom Memcached methods, optimizing the DB, changing to ebbs, and numerous other code tweaks (and a slight hardware upgrade)
  • 33.
  • 34. Any Questions: Josh Schwartzman Lead Developer, Newzwag josh@newzwag.com
  • 35. Resources •Active Record Extensions: http://www.continuousthinking.com/are/activerecord-extensions-0-0-5 •Detailed DB Logging: http://gurge.com/blog/2006/11/09/rails-sql-logging-improvements/ •Ebb: http://ebb.rubyforge.org/ •God (Monitoring): http://god.rubyforge.org/ •Gruff Graphs: http://nubyonrails.com/pages/gruff •Jmeter: http://jakarta.apache.org/jmeter/ •Magic Multi Connections: http://magicmodels.rubyforge.org/magic_multi_connections/ •Seattle.rb’s Memcache Client: http://github.com/fiveruns/memcache-client/tree/master •Thin: http://code.macournoyer.com/thin/