Deploying and Monitoring Ruby on Rails A practical guide



Similar documents
Deploying and Monitoring Ruby on Rails

Rails Application Deployment. July Philly on Rails

Accelerating Rails with

HOSTING PYTHON WEB APPLICATIONS. Graham Dumpleton PyCon Australia Sydney 2011

MAGENTO HOSTING Progressive Server Performance Improvements

Nginx 1 Web Server Implementation

Apache Jakarta Tomcat

Deployment and Monitoring. Pascal Robert MacTI

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Apache Tomcat and Apache HTTP Server

ZEN LOAD BALANCER EE v3.02 DATASHEET The Load Balancing made easy

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

<Insert Picture Here> Introducing Hudson. Winston Prakash. Click to edit Master subtitle style

ZEN LOAD BALANCER EE v3.04 DATASHEET The Load Balancing made easy

Web Development Frameworks

Magento Search Extension TECHNICAL DOCUMENTATION

Online Fuzzy-C-Means clustering

Installing Rails 2.3 Under CentOS/RHEL 5 and Apache 2.2

Ruby on Rails in GlassFish Sun Microsystems

Installing Rails 2.3 Under Windows XP and Apache 2.2

Simple and powerful site deployment with capistrano

ZingMe Practice For Building Scalable PHP Website. By Chau Nguyen Nhat Thanh ZingMe Technical Manager Web Technical - VNG

S3 Monitor Design and Implementation Plans

Native SSL support was implemented in HAProxy 1.5.x, which was released as a stable version in June 2014.

Java, PHP & Ruby - Cloud Hosting

Serving 4 million page requests an hour with Magento Enterprise

RED HAT SOFTWARE COLLECTIONS BRIDGING DEVELOPMENT AGILITY AND PRODUCTION STABILITY

BeBanjo Infrastructure and Security Overview

Crawl Proxy Installation and Configuration Guide

MASTER THESIS. TITLE: Analysis and evaluation of high performance web servers

How To Monitor A Server With Zabbix

CDH installation & Application Test Report

LOAD BALANCING TECHNIQUES FOR RELEASE 11i AND RELEASE 12 E-BUSINESS ENVIRONMENTS

OpenMind: Know Your Customer

Apache Thrift and Ruby

Building Ruby, Rails, LightTPD, and MySQL on Tiger

White Paper. Java versus Ruby Frameworks in Practice STATE OF THE ART SOFTWARE DEVELOPMENT 1

Load Balancer Comparison: a quantitative approach. a call for researchers ;)

Integrate Rails into an Existing IIS Web infrastructure using Mongrel

HAProxy. Ryan O'Hara Principal Software Engineer, Red Hat September 17, HAProxy

Advantages and Disadvantages of Application Network Marketing Systems

The enterprise class monitoring solution for everyone

Achieving High Throughput. Fernando Castano Sun Microsystems

Magento & Zend Benchmarks Version 1.2, 1.3 (with & without Flat Catalogs)

Chapter 1 - Web Server Management and Cluster Topology

ZABBIX. An Enterprise-Class Open Source Distributed Monitoring Solution. Takanori Suzuki MIRACLE LINUX CORPORATION October 22, 2009

Painless Web Proxying with Apache mod_proxy

ntopng: Realtime Network Traffic View

mod_cluster A new httpd-based load balancer Brian Stansberry JBoss, a division of Red Hat

Intro to Load-Balancing Tomcat with httpd and mod_jk

How To Configure Apa Web Server For High Performance

Performance Optimization For Operational Risk Management Application On Azure Platform

Linstantiation of applications. Docker accelerate

FileMaker Server 11. FileMaker Server Help

WEBLOGIC ADMINISTRATION

WEBAPP PATTERN FOR APACHE TOMCAT - USER GUIDE

Drupal Performance Tuning

NGASI Universal APP Panel Administration and User Guide WebAppShowcase DBA NGASI

IERG 4080 Building Scalable Internet-based Services

Layers of Caching: Key to scaling your website. Lance Albertson -- Narayan Newton

PHP web serving study Performance report

Apache 2.0 Installation Guide

BASICS OF SCALING: LOAD BALANCERS

Chapter 2 TOPOLOGY SELECTION. SYS-ED/ Computer Education Techniques, Inc.

Architecture and Mode of Operation

Tuning Tableau Server for High Performance

IBM WEBSPHERE LOAD BALANCING SUPPORT FOR EMC DOCUMENTUM WDK/WEBTOP IN A CLUSTERED ENVIRONMENT

The Other mod_rails: Easy Rails Deployment with JRuby. Nick Sieger Sun Microsystems, Inc

Configuring IBM HTTP Server as a Reverse Proxy Server for SAS 9.3 Web Applications Deployed on IBM WebSphere Application Server

CI Pipeline with Docker

Glassfish Architecture.

1. Introduction 2. Getting Started 3. Scenario 1 - Non-Replicated Cluster 4. Scenario 2 - Replicated Cluster 5. Conclusion

How To Use Ngnix (Php) With A Php-Fpm (Php-Fmm) On A Web Server (Php5) On Your Web Browser) On An Ubuntu Web Server On A Raspberry Web 2.5 (Net

JBoss Seam Performance and Scalability on Dell PowerEdge 1855 Blade Servers

High Availability Low Dollar Load Balancing

Glassfish, JAVA EE, Servlets, JSP, EJB

Scaling Progress OpenEdge Appservers. Syed Irfan Pasha Principal QA Engineer Progress Software

What s Cool in the SAP JVM (CON3243)

Exploring Oracle E-Business Suite Load Balancing Options. Venkat Perumal IT Convergence

Continuous integration with Jenkins CI

Apache Tomcat Clustering

Mobile Performance Testing Approaches and Challenges

OnCommand Performance Manager 1.1

SIEMENS. Teamcenter Web Application Deployment PLM

KonyOne Server Installer - Linux Release Notes

DEPLOYMENT GUIDE. Deploying the BIG-IP LTM v9.x with Microsoft Windows Server 2008 Terminal Services

Understanding Evolution's Architecture A Technical Overview

VMware Identity Manager Connector Installation and Configuration

FileMaker Server 10 Help

Architecture Guide. SDL Campaign Manager 4.0.0

13.1 Backup virtual machines running on VMware ESXi / ESX Server

CS312 Solutions #6. March 13, 2015

Stackato PaaS Architecture: How it works and why.

Transcription:

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

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 2

Who are we? Mathias Meyer Independent Contractor Specialized in Rails, Performance/Database Tuning, Deployment, and Refactoring Macistrano Webistrano-Client for Mac OS X (and soon the iphone) http://www.paperplanes.de 3

Agenda Infrastructure Deployment Practical Session Monitoring Q & A 4

Infrastructure Infrastructure 5

Simple Rails Setup One Rails instance handles all requests Rails is single-threaded: There is only one concurrent request 6

Rails Setup 7

Rails Setup 8

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 9

Rails Setup Options 10

Deployment Questions Mongrel? mod_proxy_balancer? Proxy? Apache? Pound? FastCGI? Load-balancer? Nginx? HA-Proxy? Ebb? Swiftiply? mod_rails? Reverse Proxy? Phusion Passenger? Thin? Rails Application Server? Lighttpd? Pen? 11

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 12

FastCGI 13

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) 14

FastCGI 15

FastCGI 16

17

Mongrel 18

Mongrel Developed by Zed Shaw as an alternative to FastCGI Complete HTTP-Server that can load arbitrary Ruby-servlets Built-in Rails support 19

Mongrel 20

Mongrel Apache 2.2 mod_proxy_balancer Lighttpd Nginx HA-Proxy Pound 21

Mongrel Cluster Utility to manage several Mongrel instances 22

Mongrel Cluster Control Mongrels 23

Mongrel and Apache 2.2 Define Mongrel Cluster in Apache 24

Simple Mongrel and Apache 2.2 Redirect all traffic to the Mongel cluster 25

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 26

Mongrel Very robust Strict HTTP parser Easy to debug (HTTP!) Defacto standard deployment 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 27

mod_rails 28

mod_rails a.k.a Phusion Passenger Fairly new module for Apache 2.2 Allows Apache to control Rails instances Apache starts and stops application instances depending on the application load Very easy to setup Able to run any RACK-compatible Ruby application (Merb & Co.) Only manages Rails on one host - no remote instances Combine with HTTP-Proxy / balancing solution 29

Install Phusion Passenger Install Apache module Load and activate in Apache 30

Customized Phusion Passenger Control Rails instance number 31

Control Phusion Passenger Restart after deployment: 32

Phusion Passenger One machine 33

Phusion Passenger One machine Multiple machines 34

Phusion Passenger Fairly new but ready for production Makes setup easier on the single machine level Multiple servers still require load balancer Suitable for mass-hosting The upcoming standard way of deploying Rails 35

JRuby 36

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, 37

JRuby on Rails 38

JRuby on Glassfish One machine 39

JRuby on Glassfish One machine Multiple machines 40

Setup JRuby on Glassfish 1. Download JRuby and Glassfish 2. From http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html 41

Warble Configuration Define min/max Rails runtimes 42

Rails Setup 43

Proxy Options 44

Proxy Requirements Hide cluster backend from the user Load-balancer backend instances Recognize down hosts Fair scheduler (Deliver static content) 45

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 46

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 47

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 48

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 49

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 50

Nginx Configuration Simple proxy example Get complete version here: http://brainspl.at/nginx.conf.txt 51

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 52

Lighttpd Lightweight and fast webserver Balancing proxy support Good FastCGI support Used to be popular until Mongrel came around 53

Lighttpd Configuration Simple proxy example 54

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 55

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 56

HAProxy Simple proxy example 57

HAProxy Pro Mature, stable, robust, and fast TCP and HTTP balancing Con Few Rails examples Usually not needed in a Rails setup 58

Recommended Setups 59

Small Site Recommendation Apache 2.2 with mod_rails / Phusion Passenger 60

Medium Site Recommendation Apache 2.2 as the frontend proxy Use Mongrel or mod_rails as the backend Deliver static files with Apache 61

Medium Site Recommendation Apache 2.2 as the frontend proxy Use Mongrel or mod_rails as the backend Deliver static files with Apache 62

Large Rails Setup Recommendation Redundant load-balancer Redundant proxy / web Mongrel / mod_rails 63

Heavy Static Files Recommendation Deliver static assets through separate web server farm Mongrel or mod_rails 64

Java Shop Recommendation Deliver a Rails-WAR file and you are done Integrate with existing Java landscape and infrastructure 65

Remarks 66

Ruby Enterprise Edition Copy-On-Write patches to Ruby 1.8 Saves memory when spawning several Rails instances Used by Phusion Passenger if available 67

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 68

In The Future, Watch Fuzed Erlang based load balancing Dynamic registration JRuby Faster Runtime Java Integration Phusion Passenger Enterprise Ruby Performance Usability 69

Infrastructure Deployment 70

71

Deployment Options 72

Deployment Options 73

Deployment Options 74

Deployment Options 75

What does Capistrano do? 76

Capistrano Deployment Cycle 77

Requirements 78

What doesn t Capistrano do? Plan your initial server setup Configure basic services 79

Basic Ingredients The cap command Variables Roles Tasks Namespaces 80

Basic Ingredients - cap Your one-stop deployment shop 81

Basic Ingredients - Variables Configure basic project information Override Capistrano s default assumptions Once set, variables are available globally Defined using the set method 82

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 83

Basic Ingredients - Roles Define custom roles as you please Can be reused when defining tasks 84

Basic Ingredients - Tasks Define an atomic set of actions for Capistrano Can be called from the command line Or other tasks 85

Basic Ingredients - Tasks To find all the tasks available in your project, use 86

Basic Ingredients - Namespaces Group tasks together logically Namespaces and tasks are separated with : 87

Get Your Capistrano On 88

Get Your Capistrano On Capfile, the place to include more recipes 89

Get Your Capistrano On config/deploy.rb, application specific configuration 90

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 91

Get Your Capistrano On 92

Get Your Capistrano On Capistrano expects a directory structure Can be created with cap deploy:setup 93

The Deployment Lifecycle 94

The Deployment Lifecycle Check the prerequisites: 95

The Deployment Lifecycle Set up your application for the first time 96

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 97

The Deployment Lifecycle 98

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 99

The Deployment Lifecycle 100

Common Capistrano Tasks Deploy and run migrations Run only the migrations Restart application servers Rollback to the previous release 101

Have Your Shell, and Eat It Too 102

Invoking any Command 103

Deployment Strategies 104

Deployment Strategies Direct checkout (from scratch) on the servers 105

Deployment Strategies Keep a cached copy of the current SCM head 106

Deployment Strategies Check out locally and transfer 107

Give it a little Spin Capistrano expects a script called spin in script/process For Passenger 108

Customizing Capistrano 109

Write your own Tasks 110

Write your own Tasks 111

Namespace your Tasks 112

Callbacks Execute a task before another runs Execute a task after another has finished Callbacks are run in the order they re defined 113

Useful Variables 114

Transactions 115

Transactions 116

Transactions 117

Transactions 118

The Rest Gem dependencies Support for deploying through gateway servers Server setup with deprec gem Lack of documentation 119

One Click Deploy 120

Webistrano 121

Webistrano Web-UI to Capistrano Manages projects and their stages Alerting and Accounting Scriptable and extendable BSD License http://labs.peritor.com/webistrano 122

Macistrano Mac-GUI to Webistrano Fire and monitor deployments from your desktop http://github.com/mattmatt/macistrano 123

Infrastructure Pratical Session 124

Practical Capistrano 125

Get the slides Connect to RailsConf Deployment WLAN The slides are at http://10.0.0.1/ The VMs are at 10.0.0.3 10.0.0.41 Sample configurations files are in the GIT/SVN repositories 126

Infrastructure Monitoring 127

The two questions of monitoring 128

1. Is everything still running? 129

2. What are the trends? 130

Monit Process-level monitoring Checks PID-files, ports, and permissions Reacts by executing a script and/or alerting 131

Monit MySQL 132

Monit Apache 133

Monit Mongrel 134

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 135

Munin 136

Munin 137

Munin 138

Other Tools Nagios Big Brother New Relic RPM FiveRuns JMX 139

Q & A 140

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: kontakt@peritor.com Peritor GmbH - Alle Rechte vorbehalten 141 141