Deployment de Rails
         Fabio Akita
     www.akitaonrails.com
Deployment de Rails
+7000 pessoas no WWR
+7000 pessoas no WWR



      +3 anos
+7000 pessoas no WWR



      +3 anos



 +8M hits no Google
“Rails Escala?”
“Sim, Rails Escala!”
Rails 1.0 em 2005
Rails 1.0 em 2005

    MySQL
Rails 1.0 em 2005

      MySQL

LightTPD + Fast CGI
Database/Storage
Database/Storage

  “Rails Stack”
Database/Storage

      “Rails Stack”

HTTP Server/Load Balancer
Database
MySQL


            PostgreSQL


Oracle/SQL Server/Informix/Sybase ...
MySQL


            PostgreSQL


Oracle/SQL Server/Informix/Sybase ...


           MEMCACHED
Rails App   Database
Rails App   Database
MEMCACHED



Rails App



             Database
MEMCACHED



Rails App



            Database          Slave
class Post < ActiveRecord::Base
end
class Post < ActiveRecord::Base
  acts_as_cached
  after_destroy :expire_cache
end
http://errtheblog.com/posts/57-kickin-ass-w-cachefu
HTTP Servers
Maduro
Apache 2.x
             Mais “pesado”
Maduro
Apache 2.x
             Mais “pesado”


Nginx 0.5       Rápido
Maduro
 Apache 2.x
                Mais “pesado”


 Nginx 0.5         Rápido


                  Rápido
Litespeed 3.x
    ...
FastCGI   Instável
FastCGI   Instável


 SAPI     Rápido
FastCGI       Instável


    SAPI        Rápido

    HTTP
                Estável
Proxy Reverso
FastCGI          Instável


    SAPI           Rápido

    HTTP
                   Estável
Proxy Reverso

  mod_rails     ...
HTTP
         “Rails Stack”
Server
FCGI


HTTP
                “Rails Stack”
Server
FCGI


HTTP
         SAPI   “Rails Stack”
Server
FCGI


HTTP
         SAPI   “Rails Stack”
Server



         HTTP
“Rails Stack”


         FCGI


HTTP
         SAPI   “Rails Stack”
Server



         HTTP


                “Rails Stack”
Rails Stack
“Rails Stack”
“Rails Stack”




Ruby VM (MRI)
“Rails Stack”


 RubyGems


Ruby VM (MRI)
Ruby on Rails


        “Rails Stack”


       RubyGems


     Ruby VM (MRI)
Ruby on Rails

                 Mongrel
        “Rails Stack”


       RubyGems


     Ruby VM (MRI)
Rails, ActiveSupport, ActiveRecord, ActionPack
Rails, ActiveSupport, ActiveRecord, ActionPack


  ActionMailer, ActiveResource, ActionWS
Rails, ActiveSupport, ActiveRecord, ActionPack


  ActionMailer, ActiveResource, ActionWS


       Capistrano, Net-SSH, Ne...
Rails, ActiveSupport, ActiveRecord, ActionPack


  ActionMailer, ActiveResource, ActionWS


       Capistrano, Net-SSH, Ne...
Rails, ActiveSupport, ActiveRecord, ActionPack


  ActionMailer, ActiveResource, ActionWS


       Capistrano, Net-SSH, Ne...
Rails, ActiveSupport, ActiveRecord, ActionPack


  ActionMailer, ActiveResource, ActionWS


       Capistrano, Net-SSH, Ne...
Mongrel   Multi-threaded
Mongrel   Multi-threaded




 Rails    Non-concurrent
Mongrel
Ruby on Rails


  Mongrel
Outras Gems


Ruby on Rails


  Mongrel
Sua Applicação


Outras Gems


Ruby on Rails


   Mongrel
“Rails Stack”
Mongrel Cluster
Mongrel Cluster

Load Balancer
Monit


God
objetos

Ruby VM
objetos



objetos

Ruby VM
GC
     objetos



     objetos

     Ruby VM
objetos
objetos

Ruby VM
Memória
     Livre
não desalocada




   objetos
   objetos

  Ruby VM
Monit



Rails App
Rails App   Monit
Monit



Rails App
Load
Balancer
Rails + Mongrel



           Rails + Mongrel



           Rails + Mongrel
 Load
Balancer
           Rails + Mongrel



 ...
Capistrano
capify .


 cap setup


cap deploy


cap rollback
capify .
set :application, "mey_aplicativo"
set :repository, "git://server.com/projeto.git"
set :deploy_to, "/var/www/#{ap...
capify .


 cap setup


cap deploy


cap rollback
capify .


 cap setup


cap deploy


cap rollback
capify .


 cap setup


cap deploy


cap rollback
Desktop
SCM
 (Git)




Desktop
SCM
 (Git)




Desktop
SCM
 (Git)




Desktop
SCM
                Staging
 (Git)
          Cap




Desktop
SCM
                Staging
 (Git)
          Cap




Desktop
SCM
                Staging
 (Git)
          Cap




Desktop
SCM
                Staging
 (Git)
          Cap




Desktop     Production
          Cap
SCM
                Staging
 (Git)
          Cap




Desktop     Production
          Cap
SCM
                Staging
 (Git)
          Cap




Desktop     Production
          Cap
SCM
Desktop
          (Git)
SCM
           Desktop
                                      (Git)



  Production     Production     Production      Prod...
http://capify.org/
Quantos Mongrels?
Apache Bench
  • Blog Demo
  • Post resource
  • (1 query, 20 rows)
Apache Bench
Apache Bench

ab -n 1000 http://127.0.0.1:3000/posts
Apache Bench

ab -n 1000 http://127.0.0.1:3000/posts


              1 conexão
           1000 requisições
Apache Bench

ab -n 5000 -c 10 http://127.0.0.1:3000/posts
Apache Bench

ab -n 5000 -c 10 http://127.0.0.1:3000/posts


                10 conexões
              5000 requisições
Nginx - 3 Mongrels
Nginx - 3 Mongrels

req/s (mean)



    1000
  requests
 1 conexão

    5000
  requests
     10
 conexões
Nginx - 3 Mongrels

req/s (mean) Hello World



    1000
  requests     414.56
 1 conexão

    5000
  requests
           ...
Nginx - 3 Mongrels
                            Posts
req/s (mean) Hello World
                           (puro)


    1000...
Nginx - 3 Mongrels
                                     Posts
                            Posts
req/s (mean) Hello World  ...
Nginx - 3 Mongrels
                                     Posts     Posts
                            Posts
req/s (mean) Hel...
Memória
Memória

 1 Mongrel,
                ~30 Mb
1 Rails vazio
Memória

 1 Mongrel,
                ~30 Mb
1 Rails vazio

1 Mongrel,
                ~70Mb
1 Mephisto
http://www.scribd.com/doc/97641/
   JHoffmanRailsConfMay2007
Estratégias
Rails Cache (Page/Action/Fragment)
Rails Cache (Page/Action/Fragment)



         MEMCACHED
Rails Cache (Page/Action/Fragment)



         MEMCACHED


     Asynchronous Processes
  (BackgrounDRb, cronjobs, etc)
class PostsController < Application
  def action
    # código lento
  end
end

# http://www.site.com/posts
class PostsController < Application
  def action           PERIGO!
    # código lento
  end
end

# http://www.site.com/pos...
class PostsController < Application
  def action
    MiddleMan.new_worker(
      :class => :heavy)
  end
end

class Heavy ...
Tempo de Execução




Rails Request
Tempo de Execução




   Rails Request



CACHE
Tempo de Execução




        Rails Request
Tempo de Execução




        Rails Request



                    Async
Tempo de Execução




Rails Request




   Outros
920 pageviews/dia

  ~30 req/s pico

  USD 370/mês
Deployment comum
Cap
Nginx




        Cap
MySQL
Nginx




        Cap
MySQL
Nginx
              Memcached


        Cap
MySQL
Nginx
                    Memcached


        Cap   Git
Desafios
Performance


Green Threads x Native Thread + GIL


       Memory Management


           C Extensions


          Interop...
Performance


Green Threads x Native Thread + GIL


       Memory Management


           C Extensions


          Interop...
Performance


Green Threads x Native Thread + GIL


       Memory Management


           C Extensions


          Interop...
Performance


Green Threads x Native Thread + GIL


       Memory Management


           C Extensions


          Interop...
Performance


Green Threads x Native Thread + GIL


       Memory Management


           C Extensions


          Interop...
Instalação
Instalação
aptitude install apache2 apache2­mpm­prefork 
       ruby1.8 dev apache2­prefork­dev


        gem install pass...
Instalação
aptitude install apache2 apache2­mpm­prefork 
       ruby1.8 dev apache2­prefork­dev


        gem install pass...
Instalação
aptitude install apache2 apache2­mpm­prefork 
       ruby1.8 dev apache2­prefork­dev


        gem install pass...
Instalação
aptitude install apache2 apache2­mpm­prefork 
       ruby1.8 dev apache2­prefork­dev


        gem install pass...
LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/
  passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnSe...
Benchmarks
Mongrel   Thin   Passenger
Benchmarks
Mongrel   Thin   Passenger
Obrigado!


www.akitaonrails.com
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Deployment de Rails
Upcoming SlideShare
Loading in …5
×

Deployment de Rails

1,923
-1

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,923
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Deployment de Rails

  1. 1. Deployment de Rails Fabio Akita www.akitaonrails.com
  2. 2. Deployment de Rails
  3. 3. +7000 pessoas no WWR
  4. 4. +7000 pessoas no WWR +3 anos
  5. 5. +7000 pessoas no WWR +3 anos +8M hits no Google
  6. 6. “Rails Escala?”
  7. 7. “Sim, Rails Escala!”
  8. 8. Rails 1.0 em 2005
  9. 9. Rails 1.0 em 2005 MySQL
  10. 10. Rails 1.0 em 2005 MySQL LightTPD + Fast CGI
  11. 11. Database/Storage
  12. 12. Database/Storage “Rails Stack”
  13. 13. Database/Storage “Rails Stack” HTTP Server/Load Balancer
  14. 14. Database
  15. 15. MySQL PostgreSQL Oracle/SQL Server/Informix/Sybase ...
  16. 16. MySQL PostgreSQL Oracle/SQL Server/Informix/Sybase ... MEMCACHED
  17. 17. Rails App Database
  18. 18. Rails App Database
  19. 19. MEMCACHED Rails App Database
  20. 20. MEMCACHED Rails App Database Slave
  21. 21. class Post < ActiveRecord::Base end
  22. 22. class Post < ActiveRecord::Base acts_as_cached after_destroy :expire_cache end
  23. 23. http://errtheblog.com/posts/57-kickin-ass-w-cachefu
  24. 24. HTTP Servers
  25. 25. Maduro Apache 2.x Mais “pesado”
  26. 26. Maduro Apache 2.x Mais “pesado” Nginx 0.5 Rápido
  27. 27. Maduro Apache 2.x Mais “pesado” Nginx 0.5 Rápido Rápido Litespeed 3.x Comercial
  28. 28. FastCGI Instável
  29. 29. FastCGI Instável SAPI Rápido
  30. 30. FastCGI Instável SAPI Rápido HTTP Estável Proxy Reverso
  31. 31. FastCGI Instável SAPI Rápido HTTP Estável Proxy Reverso mod_rails recém-chegado
  32. 32. HTTP “Rails Stack” Server
  33. 33. FCGI HTTP “Rails Stack” Server
  34. 34. FCGI HTTP SAPI “Rails Stack” Server
  35. 35. FCGI HTTP SAPI “Rails Stack” Server HTTP
  36. 36. “Rails Stack” FCGI HTTP SAPI “Rails Stack” Server HTTP “Rails Stack”
  37. 37. Rails Stack
  38. 38. “Rails Stack”
  39. 39. “Rails Stack” Ruby VM (MRI)
  40. 40. “Rails Stack” RubyGems Ruby VM (MRI)
  41. 41. Ruby on Rails “Rails Stack” RubyGems Ruby VM (MRI)
  42. 42. Ruby on Rails Mongrel “Rails Stack” RubyGems Ruby VM (MRI)
  43. 43. Rails, ActiveSupport, ActiveRecord, ActionPack
  44. 44. Rails, ActiveSupport, ActiveRecord, ActionPack ActionMailer, ActiveResource, ActionWS
  45. 45. Rails, ActiveSupport, ActiveRecord, ActionPack ActionMailer, ActiveResource, ActionWS Capistrano, Net-SSH, Net-SFTP
  46. 46. Rails, ActiveSupport, ActiveRecord, ActionPack ActionMailer, ActiveResource, ActionWS Capistrano, Net-SSH, Net-SFTP Mongrel, Mongrel Cluster
  47. 47. Rails, ActiveSupport, ActiveRecord, ActionPack ActionMailer, ActiveResource, ActionWS Capistrano, Net-SSH, Net-SFTP Mongrel, Mongrel Cluster Rmagick, Mini Magick, Image Science
  48. 48. Rails, ActiveSupport, ActiveRecord, ActionPack ActionMailer, ActiveResource, ActionWS Capistrano, Net-SSH, Net-SFTP Mongrel, Mongrel Cluster Rmagick, Mini Magick, Image Science Rspec, ZenTest
  49. 49. Mongrel Multi-threaded
  50. 50. Mongrel Multi-threaded Rails Non-concurrent
  51. 51. Mongrel
  52. 52. Ruby on Rails Mongrel
  53. 53. Outras Gems Ruby on Rails Mongrel
  54. 54. Sua Applicação Outras Gems Ruby on Rails Mongrel
  55. 55. “Rails Stack”
  56. 56. Mongrel Cluster
  57. 57. Mongrel Cluster Load Balancer
  58. 58. Monit God
  59. 59. objetos Ruby VM
  60. 60. objetos objetos Ruby VM
  61. 61. GC objetos objetos Ruby VM
  62. 62. objetos objetos Ruby VM
  63. 63. Memória Livre não desalocada objetos objetos Ruby VM
  64. 64. Monit Rails App
  65. 65. Rails App Monit
  66. 66. Monit Rails App
  67. 67. Load Balancer
  68. 68. Rails + Mongrel Rails + Mongrel Rails + Mongrel Load Balancer Rails + Mongrel Rails + Mongrel Rails + Mongrel
  69. 69. Capistrano
  70. 70. capify . cap setup cap deploy cap rollback
  71. 71. capify . set :application, "mey_aplicativo" set :repository, "git://server.com/projeto.git" set :deploy_to, "/var/www/#{application}" cap setup default_run_options[:pty] = true set :repository, "git@github.com:user/rails-app.git" set :scm, "git" set :scm_passphrase, "p00p" set :user, "deployer" cap deploy set :branch, "origin/master" set :deploy_via, :remote_cache set :git_shallow_clone, 1 set :git_enable_submodules, 1 cap rollback
  72. 72. capify . cap setup cap deploy cap rollback
  73. 73. capify . cap setup cap deploy cap rollback
  74. 74. capify . cap setup cap deploy cap rollback
  75. 75. Desktop
  76. 76. SCM (Git) Desktop
  77. 77. SCM (Git) Desktop
  78. 78. SCM (Git) Desktop
  79. 79. SCM Staging (Git) Cap Desktop
  80. 80. SCM Staging (Git) Cap Desktop
  81. 81. SCM Staging (Git) Cap Desktop
  82. 82. SCM Staging (Git) Cap Desktop Production Cap
  83. 83. SCM Staging (Git) Cap Desktop Production Cap
  84. 84. SCM Staging (Git) Cap Desktop Production Cap
  85. 85. SCM Desktop (Git)
  86. 86. SCM Desktop (Git) Production Production Production Production Cap Cap Cap Cap Production Production Production Production Cap Cap Cap Cap
  87. 87. http://capify.org/
  88. 88. Quantos Mongrels?
  89. 89. Apache Bench • Blog Demo • Post resource • (1 query, 20 rows)
  90. 90. Apache Bench
  91. 91. Apache Bench ab -n 1000 http://127.0.0.1:3000/posts
  92. 92. Apache Bench ab -n 1000 http://127.0.0.1:3000/posts 1 conexão 1000 requisições
  93. 93. Apache Bench ab -n 5000 -c 10 http://127.0.0.1:3000/posts
  94. 94. Apache Bench ab -n 5000 -c 10 http://127.0.0.1:3000/posts 10 conexões 5000 requisições
  95. 95. Nginx - 3 Mongrels
  96. 96. Nginx - 3 Mongrels req/s (mean) 1000 requests 1 conexão 5000 requests 10 conexões
  97. 97. Nginx - 3 Mongrels req/s (mean) Hello World 1000 requests 414.56 1 conexão 5000 requests 701.88 10 conexões
  98. 98. Nginx - 3 Mongrels Posts req/s (mean) Hello World (puro) 1000 requests 414.56 24.44 1 conexão 5000 requests 701.88 39.31 10 conexões
  99. 99. Nginx - 3 Mongrels Posts Posts req/s (mean) Hello World (page (puro) cache) 1000 requests 414.56 24.44 1587.31 1 conexão 5000 requests 701.88 39.31 2220.24 10 conexões
  100. 100. Nginx - 3 Mongrels Posts Posts Posts req/s (mean) Hello World (page (action (puro) cache) cache) 1000 requests 414.56 24.44 1587.31 106.29 1 conexão 5000 requests 701.88 39.31 2220.24 96.81 10 conexões
  101. 101. Memória
  102. 102. Memória 1 Mongrel, ~30 Mb 1 Rails vazio
  103. 103. Memória 1 Mongrel, ~30 Mb 1 Rails vazio 1 Mongrel, ~70Mb 1 Mephisto
  104. 104. http://www.scribd.com/doc/97641/ JHoffmanRailsConfMay2007
  105. 105. Estratégias
  106. 106. Rails Cache (Page/Action/Fragment)
  107. 107. Rails Cache (Page/Action/Fragment) MEMCACHED
  108. 108. Rails Cache (Page/Action/Fragment) MEMCACHED Asynchronous Processes (BackgrounDRb, cronjobs, etc)
  109. 109. class PostsController < Application def action # código lento end end # http://www.site.com/posts
  110. 110. class PostsController < Application def action PERIGO! # código lento end end # http://www.site.com/posts
  111. 111. class PostsController < Application def action MiddleMan.new_worker( :class => :heavy) end end class Heavy < BackgrounDRb::Worker::RailsBase def do_work(options) # código lento end end
  112. 112. Tempo de Execução Rails Request
  113. 113. Tempo de Execução Rails Request CACHE
  114. 114. Tempo de Execução Rails Request
  115. 115. Tempo de Execução Rails Request Async
  116. 116. Tempo de Execução Rails Request Outros
  117. 117. 920 pageviews/dia ~30 req/s pico USD 370/mês
  118. 118. Deployment comum
  119. 119. Cap
  120. 120. Nginx Cap
  121. 121. MySQL Nginx Cap
  122. 122. MySQL Nginx Memcached Cap
  123. 123. MySQL Nginx Memcached Cap Git
  124. 124. Desafios
  125. 125. Performance Green Threads x Native Thread + GIL Memory Management C Extensions Interoperability
  126. 126. Performance Green Threads x Native Thread + GIL Memory Management C Extensions Interoperability
  127. 127. Performance Green Threads x Native Thread + GIL Memory Management C Extensions Interoperability
  128. 128. Performance Green Threads x Native Thread + GIL Memory Management C Extensions Interoperability
  129. 129. Performance Green Threads x Native Thread + GIL Memory Management C Extensions Interoperability
  130. 130. Instalação
  131. 131. Instalação aptitude install apache2 apache2­mpm­prefork  ruby1.8 dev apache2­prefork­dev gem install passenger ./passenger­install­apache2­module cd /var/www ; rails .
  132. 132. Instalação aptitude install apache2 apache2­mpm­prefork  ruby1.8 dev apache2­prefork­dev gem install passenger ./passenger­install­apache2­module cd /var/www ; rails .
  133. 133. Instalação aptitude install apache2 apache2­mpm­prefork  ruby1.8 dev apache2­prefork­dev gem install passenger ./passenger­install­apache2­module cd /var/www ; rails .
  134. 134. Instalação aptitude install apache2 apache2­mpm­prefork  ruby1.8 dev apache2­prefork­dev gem install passenger ./passenger­install­apache2­module cd /var/www ; rails .
  135. 135. LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/ passenger-1.0.1/ext/apache2/mod_passenger.so RailsSpawnServer /opt/local/lib/ruby/gems/1.8/gems/passenger-1.0.1/bin/ passenger-spawn-server RailsRuby /opt/local/bin/ruby <Directory "/Users/akitaonrails/rails/blog/public"> Order allow,deny Allow from all </Directory> <VirtualHost *:80> ServerName localhost DocumentRoot /Users/akitaonrails/rails/blog/public </VirtualHost>
  136. 136. Benchmarks Mongrel Thin Passenger
  137. 137. Benchmarks Mongrel Thin Passenger
  138. 138. Obrigado! www.akitaonrails.com
  1. A particular slide catching your eye?

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

×