Top Banner
Real World Rails Deployment Alan Hecht
21

Real World Rails Deployment

May 15, 2015

Download

Technology

Alan Hecht

ATLRUG Emerald City presentation given on June 16, 2012
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Real World Rails Deployment

Real WorldRails Deployment

Alan Hecht

Page 2: Real World Rails Deployment

Deployment Options

• Heroku - PaaS

• Shared Web Hosting

• Virtual Private Server

• Amazon Web Services - IaaS

Page 3: Real World Rails Deployment

Heroku - PaaS

• No setup & no system administration- Easy to deploy

• Free when using one web process- Pay as you scale

• App will idle after inactivity if only using one process (“dyno”)

• Additional “dyno” + database > 5MB is $50/month

Page 4: Real World Rails Deployment

Shared Web Hosting

• Cheap - $5 to $10 per month

• Web hosting control panel (i.e. cPanel) to configure web server & web application

• Limited to what is on the server

• Not recommended- Constrained by CPU usage

Page 5: Real World Rails Deployment

Virtual Private Server

• Starts at around $25 per month

• Extremely flexible, can load anything you want

• System administration knowledge required- Must maintain server

• Good for one or two standalone servers

Page 6: Real World Rails Deployment

Amazon Web Services - IaaS

• Building a virtual data center• Netflix runs on AWS

• Can load instances with a pre-built O/S

• Pay as you scale

• Most expensive option

Page 7: Real World Rails Deployment

Running Rails

• WEBrick should only be used in a development environment

• Need a web server to handle static requests- Images, HTML, JavaScript, CSS

• Need a Ruby web application server to handle Rails requests (i.e. Unicorn, Thin, or Passenger)

Page 8: Real World Rails Deployment

Web Server

• Apache & Nginx the two most popular choices

• Rack is used as an interface between the web server and Rails

Page 9: Real World Rails Deployment

Apache

• Most popular web server and has the many options & features

• Process-based web server

• Good for handling dynamic content via modules

Page 10: Real World Rails Deployment

Nginx

• Light weight web server that only handles static content

• Event-based web server

• Low memory usage

Page 11: Real World Rails Deployment

Apache or Nginx

• Pick one - either works

• Nginx better on a VPS because of low memory usage

• Apache is full-featured

• Nginx does a few things well

Page 12: Real World Rails Deployment

Rails Web App Servers

• Phusion Passenger, Thin, and Unicorn currently the most widely used Rails app servers

• Can be installed as a web server plugin or as a separate Ruby Gem

Page 13: Real World Rails Deployment

Phusion Passenger

• Acts as an Apache or Nginx module

• Philosophy – same as Rails (DRY, convention over configuration)

• Easy to deploy & maintain- No separate configuration file

Page 14: Real World Rails Deployment

Thin

• Event based Rails server

• Philosophy – tiny, fast, and secure

• Used by Heroku

Page 15: Real World Rails Deployment

Unicorn

• Process-based Rails server

• Philosophy – Unicorn is Unix

• Used by Twitter & GitHub

Page 16: Real World Rails Deployment

Nginx + Unicorn Architecture

Page 17: Real World Rails Deployment

Sample Nginx Configuration

Page 18: Real World Rails Deployment

Which One?

• People have built scalable sites with all three

• Thin & Unicorn need configuration, Passenger does not

• Performance depends on the application- “Hello World” apps not useful for profiling

Page 19: Real World Rails Deployment

Capistrano

•Tool for deploying Rails (or Rack) applications

•Similar in structure to Rakefile

Page 20: Real World Rails Deployment

Sample Capistrano Script

Page 21: Real World Rails Deployment

What Does a Scalable Site Architecture Look Like?

Content Delivery Network

Nginx SSL

HA Proxy

Nginx +Unicorn

Nginx +Unicorn

Nginx +Unicorn