SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
Scaling Rails Site
                by default
General Scaling

Scaling Rails Site :
	

 	

 	

 	

 Reading Material #1- #5

                 http://blog.xdite.net/?cat=91
•Client-side Performance
• Database Performance
• Rails Performance
Client-side Performance
150ms > 5ms
YSlow!
Cookie Free Domain
main site     http://www.example.org
static site   http://asset.example.org
main site        http://example.org
static site   http://example-static.org
config.action_controller.asset_host =
       “asset.example.org”
CDN
image_tag
http://asset.example.org/photos/small.jpg?1269316198
Parallel Download
config.action_controller.asset_host =
         “asset%d.example.org”
Minimal HTTP Request
<%= javascript_include_tag :default, :cache => true %>

<%=stylesheet_link_tag “main”, :cache => true %>




http://asset.example.org/javascripts/all.js?1269316198

http://asset.example.org/stylesheets/all.css?1269316198
Cache-Control
def index

	

 do_somthing
	

 expires_in 10.minutes

end



header[“Cache-Control”] = “max-age=600”
ETags
def show

	

 @user = User.find(params[:id])
	

 if stale?(:etag => @user)
	

 	

 @content = @user.very_expensive_call
	

 	

 respond_to do |format|
	

 	

 	

 formant.html.erb
	

 	

 end
	

 end
end


304 Not Modified
Last Modified
[‘Last-Modfield’]   [‘If-Modified-Since’]   304
def show

	

 @user = User.find(params[:id])
	

 if stale?(:last_modified => @user.updated_at )
	

 	

 @content = @user.very_expensive_call
	

 	

 respond_to do |format|
	

 	

 	

 formant.html.erb
	

 	

 end
	

 end
end


304 Not Modified
Database Performance
ADD INDEX
 EXPLAIN every query, avoid table scan
SELECT ONLY NEED
    use “scrooge” plugin replace SELECT *
Avoid N+1 Queries
       use :include => [ “comment”]
Use Counter Cache
           size, count , length
Use CONSTANT
   CONSTANT will cache in memory
Use Transaction
      BEGIN COMMIT is expensive
Ruby / Rails Performance
Writing Efficiently Ruby Code
          http://ihower.tw/blog/archives/1691
Avoiding creating unnecessary object
Avoiding writing stupid code
str + other_str => new_str




str = “a” + “b” + “c”

==>

str = “#{a}#{b}#{c}”
Array#join
tag_list = [“a”, “b”, “c”]

# rendering tags

tags = “”

tag_list.each do |t|
	

 tags +=”t”
	

 tags += “,”
end

===>

tags = tag_list.join(“,”)
tag_list = [“a”, “b”, “c”]            Array#each_with_index

# rendering tags

tags = “”
counter = 1

tag_list.each do |t|
	

 tags +=”counter”
	

 tags +=”t”
	

 tags += “,”
	

 counter +=1
end

===>
tag_list.each_with_index do |t , i|
Date.parse(“1992-02-13”)
          very expensive, should use regexp
Knowing Rails API
render :partial is slow
             Use Fragment Caching
Rails action is expensive
                   Use Rails Metal
Ruby API is slow
            use C extension
Conculsion
• Cache Everything
• Knowing API
• Drop in other language / system command
• Avoid hit DB
• Avoid hit Application
Thanks for listening

Weitere ähnliche Inhalte

Was ist angesagt?

Don't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHHDon't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHHtech.kartenmacherei
 
Creating asynchronous flows on AWS
Creating asynchronous flows on AWSCreating asynchronous flows on AWS
Creating asynchronous flows on AWSMetin Kale
 
3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster Frontends3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster FrontendsNico Hagenburger
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDBbenaldred
 
Yesplan: 10 Years later
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years laterPharo
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web ComponentsColdFusionConference
 
Serverless Ballerina
Serverless BallerinaServerless Ballerina
Serverless BallerinaBallerina
 
Symfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processingSymfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processingWojciech Ciołko
 
App engine beats pony.key
App engine beats pony.keyApp engine beats pony.key
App engine beats pony.keyAlper Çugun
 
Bigger Stronger Faster
Bigger Stronger FasterBigger Stronger Faster
Bigger Stronger FasterChris Love
 
RoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskytingRoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskyting信凱 王
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingEmanuele DelBono
 
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...Marc Müller
 
Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS Gabriel Gottgtroy Zigolis
 
Web Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your GooglejuiceWeb Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your GooglejuiceDave Cross
 

Was ist angesagt? (19)

Don't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHHDon't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHH
 
Creating asynchronous flows on AWS
Creating asynchronous flows on AWSCreating asynchronous flows on AWS
Creating asynchronous flows on AWS
 
3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster Frontends3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster Frontends
 
Big Frontends Made Simple
Big Frontends Made SimpleBig Frontends Made Simple
Big Frontends Made Simple
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
 
Yesplan: 10 Years later
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years later
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web Components
 
Serverless Ballerina
Serverless BallerinaServerless Ballerina
Serverless Ballerina
 
Symfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processingSymfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processing
 
App engine beats pony.key
App engine beats pony.keyApp engine beats pony.key
App engine beats pony.key
 
Bigger Stronger Faster
Bigger Stronger FasterBigger Stronger Faster
Bigger Stronger Faster
 
Easy REST with OpenAPI
Easy REST with OpenAPIEasy REST with OpenAPI
Easy REST with OpenAPI
 
RoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskytingRoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskyting
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Paperclip
PaperclipPaperclip
Paperclip
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
 
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP...
 
Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS
 
Web Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your GooglejuiceWeb Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your Googlejuice
 

Ähnlich wie Scaling Rails Sites by default

Using Amazon Simple Db With Rails
Using Amazon Simple Db With RailsUsing Amazon Simple Db With Rails
Using Amazon Simple Db With RailsAkhil Bansal
 
Aspnet2 Overview
Aspnet2 OverviewAspnet2 Overview
Aspnet2 Overviewajitbergi
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp ArchitectureMorgan Cheng
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Asher Martin
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...Amazon Web Services
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous MerbMatt Todd
 
Useful Rails Plugins
Useful Rails PluginsUseful Rails Plugins
Useful Rails Pluginsnavjeet
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QAAlban Gérôme
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapMarcio Marinho
 
Modular Web Applications With Netzke
Modular Web Applications With NetzkeModular Web Applications With Netzke
Modular Web Applications With Netzkenetzke
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizationsChris Love
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web PerformanceAdam Lu
 
Ruby Isn't Just About Rails
Ruby Isn't Just About RailsRuby Isn't Just About Rails
Ruby Isn't Just About RailsAdam Wiggins
 
Minimalism in Web Development
Minimalism in Web DevelopmentMinimalism in Web Development
Minimalism in Web DevelopmentJamie Matthews
 

Ähnlich wie Scaling Rails Sites by default (20)

Using Amazon Simple Db With Rails
Using Amazon Simple Db With RailsUsing Amazon Simple Db With Rails
Using Amazon Simple Db With Rails
 
Aspnet2 Overview
Aspnet2 OverviewAspnet2 Overview
Aspnet2 Overview
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
Rack
RackRack
Rack
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
Byte Sized Rust
Byte Sized RustByte Sized Rust
Byte Sized Rust
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ...
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Useful Rails Plugins
Useful Rails PluginsUseful Rails Plugins
Useful Rails Plugins
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QA
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
Modular Web Applications With Netzke
Modular Web Applications With NetzkeModular Web Applications With Netzke
Modular Web Applications With Netzke
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
 
Ruby Isn't Just About Rails
Ruby Isn't Just About RailsRuby Isn't Just About Rails
Ruby Isn't Just About Rails
 
Minimalism in Web Development
Minimalism in Web DevelopmentMinimalism in Web Development
Minimalism in Web Development
 

Mehr von Yi-Ting Cheng

Mehr von Yi-Ting Cheng (18)

2016 01 09 NPS - 63
2016 01 09 NPS - 632016 01 09 NPS - 63
2016 01 09 NPS - 63
 
2016 01 07-part2
2016 01 07-part22016 01 07-part2
2016 01 07-part2
 
2016 01 07 part 1
2016 01 07 part 12016 01 07 part 1
2016 01 07 part 1
 
Intro to Rails Workshop ( TA 須知 )
Intro to Rails Workshop ( TA 須知 )Intro to Rails Workshop ( TA 須知 )
Intro to Rails Workshop ( TA 須知 )
 
農家樂 Agricola
農家樂 Agricola農家樂 Agricola
農家樂 Agricola
 
莫拉克颱風災情支援網
莫拉克颱風災情支援網莫拉克颱風災情支援網
莫拉克颱風災情支援網
 
Rapid development with Rails
Rapid development with RailsRapid development with Rails
Rapid development with Rails
 
Upgrading to rails3
Upgrading to rails3Upgrading to rails3
Upgrading to rails3
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemShip It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
 
Sinatra Introduction
Sinatra IntroductionSinatra Introduction
Sinatra Introduction
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Ec2onrails
Ec2onrailsEc2onrails
Ec2onrails
 
Rails21v2
Rails21v2Rails21v2
Rails21v2
 
Pp6-xdite
Pp6-xditePp6-xdite
Pp6-xdite
 
Very Xd Hw9
Very Xd Hw9Very Xd Hw9
Very Xd Hw9
 
Very Xd
Very XdVery Xd
Very Xd
 
Happyweb8 Encode
Happyweb8 EncodeHappyweb8 Encode
Happyweb8 Encode
 
Happyweb8 Encode
Happyweb8 EncodeHappyweb8 Encode
Happyweb8 Encode
 

Scaling Rails Sites by default