Rails Performance
    When, What and How




                  Vitaly Kushner
                    @vkushner
Vitaly Kushner
programming since middle 80s
 professionally since early 90s
       Rails since 2005
   founded Astrails in 2008
http://astrails.com/blog
performance
slow
for whatever reason
performance
performance

• raw speed
• throughput
• scalability
• end-user
No time
to dive into details
When to optimize?
     and when not to.
what to do with 1M
       users
Celebrate!
 you’ve made it.
why startups fail?
NOT because of
performance problems
1 million users
first 1000 users!
have scalability
   problem?
GREAT!
because it means you grow fast
later
Scalability Plan


• understand the limits
• know your next step
performance
  does it matter?
YES!
performance is very important
Is 1% a lot?
yes, if you are Google.
Why not to optimize
     anyway?
time and budget
    usually limited
Measure
You can not improve what you do not measure.
Tools
• Yahoo Yslow
  http://developer.yahoo.com/yslow/


• Google PageSpeed
  https://developers.google.com/speed/pagespeed


• NewRelic -     http://newrelic.com


• httperf & ab
• Blitz.io
limit number of records
       from the database
oink
https://github.com/noahd1/oink
Instantiation Breakdown: Total: 14 |
User: 4 | Experience: 3 | Location: 3 |
Interest: 3 | Admin: 1
limit number of queries
     prevent 1+N queries problem
bullet
https://github.com/flyerhzm/bullet
N+1 Query detected
Experience => [:interest]
Add to your finder: :include => [:interest]
define indexes
   can be done later
query_reviewer
https://github.com/nesquena/query_reviewer
limit number of http
       requests
        consolidate assets
   assets pipeline makes it easy
css at the top
js at the bottom
 improves perceived page speed
low level hacks


• replace :include with :join
• explicit :select
not recommened
Maintainability
 usually better then speed
low hanging fruits

• compress and http cache assets
• CDN libraries
• image sprites
• bundle images into CSS
• CDN for all static assets
Caching
 much later
real performance
    problem?
next time...
Thank you!
Slides and video will be published at
      http://astrails.com/blog




                         Vitaly Kushner
                           @vkushner

Performance - When, What and How