Performance on Rails

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Performance on Rails - Presentation Transcript

    1. Ruby on Rails Performance Tips Barcamp Coimbra 2008 Pedro Sousa
    2. Your application is slow
    3. Caching in RoR
    4. Before you begin You need to define where to place your cache (db, memory, file) You need to tweak you development environment to test caching
    5. Setup up your environment > Rails 2.1 <= Rails 2.0
    6. Types of Cache Store
    7. Setup up your environment development.rb
    8. 3 Types of Caching Page Caching will always use File Store Action Caching & Fragment Caching Will use the cache store you defined
    9. Page Caching Transforms your views into pure HTML Best for pages with common content for all your users or very static pages
    10. Example
    11. Action Caching Works the same as way as page caching ... but goes through dispatcher to run filters and callbacks For example you can use it with pages that require authentication
    12. Example
    13. More options
    14. Fragment Caching More flexible Great for dynamic content directed at specific users or conditions (ex: your friends latest blog posts) Transforms portions of your views into rendered HTML
    15. Examples of Caching
    16. Example No caching
    17. Fragment Caching
    18. Oops, I forgot about the controller
    19. the fragment
    20. Cleaning up individual cache files
    21. Cleaning up (brute force)
    22. Cleaning up with memcached soon...
    23. DB Model Cache It’s built into Rails, you don’t have to do nothing good for not making the same query twice limited... only works on the same request
    24. DB Cache (stupid) example
    25. Memcached New in Rails 2.0 Simple to use It’s like a Hash in memory, has a key/value way of working
    26. Methods Rails.cache.read Rails.cache.write Rails.cache.fetch Rails.cache.delete Rails.cache.exist? Rails.cache.increment Rails.cache.decrement
    27. example
    28. example with data Model Controller
    29. example with data View (first time) View (second time, it’s read from the cache)
    30. More info on caching http://www.railsenvy.com/2007/2/28/rails-caching- tutorial http://railscasts.com/episodes/115 http://www.thewebfellas.com/blog/2008/6/9/rails-2-1- now-with-better-integrated-caching http://www.akitaonrails.com/2008/5/25/rolling-with- rails-2-1-the-first-full-tutorial-part-1
    31. Tips for Optimization
    32. Write Eficient SQL Queries Bring only what you need
    33. Eager Loading Sometimes it’s best to bring all data at once Prevents N+1 problem Optimized Eager Loading in Rails 2.1
    34. Create indexes on DB It really makes a difference Don’t exagerate
    35. Use Transactions Group Transactions when possible Minimizes errors Less effort on the Database
    36. Reduce http requests Too many javascript and css files makes your page slow You can package all you files into only one
    37. Solutions Built-in mechanism in Rails 2.0 but without js minification Alternative plugin - Bundle-FU http://code.google.com/p/bundle-fu/
    38. Bundling Example Before/After
    39. Too many images? Use CSS Sprites Technique Less http requests More hard to manage
    40. References about CSS Sprites http://css-tricks.com/css-sprites-what-they-are-why- theyre-cool-and-how-to-use-them/ http://www.alistapart.com/articles/sprites
    41. Tools
    42. Firebug & Yslow Track your page performance Easy to install and run Download from http://developer.yahoo.com/yslow/
    43. Examples
    44. More examples
    45. TextMate Footnotes Useful plugin for Rails Download from http://github.com/drnic/rails-footnotes/ tree/master
    46. Other Small Tips Use LibXML-Ruby for processing XML: http://libxml.rubyforge.org/ Log only what you need Use a CDN (ex: Amazon CloudFront) Patch the RUBY GC: http://rubyforge.org/projects/railsbench/
    47. That’s it! Have fun! Don’t be afraid to experiment! Tweak until your satisfied! If all fails, invest in hardware. :)
    48. The End
    49. Thank you Pedro Sousa [blog] http://www.reinventar.com [work] http://www.thinkorange.pt [linkedin] http://www.linkedin.com/psousa

    + Pedro  SousaPedro Sousa, 2 years ago

    custom

    1569 views, 4 favs, 0 embeds more stats

    Presentation about the several caching mecanisms in more

    More info about this document

    CC Attribution License

    Go to text version

    • Total Views 1569
      • 1569 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 40
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories