Scaling Rails Sites by default

Yi-Ting Cheng
Yi-Ting ChengSenior Manager um HTC Corporation
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
Scaling Rails Sites by default
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
1 von 46

Recomendados

Ruby on Rails - UNISO von
Ruby on Rails - UNISORuby on Rails - UNISO
Ruby on Rails - UNISOLucas Renan
268 views57 Folien
Optimizing AngularJS Application von
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS ApplicationMd. Ziaul Haq
1.8K views45 Folien
Client Side Optimization von
Client Side OptimizationClient Side Optimization
Client Side OptimizationPatrick Huesler
1.7K views50 Folien
Put a Button on It: Removing Barriers to Going Fast von
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastOSCON Byrum
10.3K views97 Folien
Rapid Prototyping FTW!!! von
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
991 views63 Folien
3 ways-to-create-sprites-in-rails von
3 ways-to-create-sprites-in-rails3 ways-to-create-sprites-in-rails
3 ways-to-create-sprites-in-railsNico Hagenburger
9.4K views37 Folien

Más contenido relacionado

Was ist angesagt?

Don't Fear the Walking Dead @ PHPUGHH von
Don't Fear the Walking Dead @ PHPUGHHDon't Fear the Walking Dead @ PHPUGHH
Don't Fear the Walking Dead @ PHPUGHHtech.kartenmacherei
1.1K views34 Folien
Creating asynchronous flows on AWS von
Creating asynchronous flows on AWSCreating asynchronous flows on AWS
Creating asynchronous flows on AWSMetin Kale
61 views16 Folien
3 Steps to Make Better & Faster Frontends von
3 Steps to Make Better & Faster Frontends3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster FrontendsNico Hagenburger
4K views37 Folien
Big Frontends Made Simple von
Big Frontends Made SimpleBig Frontends Made Simple
Big Frontends Made SimpleNico Hagenburger
3.3K views51 Folien
Intro to CouchDB von
Intro to CouchDBIntro to CouchDB
Intro to CouchDBbenaldred
591 views38 Folien
Yesplan: 10 Years later von
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years laterPharo
2.5K views30 Folien

Was ist angesagt?(19)

Creating asynchronous flows on AWS von Metin Kale
Creating asynchronous flows on AWSCreating asynchronous flows on AWS
Creating asynchronous flows on AWS
Metin Kale61 views
3 Steps to Make Better & Faster Frontends von Nico Hagenburger
3 Steps to Make Better & Faster Frontends3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster Frontends
Nico Hagenburger4K views
Intro to CouchDB von benaldred
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
benaldred591 views
Yesplan: 10 Years later von Pharo
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years later
Pharo2.5K views
Serverless Ballerina von Ballerina
Serverless BallerinaServerless Ballerina
Serverless Ballerina
Ballerina98 views
Symfony bundle fo asynchronous job processing von Wojciech Ciołko
Symfony bundle fo asynchronous job processingSymfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processing
Wojciech Ciołko1.5K views
App engine beats pony.key von Alper Çugun
App engine beats pony.keyApp engine beats pony.key
App engine beats pony.key
Alper Çugun628 views
Bigger Stronger Faster von Chris Love
Bigger Stronger FasterBigger Stronger Faster
Bigger Stronger Faster
Chris Love465 views
RoR vs-nodejs-by-jcskyting von 信凱 王
RoR vs-nodejs-by-jcskytingRoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskyting
信凱 王432 views
Modern Perl Web Development with Dancer von Dave Cross
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
Dave Cross2.5K views
From ActiveRecord to EventSourcing von Emanuele DelBono
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
Emanuele DelBono11.1K views
DevDay 2017 - Automatisierte Release-Pipeline mit VSTS und Kubernetes für ASP... von Marc Müller
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üller69 views
Web Site Tune-Up - Improve Your Googlejuice von Dave Cross
Web Site Tune-Up - Improve Your GooglejuiceWeb Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your Googlejuice
Dave Cross1.1K views

Similar a Scaling Rails Sites by default

Using Amazon Simple Db With Rails von
Using Amazon Simple Db With RailsUsing Amazon Simple Db With Rails
Using Amazon Simple Db With RailsAkhil Bansal
988 views38 Folien
Aspnet2 Overview von
Aspnet2 OverviewAspnet2 Overview
Aspnet2 Overviewajitbergi
1.8K views66 Folien
Designing REST API automation tests in Kotlin von
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
3.1K views48 Folien
Rack von
RackRack
Rackshen liu
2.1K views57 Folien
Single Page WebApp Architecture von
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp ArchitectureMorgan Cheng
12.9K views61 Folien
Byte Sized Rust von
Byte Sized RustByte Sized Rust
Byte Sized RustSteve Hoffman
175 views75 Folien

Similar a Scaling Rails Sites by default(20)

Using Amazon Simple Db With Rails von Akhil Bansal
Using Amazon Simple Db With RailsUsing Amazon Simple Db With Rails
Using Amazon Simple Db With Rails
Akhil Bansal988 views
Aspnet2 Overview von ajitbergi
Aspnet2 OverviewAspnet2 Overview
Aspnet2 Overview
ajitbergi1.8K views
Designing REST API automation tests in Kotlin von Dmitriy Sobko
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
Dmitriy Sobko3.1K views
Rack von shen liu
RackRack
Rack
shen liu2.1K views
Single Page WebApp Architecture von Morgan Cheng
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng12.9K views
Cape Cod Web Technology Meetup - 2 von Asher Martin
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
Asher Martin283 views
Lightweight Webservices with Sinatra and RestClient von Adam Wiggins
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
Adam Wiggins24.1K views
Optimizing Lambda@Edge for Performance and Cost Efficiency (CTD405-R2) - AWS ... von Amazon Web Services
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 Services2.3K views
Adventurous Merb von Matt Todd
Adventurous MerbAdventurous Merb
Adventurous Merb
Matt Todd2K views
Useful Rails Plugins von navjeet
Useful Rails PluginsUseful Rails Plugins
Useful Rails Plugins
navjeet1.4K views
Killing the Angle Bracket von jnewmanux
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
jnewmanux2K views
Spicy javascript: Create your first Chrome extension for web analytics QA von Alban Gérôme
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
Alban Gérôme352 views
Ruby on Rails + AngularJS + Twitter Bootstrap von Marcio Marinho
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
Marcio Marinho3K views
Modular Web Applications With Netzke von netzke
Modular Web Applications With NetzkeModular Web Applications With Netzke
Modular Web Applications With Netzke
netzke1.1K views
JavaScript front end performance optimizations von Chris Love
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love862 views
Enhance Web Performance von Adam Lu
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
Adam Lu803 views
Ruby Isn't Just About Rails von Adam Wiggins
Ruby Isn't Just About RailsRuby Isn't Just About Rails
Ruby Isn't Just About Rails
Adam Wiggins6.3K views
Minimalism in Web Development von Jamie Matthews
Minimalism in Web DevelopmentMinimalism in Web Development
Minimalism in Web Development
Jamie Matthews3.2K views

Más de Yi-Ting Cheng

2016 01 09 NPS - 63 von
2016 01 09 NPS - 632016 01 09 NPS - 63
2016 01 09 NPS - 63Yi-Ting Cheng
1.2K views28 Folien
2016 01 07-part2 von
2016 01 07-part22016 01 07-part2
2016 01 07-part2Yi-Ting Cheng
1.6K views3 Folien
2016 01 07 part 1 von
2016 01 07 part 12016 01 07 part 1
2016 01 07 part 1Yi-Ting Cheng
2.6K views79 Folien
Intro to Rails Workshop ( TA 須知 ) von
Intro to Rails Workshop ( TA 須知 )Intro to Rails Workshop ( TA 須知 )
Intro to Rails Workshop ( TA 須知 )Yi-Ting Cheng
1.8K views18 Folien
農家樂 Agricola von
農家樂 Agricola農家樂 Agricola
農家樂 AgricolaYi-Ting Cheng
1.6K views42 Folien
莫拉克颱風災情支援網 von
莫拉克颱風災情支援網莫拉克颱風災情支援網
莫拉克颱風災情支援網Yi-Ting Cheng
1.3K views30 Folien

Scaling Rails Sites by default