deploying and monitoring rails

193
Deploying and Monitoring Ruby on Rails A practical guide Mathias Meyer and Jonathan Weiss, 25.05.2009 Peritor GmbH

Upload: jonathan-weiss

Post on 06-May-2015

11.652 views

Category:

Technology


4 download

DESCRIPTION

While it’s easy to get started developing applications using Ruby on Rails, the hard part is (as with most technologies) how to put it into production? There are a lot of options like Mongrel, nginx, Apache and JRuby, all of them difficult to evaulate without deeper knowledge of Rails and your application’s scaling needs. We will look at the available options to get a clearer picture how each setup is in different situations, and how you can utilize Capistrano for an easy deployment process in those situations. Simple as well as more complex setups will be discussed. We’ll try to include your problems as well as your experiences to discuss specific issues with deployment and scalability.

TRANSCRIPT

Page 1: Deploying And Monitoring Rails

Deploying and Monitoring

Ruby on Rails A practical guide

Mathias Meyer and Jonathan Weiss, 25.05.2009

Peritor GmbH

Page 2: Deploying And Monitoring Rails

2

Who are we?

Jonathan Weiss

•  Consultant for Peritor GmbH in Berlin

•  Specialized in Rails, Scaling, Deployment, and Code Review

•  Webistrano - Rails deployment tool

•  FreeBSD Rubygems and Ruby on Rails maintainer

http://www.peritor.com

http://blog.innerewut.de

Page 3: Deploying And Monitoring Rails

3

Who are we?

Mathias Meyer

•  Consultant for Peritor GmbH in Berlin

•  Specialized in Rails, Performance/Database Tuning, Deployment, and Refactoring

•  Maintainer of Macistrano – Webistrano-Client for Mac OS X (and soon the iPhone), run_later and acts_as_solr

http://www.paperplanes.de

Page 4: Deploying And Monitoring Rails

4

Agenda

Infrastructure Deployment Monitoring Q & A Practical Session

Page 5: Deploying And Monitoring Rails

5

Infrastructure Infrastructure

Page 6: Deploying And Monitoring Rails

6

Simple Rails Setup

One Rails instance handles all requests

Rails is single-threaded: There is only one concurrent request

Page 7: Deploying And Monitoring Rails

7

Rails Setup

Page 8: Deploying And Monitoring Rails

8

Rails Setup

Page 9: Deploying And Monitoring Rails

9

Typical Rails Setup

•  A load-balancer distributes the incoming requests

•  Some load-balancers will deliver static requests themselves

•  Several Rails instances handle all requests

•  Number of concurrent requests equals number of Rails instances

Page 10: Deploying And Monitoring Rails

10

Rails Setup Options

Page 11: Deploying And Monitoring Rails

11

Deployment Questions

Mongrel?

Apache?

Ebb?

FastCGI?

mod_rails?

Thin?

Nginx?

Lighttpd?

Pound? mod_proxy_balancer?

HA-Proxy?

Phusion Passenger?

Load-balancer? Proxy?

Rails Application Server?

Swiftiply? Reverse Proxy?

Pen?

Page 12: Deploying And Monitoring Rails

12

What we are going to cover today

Rails Application Server

•  FastCGI

•  Mongrel

•  mod_rails / Phussion Passenger

•  JRuby + Glassfish & Co.

Proxy/Web Server

•  Apache2

•  Nginx

•  Lighttpd

•  HA-Proxy

Page 13: Deploying And Monitoring Rails

13

FastCGI

Page 14: Deploying And Monitoring Rails

14

FastCGI

•  Protocol to communicate with long-running CGI applications

•  Usage of either mod_fcgi with Apache 1.3 or mod_fcgi with Lighttpd

•  Proxy local and remote FastCGI instances

•  Oldest way of deploying Rails

•  Deprecated and unstable

•  Hard to debug (FastCGI protocol)

Page 15: Deploying And Monitoring Rails

15

FastCGI

Page 16: Deploying And Monitoring Rails

16

FastCGI

Page 17: Deploying And Monitoring Rails

17

Page 18: Deploying And Monitoring Rails

18

Mongrel

Page 19: Deploying And Monitoring Rails

19

Mongrel

•  Developed by Zed Shaw as an alternative to FastCGI

•  Complete HTTP-Server that can load arbitrary Ruby-servlets

•  Built-in Rails support

Page 20: Deploying And Monitoring Rails

20

Mongrel

Page 21: Deploying And Monitoring Rails

21

Mongrel

Apache 2.2 – mod_proxy_balancer Lighttpd Nginx HA-Proxy Pound

Page 22: Deploying And Monitoring Rails

22

Mongrel Cluster

Utility to manage several Mongrel instances

Page 23: Deploying And Monitoring Rails

23

Mongrel Cluster

Control Mongrels

Page 24: Deploying And Monitoring Rails

24

Mongrel and Apache 2.2

Define Mongrel Cluster in Apache

Page 25: Deploying And Monitoring Rails

25

Simple Mongrel and Apache 2.2

Redirect all traffic to the Mongel cluster

Page 26: Deploying And Monitoring Rails

26

A more complex example

•  Redirect dynamic requests

•  Serve static content

•  Support cached pages

•  Support maintenance page

•  Enable client-side caching of images, stylesheets, and JavaScript

•  Compress output if supported

Page 27: Deploying And Monitoring Rails

27

Mongrel

•  Very robust

•  Strict HTTP parser

•  Easy to debug (HTTP!)

•  Used to be defacto deployment setup with Apache 2.2 and mod_proxy_balancer

•  Can be a bit difficult to setup (mongrel_cluster, ports, Apache)

•  Not so easy on mass/virtual hosting

Page 28: Deploying And Monitoring Rails

28

mod_rails

Page 29: Deploying And Monitoring Rails

29

mod_rails a.k.a Phusion Passenger

•  Module for Apache 2.2 (and Nginx)

•  Allows Apache to control Rails instances

•  Apache starts and stops application instances depending on the application load

•  Able to run any Rack-compatible Ruby application (Merb, Sinatra & Co.)

•  Only manages Rails on one host - no remote instances

•  Combine with HTTP-Proxy / balancing solution

Page 30: Deploying And Monitoring Rails

30

Install Phusion Passenger

Install Apache module

Load and activate in Apache

Page 31: Deploying And Monitoring Rails

31

Install Phusion Passenger

Install Passenger with nginx (installs custom nginx)

Configure nginx

Page 32: Deploying And Monitoring Rails

32

Customized Phusion Passenger

Control Rails instance number

Page 33: Deploying And Monitoring Rails

33

Control Phusion Passenger

Restart after deployment:

Page 34: Deploying And Monitoring Rails

34

Phusion Passenger

One machine

Page 35: Deploying And Monitoring Rails

35

Phusion Passenger

One machine Multiple machines

Page 36: Deploying And Monitoring Rails

36

Phusion Passenger

•  Ready for production

•  Makes setup easier – on the single machine level

•  Multiple servers still require load balancer

•  Suitable for mass-hosting

•  upcoming standard way of deploying Rails

Page 37: Deploying And Monitoring Rails

37

JRuby

Page 38: Deploying And Monitoring Rails

38

•  Ruby Runtime on the Java Virtual Machine

•  Implemented in Java and Ruby

•  Compiles Ruby into Java-bytecode

•  Integrates with Java code and libraries

•  Java’s promises of native threads and JIT

•  Allows for Ruby/Rails applications to be packaged as WAR files

•  WAR files deployable on any J2EE-container: Glassfish, JBoss, Tomcat, Jetty, …

Page 39: Deploying And Monitoring Rails

39

JRuby on Rails

Page 40: Deploying And Monitoring Rails

40

JRuby on Glassfish

One machine

Page 41: Deploying And Monitoring Rails

41

JRuby on Glassfish

One machine Multiple machines

Page 42: Deploying And Monitoring Rails

42

Setup JRuby on Glassfish

1.  Download JRuby and Glassfish

2.  From http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html

Page 43: Deploying And Monitoring Rails

43

Warble Configuration

Define min/max Rails runtimes

Page 44: Deploying And Monitoring Rails

44

Glassfish for development

Shrunk-down version of Glassfish v3 - packaged as a gem

Can run any Rack-based application

Installation:

•  $ jruby -S gem install glassfish

•  $ glassfish

•  There is no Step 3

Page 45: Deploying And Monitoring Rails

45

Rails Setup

Page 46: Deploying And Monitoring Rails

46

Proxy Options

Page 47: Deploying And Monitoring Rails

47

Proxy Requirements

•  Hide cluster backend from the user

•  Load-balancer backend instances

•  Recognize down hosts

•  Fair scheduler

•  (Deliver static content)

Page 48: Deploying And Monitoring Rails

48

Apache 2.2

•  Apache 2.2 introduced mod_proxy_balancer

•  mod_proxy_balancer can speak to multiple backends and balance requests

•  Apache can acts as a pure proxy or can also serve static files

Page 49: Deploying And Monitoring Rails

49

Apache 2.2

•  Apache 2.2 introduced mod_proxy_balancer

•  mod_proxy_balancer can speak to multiple backends and balance requests

•  Apache can acts as a pure proxy or can also serve static files

Page 50: Deploying And Monitoring Rails

50

Apache 2.2

•  Apache 2.2 introduced mod_proxy_balancer

•  mod_proxy_balancer can speak to multiple backends and balance requests

•  Apache can acts as a pure proxy or can also serve static files

Page 51: Deploying And Monitoring Rails

51

Apache 2.2

Pro

•  Stable, robust, and mature

•  Many people know how to work with Apache

•  Integrates well with other modules (SVN, DAV, Auth, …)

Con

•  Apache can be complicated to configure

•  The stock Apache is quite resource-hungry compared to pure proxy solutions

Page 52: Deploying And Monitoring Rails

52

Nginx – From Russia with love

•  Nginx - popular Russian webserver with good proxy support

•  Can load-balance multiple backends and deliver static content

•  Quite popular with Mongrel as the Rails backend

•  Recent Passenger support

Page 53: Deploying And Monitoring Rails

53

Nginx Configuration

Simple proxy example

Get complete version here:

http://brainspl.at/nginx.conf.txt

Page 54: Deploying And Monitoring Rails

54

Nginx

Pro

•  Stable, robust, and fast

•  Uses fewer resources (CPU and RAM) than Apache for proxy-mode and static files

•  Simpler configuration file

•  Can directly talk to memcached - SSI

Con

•  More documentation would be nice

•  No equivalent for many Apache modules

Page 55: Deploying And Monitoring Rails

55

Lighttpd

•  Lightweight and fast webserver

•  Balancing proxy support

•  Good FastCGI support

•  Used to be popular – until Mongrel came around

Page 56: Deploying And Monitoring Rails

56

Lighttpd Configuration

Simple proxy example

Page 57: Deploying And Monitoring Rails

57

Lighttpd

Pro

•  Fast and lightweight

•  Uses fewer resources (CPU and RAM) than Apache for proxy-mode and static files

•  Simpler configuration file

Con

•  Unstable for some people

•  Slow development cycle

•  More documentation would be nice

•  Configuration file can be too simple (virtual host aliasing)

•  No equivalent for many Apache modules

•  (No Passenger support)

Page 58: Deploying And Monitoring Rails

58

HA-Proxy

•  HAProxy – reliable, high performance TCP/HTTP load balancer

•  Proxying and content inspection

•  No content serving, just a proxy

•  Mature proxy module (fair scheduler)

•  ACL support

See also similar Pound and Pen

Page 59: Deploying And Monitoring Rails

59

HAProxy

Simple proxy example

Page 60: Deploying And Monitoring Rails

60

HAProxy

Pro

•  Mature, stable, robust, and fast

•  TCP and HTTP balancing

Con

•  Few Rails examples

•  Usually not needed in a Rails setup

Page 61: Deploying And Monitoring Rails

61

Recommended Setups

Page 62: Deploying And Monitoring Rails

62

Small Site

Recommendation

Apache 2.2 with mod_rails / Phusion Passenger

Page 63: Deploying And Monitoring Rails

63

Medium Site

Recommendation

•  Apache/Nginx as the frontend proxy

•  Passenger/mod_rails as the backend

•  Deliver static files with Apache

Page 64: Deploying And Monitoring Rails

64

Large Rails Setup

Recommendation

•  Redundant load-balancer

•  Redundant proxy / web

•  Passenger/mod_rails

Page 65: Deploying And Monitoring Rails

65

Heavy Static Files

Recommendation

•  Deliver static assets through separate web server farm

•  Passenger/mod_rails

Page 66: Deploying And Monitoring Rails

66

Java Shop

Recommendation

•  Deliver a Rails-WAR file and you are done

•  Integrate with existing Java landscape and infrastructure

Page 67: Deploying And Monitoring Rails

67

Page 68: Deploying And Monitoring Rails

68

Application Server Handler

Page 69: Deploying And Monitoring Rails

69

Application Server Handler

Page 70: Deploying And Monitoring Rails

70

Application Server Handler

Page 71: Deploying And Monitoring Rails

71

Rack

Page 72: Deploying And Monitoring Rails

72

Rack Handler

Page 73: Deploying And Monitoring Rails

73

Rack

Page 74: Deploying And Monitoring Rails

74

Rack Middleware

Page 75: Deploying And Monitoring Rails

75

Rack Middleware

•  Authentication (HTTP, OpenID)

•  Sessions

•  Routing

•  Caching

•  Logging

•  Debugging

Page 76: Deploying And Monitoring Rails

76

Support

Frameworks

•  Rails

•  Merb

•  Camping

•  Sinatra

•  Mack

•  Maveric

•  Halcyon

•  Ramaze

•  Rum

•  Vintage

•  Waves

Web Server

•  CGI

•  FastCGI

•  Mongrel

•  Phusion Passenger

•  JRuby Servlets

•  WEBrick

•  Ebb

•  Thin

•  LiteSpeed

•  Swiftcore

•  Unicorn

Page 77: Deploying And Monitoring Rails

77

Remarks

Page 78: Deploying And Monitoring Rails

78

Ruby Enterprise Edition

•  Copy-On-Write patches to Ruby 1.8

•  Saves memory when spawning several Rails instances

•  Used by Phusion Passenger if available

Page 79: Deploying And Monitoring Rails

79

Thin, Ebb, Evented Mongrel & Co.

•  Alternatives to Mongrel

•  Claim to be faster, lighter, and what have you

•  Rendering “Hello World” is usually not your bottleneck

Stick with stable and robust Mongrel, or better yet, with Passenger

Page 80: Deploying And Monitoring Rails

80

Infrastructure Deployment

Page 81: Deploying And Monitoring Rails

81

Page 82: Deploying And Monitoring Rails

82

Deployment Options

Page 83: Deploying And Monitoring Rails

83

Deployment Options

Page 84: Deploying And Monitoring Rails

84

Deployment Options

Page 85: Deploying And Monitoring Rails

85

Deployment Options

Page 86: Deploying And Monitoring Rails

86

What does Capistrano do?

Page 87: Deploying And Monitoring Rails

87

Capistrano Deployment Cycle

Page 88: Deploying And Monitoring Rails

88

Requirements

Page 89: Deploying And Monitoring Rails

89

What doesn’t Capistrano do?

•  Plan your initial server setup

•  Configure basic services

Page 90: Deploying And Monitoring Rails

90

Basic Ingredients

•  The cap command

•  Variables

•  Roles

•  Tasks

•  Namespaces

Page 91: Deploying And Monitoring Rails

91

Basic Ingredients - cap

Your one-stop deployment shop

Page 92: Deploying And Monitoring Rails

92

Basic Ingredients - Variables

•  Configure basic project information

•  Override Capistrano’s default assumptions

•  Once set, variables are available globally

•  Defined using the set method

Page 93: Deploying And Monitoring Rails

93

Basic Ingredients - Roles

•  Define types of servers

•  Default roles

•  :www

•  :app

•  :db

•  All can point to the same server

•  But all three must be defined

•  At least one database server needs to be primary

Page 94: Deploying And Monitoring Rails

94

Basic Ingredients - Roles

Define custom roles as you please

Can be reused when defining tasks

Page 95: Deploying And Monitoring Rails

95

Basic Ingredients - Tasks

•  Define an atomic set of actions for Capistrano

•  Can be called from the command line

•  Or other tasks

Page 96: Deploying And Monitoring Rails

96

Basic Ingredients - Tasks

To find all the tasks available in your project, use

Page 97: Deploying And Monitoring Rails

97

Basic Ingredients - Namespaces

Group tasks together logically

Namespaces and tasks are separated with “:”

Page 98: Deploying And Monitoring Rails

98

Get Your Capistrano On

Page 99: Deploying And Monitoring Rails

99

Get Your Capistrano On

Capfile, the place to include more recipes

Page 100: Deploying And Monitoring Rails

100

Get Your Capistrano On

config/deploy.rb, application specific configuration

Page 101: Deploying And Monitoring Rails

101

Capistrano’s Defaults

•  Your SCM is Subversion

•  Deployment directory is /u/apps/#{application_name}

•  User for SCM and SSH is the currently logged-in user

•  Commands are run with sudo

Page 102: Deploying And Monitoring Rails

102

Get Your Capistrano On

Page 103: Deploying And Monitoring Rails

103

Get Your Capistrano On

•  Capistrano expects a directory structure

•  Can be created with cap deploy:setup

Page 104: Deploying And Monitoring Rails

104

The Deployment Lifecycle

Page 105: Deploying And Monitoring Rails

105

The Deployment Lifecycle

Check the prerequisites:

Page 106: Deploying And Monitoring Rails

106

The Deployment Lifecycle

Set up your application for the first time

Page 107: Deploying And Monitoring Rails

107

The Deployment Lifecycle

The initial deployment

1.  Checks the revision from the local machine

2.  Checks out the code on the remote machines

3.  Sets a link called current pointing to the lates release

4.  Runs the migrations

5.  Fires up application servers

Page 108: Deploying And Monitoring Rails

108

The Deployment Lifecycle

Page 109: Deploying And Monitoring Rails

109

The Deployment Lifecycle

Subsequent deployments

1.  Checks the revision from the local machine

2.  Checks out the code on the remote machines

3.  Updates current link

4.  Restarts application servers

Page 110: Deploying And Monitoring Rails

110

The Deployment Lifecycle

Page 111: Deploying And Monitoring Rails

111

Common Capistrano Tasks

Deploy and run migrations

Run only the migrations

Restart application servers

Rollback to the previous release

Page 112: Deploying And Monitoring Rails

112

Have Your Shell, and Eat It Too

Page 113: Deploying And Monitoring Rails

113

Invoking any Command

Page 114: Deploying And Monitoring Rails

114

Deployment Strategies

Page 115: Deploying And Monitoring Rails

115

Deployment Strategies

Direct checkout (from scratch) on the servers

Page 116: Deploying And Monitoring Rails

116

Deployment Strategies

Keep a cached copy of the current SCM head

Page 117: Deploying And Monitoring Rails

117

Deployment Strategies

Check out locally and transfer

Page 118: Deploying And Monitoring Rails

118

Give it a little Spin

Capistrano expects a script called spin in script/process

For Passenger

Page 119: Deploying And Monitoring Rails

119

Customizing Capistrano

Page 120: Deploying And Monitoring Rails

120

Write your own Tasks

Page 121: Deploying And Monitoring Rails

121

Write your own Tasks

Page 122: Deploying And Monitoring Rails

122

Namespace your Tasks

Page 123: Deploying And Monitoring Rails

123

Callbacks

Execute a task before another runs

Execute a task after another has finished

Callbacks are run in the order they’re defined

Page 124: Deploying And Monitoring Rails

124

Useful Variables

Page 125: Deploying And Monitoring Rails

125

Transactions

Page 126: Deploying And Monitoring Rails

126

Transactions

Page 127: Deploying And Monitoring Rails

127

Transactions

Page 128: Deploying And Monitoring Rails

128

Transactions

Page 129: Deploying And Monitoring Rails

129

The Rest

•  Gem dependencies

•  Support for deploying through gateway servers

•  Parallel execution on multiple servers

•  Server setup with deprec gem

Page 130: Deploying And Monitoring Rails

130

Vlad the Deployer

Page 131: Deploying And Monitoring Rails

131

Vlad the Deployer

•  Simple, Rake-based deployment solution

•  Comes with defaults for most popular SCM, app and web servers

Page 132: Deploying And Monitoring Rails

132

Vlad the Deployer

Load

Configure

Page 133: Deploying And Monitoring Rails

133

Vlad the Deployer

Deployment

Page 134: Deploying And Monitoring Rails

134

Vlad the Deployer

•  Simple, sometimes too simple

•  No callback mechanism, instead the Rake syntax must be used

•  Very non-verbose output, using --trace recommended

Page 135: Deploying And Monitoring Rails

135

Chef

•  System Integration Framework

•  Written in Ruby – inspired by Puppet

•  Manage multiple nodes

•  Configuration

•  Packages

•  Custom scripts and commands

Page 136: Deploying And Monitoring Rails

136

Architecture

Page 137: Deploying And Monitoring Rails

137

Recipes

Install and upgrade packages

Page 138: Deploying And Monitoring Rails

138

Recipes

Create and update remote files

Page 139: Deploying And Monitoring Rails

139

Recipes

Create and update remote files

Page 140: Deploying And Monitoring Rails

140

chef-deploy

Enable

Use in recipe

Page 141: Deploying And Monitoring Rails

141

Chef and chef-deploy

•  In heavy development: sometimes unstable and hard to debug

•  Be prepared to get your hands dirty

•  Better suited for configuration than deployment

•  Community recipes at http://github.com/opscode/cookbooks

Page 142: Deploying And Monitoring Rails

142

One Click Deploy

Page 143: Deploying And Monitoring Rails

143

Webistrano

Page 144: Deploying And Monitoring Rails

144

Webistrano

•  Web-UI to Capistrano

•  Manages projects and their stages

•  Alerting and Accounting

•  Scriptable and extendable

•  BSD License

http://labs.peritor.com/webistrano

Page 145: Deploying And Monitoring Rails

145

Macistrano

•  Mac-GUI to Webistrano

•  Fire and monitor deployments from your desktop

http://github.com/mattmatt/macistrano

Page 146: Deploying And Monitoring Rails

146

Infrastructure Practical Session

Page 147: Deploying And Monitoring Rails

147

Practical Capistrano

Page 148: Deploying And Monitoring Rails

148

EC2 Instances

•  Users

•  root / railswaycon

•  deploy / railswaycon

•  MySQL

•  root / ‘’

•  Apache Configuration

•  /etc/apache2/sites-enabled/default

•  Rails

•  /srv/www

Page 149: Deploying And Monitoring Rails

149

Git Repository

•  git://github.com/mattmatt/railscasts.git

•  Setup the servers

•  Deploy!

Page 150: Deploying And Monitoring Rails

150

Tasks

•  Make memcached restart with every deploy

•  (Usually not a good idea, but why not?)

Page 151: Deploying And Monitoring Rails

151

Tasks

•  Make Apache recognize maintenance.html and display it if exists

Page 152: Deploying And Monitoring Rails

152

Maintenance Page

•  Create symbolic link to /etc/apache2/mods-available/rewrite.load in /etc/apache2/mods-enabled

•  Update virtual host configuration with rewrite rules

•  Run cap deploy:web:disable •  Hook it into the deployment process

Page 153: Deploying And Monitoring Rails

153

Tasks

•  Deploy a Rack-based application

•  Install Sinatra locally and on the server

•  git://github.com/mattmatt/railswaycon.git

•  Create deployment configuration

•  Create Apache configuration

Page 154: Deploying And Monitoring Rails

154

Infrastructure Monitoring

Page 155: Deploying And Monitoring Rails

155

The two questions of monitoring

Page 156: Deploying And Monitoring Rails

156

1. Is everything still running?

Page 157: Deploying And Monitoring Rails

157

2. What are the trends?

Page 158: Deploying And Monitoring Rails

158

Monit

•  Process-level monitoring

•  Checks PID-files, ports, and permissions

•  Reacts by executing a script and/or alerting

•  Has a web GUI for administering nodes

Page 159: Deploying And Monitoring Rails

159

Monit

MySQL

Page 160: Deploying And Monitoring Rails

160

Monit

Apache

Page 161: Deploying And Monitoring Rails

161

Monit

Mongrel

Page 162: Deploying And Monitoring Rails

162

God

•  Ruby-based configuration

•  Easily extendible

•  Can work with event- and poll-based conditions

•  Comes with less recipes than Monit

Page 163: Deploying And Monitoring Rails

163

God

Mongrel

Page 164: Deploying And Monitoring Rails

164

Munin

•  Host-level monitoring

•  Master periodically asks nodes for local data

•  Checks system resources and records historical data

•  Allows to recognize trends and make predictions

•  Alerting support

Page 165: Deploying And Monitoring Rails

165

Munin

Page 166: Deploying And Monitoring Rails

166

Munin

Page 167: Deploying And Monitoring Rails

167

Munin

Page 168: Deploying And Monitoring Rails

168

Exception Monitoring

•  Monitor errors raised by your application

•  Usually notifying you by email

•  Good old exception_notification Plugin

•  Exceptions as a Service

Page 169: Deploying And Monitoring Rails

169

Hoptoad

Page 170: Deploying And Monitoring Rails

170

Exceptional

Page 171: Deploying And Monitoring Rails

171

New Relic

•  Rails Performance monitoring

•  Live view into your application

Page 172: Deploying And Monitoring Rails

172

Other Tools

•  Nagios

•  Big Brother

•  New Relic RPM

•  FiveRuns

•  JMX

Page 173: Deploying And Monitoring Rails

173

Infrastructure Advanced Deployment

Page 174: Deploying And Monitoring Rails

174

Search

Page 175: Deploying And Monitoring Rails

175

Search

Full text search

Can become very slow on big data sets

Page 176: Deploying And Monitoring Rails

176

Full Text Search Engine

Separate Service

•  Creates full text index

•  Application queries search daemon

•  Index update through application or database

Possible Engines

•  Ferret

•  Sphinx

•  Solr

•  Lucene

•  …

Page 177: Deploying And Monitoring Rails

177

Search Slave

Database replication slave

•  Has complete dataset

•  Migrates slow search queries from master

•  Can use different database table engine

Page 178: Deploying And Monitoring Rails

178

Database Index

PostgreSQL Tsearch2

•  Core since 8.3

•  Allows to create full text index on multiple columns or arbitrary SQL expressions

MySQL MyISAM FULLTEXT index

•  Only works with MySQL <= 5.0 and MyISAM tables

•  Full text index on multiple columns

Page 179: Deploying And Monitoring Rails

179

What to use?

Different characteristics

•  Real-time updates and stale data

•  Lost updates

•  Performance

•  Document content and format

•  Complexity

Page 180: Deploying And Monitoring Rails

180

Background Processing

Page 181: Deploying And Monitoring Rails

181

Problem

Long running tasks

•  Resizing uploaded images

•  Mailing

•  Computing an expensive operation

•  Accessing slow back-ends

When running inside request-response-cycle

•  Blocks user

•  Blocks Rails instance

•  Hard to monitor and debug

Page 182: Deploying And Monitoring Rails

182

Solution

Asynchronous processing in the background

Message/Queue Scheduler

Page 183: Deploying And Monitoring Rails

183

Background Processing

Page 184: Deploying And Monitoring Rails

184

Options

Options for message bus:

•  Database

•  Amazon SQS

•  Drb

•  Memcache

•  ActiveMQ

•  …

Options for background process:

•  (Ruby) Daemon

•  Cron job with script/runner

•  Forked process

•  Delayed Job / BJ / (Backgroundrb)

•  run_later

•  ….

Page 185: Deploying And Monitoring Rails

185

Database/Ruby daemon example

Page 186: Deploying And Monitoring Rails

186

Cloud Infrastructure

Page 187: Deploying And Monitoring Rails

187

Cloud Infrastructure

Servers come and go

•  You do not know your servers before deploying

•  Restarting is the same as introducing a new machine

You can’t hardcode IPs

database.yml

Page 188: Deploying And Monitoring Rails

188

Solution #1

Query and manually adjust

•  Servers do not change that often

•  New nodes probably need manual intervention

•  Use AWS ElasticIPs to ease the pain

Set servers dynamically AWS Elastic IP

Page 189: Deploying And Monitoring Rails

189

Solution #2

Use a central directory service

•  A central place to manage your running instances

•  Instances query the directory and react

Page 190: Deploying And Monitoring Rails

190

Solution #2

Use a central directory service

•  A central place to manage your running instances

•  Instances query the directory and react

Page 191: Deploying And Monitoring Rails

191

Central Directory

Different Implementations

•  File on S3

•  SimpleDB

•  A complete service, capable of monitoring and controlling your instances

Page 192: Deploying And Monitoring Rails

192

Q & A

Page 193: Deploying And Monitoring Rails

193

193

Peritor GmbH

Teutonenstraße 16 14129 Berlin

Telefon: +49 (0)30 69 20 09 84 0 Telefax: +49 (0)30 69 20 09 84 9

Internet: www.peritor.com E-Mail: [email protected]

Peritor GmbH - Alle Rechte vorbehalten