Deploying Rails Applications


Published on

Covers the different options for scaling Rails applications, Nginx, a light weight HTTP server / reverse proxy, using Cron for periodic scheduled task, and Monit for monitoring rails applications.

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Deploying Rails Applications

    1. 1. Deploying Rails Applications Vivek Prahlad
    2. 2. Agenda <ul><ul><li>Typical Rails deployment scenarios </li></ul></ul><ul><ul><li>Mongrel </li></ul></ul><ul><ul><li>Nginx vs. Apache vs. Lighttpd </li></ul></ul><ul><ul><li>Shared vs. Virtual vs. Dedicated hosting </li></ul></ul><ul><ul><li>Monitoring Rails Applications </li></ul></ul>
    3. 3. Typical Rails Deployment Setup Web Server (Static Content)‏ Rails App (Mongrel)‏ Database (MySQL / PostgreSQL)‏
    4. 4. Lots of Static content? Web Server (Static Content)‏ Rails App (Mongrel)‏ Database )‏ (MySQL / PostgreSQL)‏ Load Balancer Cluster
    5. 5. Heavy database load? Web Server (Static Content)‏ Rails App (Mongrel)‏ Database (MySQL / PostgreSQL)‏ Cluster
    6. 6. Very dynamic application? Web Server (Static Content)‏ Rails App (Mongrel)‏ Database (MySQL / PostgreSQL)‏ Cluster
    7. 7. Installing the stack using Deprec <ul><ul><li>cd /path/to/railsapp </li></ul></ul><ul><ul><li>deprec --apply-to . --name projectname --domain </li></ul></ul><ul><ul><li># edit config/deploy.rb to add svn details </li></ul></ul><ul><ul><li>cap install_rails_stack </li></ul></ul><ul><ul><li>cap setup </li></ul></ul><ul><ul><li>cap deploy_with_migrations </li></ul></ul><ul><ul><li>cap restart_apache </li></ul></ul>
    8. 8. Mongrel
    9. 9. Mongrel <ul><ul><li>Pure Ruby web server for Ruby applications </li></ul></ul><ul><ul><li>Supports Rails, Camping, Og + Nitro </li></ul></ul><ul><ul><li>Need a cluster due to Rails threadsafety issue </li></ul></ul><ul><ul><li>Significant footprint increase with Rails 1.2 </li></ul></ul><ul><ul><ul><li>Approximately 60MB / Mongrel / Mephisto instance </li></ul></ul></ul><ul><ul><li>Dash B logging for detecting memory leaks </li></ul></ul>
    10. 11. Nginx <ul><ul><li>Web server from Igor Sysoev: best used as a reverse proxy </li></ul></ul><ul><ul><li>Rapidly becoming preferred choice of Rails community </li></ul></ul><ul><ul><li>10MB footprint with 10,000 concurrent connections </li></ul></ul><ul><ul><li>Load balancing </li></ul></ul><ul><ul><li>Weighted load balancing </li></ul></ul><ul><ul><li>Relatively straightforward configuration </li></ul></ul>
    11. 12. Nginx vs. Apache <ul><ul><li>Apache: Relatively Larger footprint </li></ul></ul><ul><ul><li>Thread per request </li></ul></ul><ul><ul><li>Nginx: Low footprint </li></ul></ul><ul><ul><li>Non blocking IO </li></ul></ul>
    12. 13. Issues with Lighttpd <ul><ul><li>Stability </li></ul></ul><ul><ul><li>Memory leaks </li></ul></ul><ul><ul><li>Non-trivial URL rewriting </li></ul></ul>
    13. 14. Nginx: configuring mongrel <ul><ul><li>upstream mongrel { </li></ul></ul><ul><ul><li>server; </li></ul></ul><ul><ul><li>server; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>proxy_pass http://mongrel; </li></ul></ul>
    14. 15. Nginx: load balancing <ul><ul><li>upstream backend { </li></ul></ul><ul><ul><li>server weight=5; </li></ul></ul><ul><ul><li>server; </li></ul></ul><ul><ul><li>server unix:/tmp/backend3; </li></ul></ul><ul><ul><li>} </li></ul></ul>
    15. 16. Nginx: Caveats <ul><ul><li>Primary documentation in Russian </li></ul></ul><ul><ul><ul><li>(Documentation is rapidly improving, though)‏ </li></ul></ul></ul><ul><ul><li>No X-sendfile support (useful for serving large files)‏ </li></ul></ul><ul><ul><li>Virtual host support poor </li></ul></ul>
    16. 17. Rails Hosting <ul><ul><li>Rails 1.2+ unsuitable for shared hosting </li></ul></ul><ul><ul><li>Most shared hosts have published / unpublished memory caps </li></ul></ul><ul><ul><ul><li>Textdrive: 47 MB per process </li></ul></ul></ul><ul><ul><li>Dedicated hosting expensive </li></ul></ul><ul><ul><ul><li>Starts at ~ $70 per month (e.g. ServerPronto)‏ </li></ul></ul></ul>
    17. 18. Virtual Private Server (VPS) Hosting <ul><ul><li>Fits in between Shared and Dedicated hosting </li></ul></ul><ul><ul><li>Nice performance / price ratio (starts @ $20 / month)‏ </li></ul></ul><ul><ul><li>Can potentially exploit superior hardware </li></ul></ul><ul><ul><li>Alternatives: </li></ul></ul><ul><ul><ul><li>Xen </li></ul></ul></ul><ul><ul><ul><li>Virtuzzo </li></ul></ul></ul><ul><ul><li>Baked in kernel level virtualization support is coming </li></ul></ul><ul><ul><li>Caveat: Need to manage your own setup </li></ul></ul>
    18. 19. Advantages of VPS hosting <ul><ul><li>Entire CPU available when other users are idle. </li></ul></ul><ul><ul><li>Disk I/O usually faster than dedicated box (due to RAID etc.)‏ </li></ul></ul><ul><ul><li>Can take advantage of SANs if required. </li></ul></ul><ul><ul><li>Hosting company takes care of the VPS server </li></ul></ul><ul><ul><li>Fairly easy to scale VPS setup (just add more VMs)‏ </li></ul></ul>
    19. 20. Monitoring Rails applications <ul><ul><li>Monit (‏ </li></ul></ul><ul><ul><li>Process monitoring tool </li></ul></ul><ul><ul><li>Can monitor: </li></ul></ul><ul><ul><ul><li>HTTP server </li></ul></ul></ul><ul><ul><ul><li>Processes </li></ul></ul></ul><ul><ul><ul><li>Databases (MySQL and PostgreSQL)‏ </li></ul></ul></ul>
    20. 21. Cron Jobs <ul><ul><li>Clear stale sessions </li></ul></ul><ul><ul><li>Database maintenance </li></ul></ul><ul><ul><li>Clear logs </li></ul></ul><ul><ul><li>Best practice: get Cron to call out to a script </li></ul></ul><ul><ul><li>Don't hardcode commands in the crontab </li></ul></ul><ul><ul><li>Makes it easy to test </li></ul></ul>
    21. 22. Putting it all together <ul><ul><li>Can use Monit to create 'self healing' setup </li></ul></ul><ul><ul><li>PostgresQL </li></ul></ul><ul><ul><li>Nginx </li></ul></ul><ul><ul><li>Mongrel </li></ul></ul><ul><ul><li>Cron </li></ul></ul>
    22. 23. <ul><ul><li> </li></ul></ul><ul><ul><li> (performance tuning)‏ </li></ul></ul><ul><ul><li> (blog on hosting)‏ </li></ul></ul><ul><ul><li> (scaling Rails)‏ </li></ul></ul>Additional Information
    23. 24. Thank You
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.