SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
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/

Contenu connexe

Tendances

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 dataAleks Y
 
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 forksCommand 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 DetailsAzul 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 SummitDon 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 / 企業級私有NPMFeng Yuan
 
Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012Performance Tuning - MuraCon 2012
Performance Tuning - MuraCon 2012eballisty
 
Cache hcm-topdev
Cache hcm-topdevCache hcm-topdev
Cache hcm-topdevThanh Chau
 
Beyond 1000 bosh Deployments
Beyond 1000 bosh DeploymentsBeyond 1000 bosh Deployments
Beyond 1000 bosh Deploymentsanynines 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 scEmanuel Calvo
 

Tendances (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
 

En vedette

Cinema quiz - Aakash Vasa
Cinema quiz - Aakash VasaCinema quiz - Aakash Vasa
Cinema quiz - Aakash VasaShashank Jogani
 
Olympics Quiz - Answers
Olympics Quiz  - AnswersOlympics Quiz  - Answers
Olympics Quiz - AnswersRithwik K
 
KQA Cricket Quiz Finals 2011
KQA Cricket Quiz Finals 2011KQA Cricket Quiz Finals 2011
KQA Cricket Quiz Finals 2011Manish Achuth
 
Quiz on connecting words and pictures
Quiz on connecting words and picturesQuiz on connecting words and pictures
Quiz on connecting words and picturespptmania
 

En vedette (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
 

Similaire à Scaling Rails to 30,000 Users

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 AWSwr0ngway
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro MerbPaul 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 Rubymattmatt
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on RailsJonathan Weiss
 
Rails on JRuby
Rails on JRubyRails on JRuby
Rails on JRubyRob 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 ClustersSeveralnines
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen 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 clusterTim 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 Cloudiwarshak
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring RailsJonathan 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
 

Similaire à Scaling Rails to 30,000 Users (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
 

Plus de elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando 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 Structureselliando 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 makeselliando 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
 

Plus de 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
 

Dernier

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 

Scaling Rails to 30,000 Users

  • 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/