SlideShare a Scribd company logo
1 of 85
Download to read offline
Complex Made Simple
                       Sleep Better With TorqueBox

                                       Lance Ball
                                       Senior Software Engineer
                                       Red Hat


                                                  Creative Commons BY-SA 3.0

Friday, April 27, 12
Complex Made Simple
                       Sleep Better With TorqueBox

                                       Lance Ball
                                       Senior Software Engineer
                                       Red Hat


                                                  Creative Commons BY-SA 3.0

Friday, April 27, 12
Who am I?

                  Lance Ball
                  ๏    Senior Software Engineer @ Red Hat
                  ๏    TorqueBox core developer
                  ๏    Part of the project:odd team
                  ๏    Open source contributor




Friday, April 27, 12
Scenario

                  You've got a Ruby
                  application to
                  deploy, for
                  production.

Friday, April 27, 12
Ruby App
                         Sinatra      Rails
                               Rack
                         Passenger/Thin


                         Apache/Nginx




Friday, April 27, 12
But...

                  The app you deploy
                  today will grow in the
                  future, if you’re
                  successful.

Friday, April 27, 12
Eventual Complexity




Friday, April 27, 12
Ruby App
                                    Sinatra      Rails
                                          Rack
                          Tasks     Passenger/Thin
                        Resque/
                       DelayedJob   Apache/Nginx




Friday, April 27, 12
Ruby App
                                    Sinatra      Rails
                                          Rack
                          Tasks     Passenger/Thin       Jobs
                        Resque/
                       DelayedJob   Apache/Nginx         crond




Friday, April 27, 12
Ruby App
                                    Sinatra      Rails
                                          Rack
                          Tasks     Passenger/Thin       Jobs
                        Resque/
                       DelayedJob   Apache/Nginx         crond


                                       Daemons


                                     god/monit




Friday, April 27, 12
Deploy Continuum




Friday, April 27, 12
Deploy Continuum




Friday, April 27, 12
Deploy Continuum




Friday, April 27, 12
What is TorqueBox?

                  TorqueBox is a
                  Ruby Application Server.

                  Based on JRuby and
                  JBoss AS7.

Friday, April 27, 12
TorqueBox AS

            Sinatra           Rails
                       Rack            Tasks   Procs            Jobs        Daemons
                       Web               Messaging        Scheduling        Services

                                                 JBoss AS
                                Clustering     Load Balancing          HA




Friday, April 27, 12
Roll your own

                  ๏ Install OS
                  ๏ Install packages

                  ๏ Configure everything

                  ๏ Manage everything




Friday, April 27, 12
Roll your own
                  ๏
                       Apache httpd
                  ๏
                       Load balancer
                  ๏
                       Unicorn, pack of Mongrels
                  ๏
                       crontab
                  ๏
                       SMTP
                  ๏
                       memcached
                  ๏
                       Database
                  ๏
                       deployment
                  ๏
                       monitoring

Friday, April 27, 12
Or outsource
                          some...

Friday, April 27, 12
Roll your own >>
                  ๏
                       Apache httpd
                  ๏
                       Load balancer
                  ๏
                       Unicorn, pack of Mongrels
                  ๏
                       crontab
                  ๏
                       SMTP Amazon SES, SendGrid
                  ๏
                       memcached
                  ๏
                       Database
                  ๏
                       deployment Capistrano
                  ๏
                       monitoring New Relic

Friday, April 27, 12
Use a Paas

                  Outsource
                  everything but
                  your app.

Friday, April 27, 12
Heroku
                  ๏
                       Apache httpd Heroku
                  ๏
                       Load balancer Heroku
                  ๏
                       Unicorn, pack of Mongrels Heroku
                  ๏
                       crontab Heroku
                  ๏
                       SMTP SendGrid
                  ๏
                       memcached Heroku
                  ๏
                       Database Heroku
                  ๏
                       deployment Heroku
                  ๏
                       monitoring New Relic

Friday, April 27, 12
TorqueBox
                  ๏
                       Apache httpd
                  ๏
                       Load balancer JBoss mod_cluster
                  ๏
                       Unicorn, pack of Mongrels TorqueBox
                  ๏
                       crontab TorqueBox
                  ๏
                       SMTP Amazon SES, SendGrid
                  ๏
                       memcached TorqueBox
                  ๏
                       Database
                  ๏
                       deployment Capistrano
                  ๏
                       monitoring NewRelic

Friday, April 27, 12
Case Study!


Friday, April 27, 12
Appalachian Sustainable
                   Agriculture Project (ASAP)




Friday, April 27, 12
Application Needs
                  ๏ Rails 2.x web app
                  ๏ Caching

                  ๏ Background tasks

                  ๏ Cron jobs

                  ๏ Deployment from SCM

                  ๏ Sending email

                  ๏ Database queries

                  ๏ Monitoring & metrics



Friday, April 27, 12
As deployed on Heroku




Friday, April 27, 12
Migration Motivation

                  In this particular case, client feels
                  it could save money, and have a
                  better system by moving to an
                  affordable VPS, letting TorqueBox
                  absorb some of the roll-your-own
                  complexity.



Friday, April 27, 12
Install


           $ rvm install jruby-1.6.7
           $ rvm use jruby-1.6.7
           $ gem install torquebox-server



Friday, April 27, 12
Templatize



           $ torquebox rails myapp




Friday, April 27, 12
torquebox.rb template

                  ๏    torquebox-* and activerecord-jdbc-
                       adapter gems
                  ๏    torquebox-rake-support
                  ๏    Directories for services, jobs, etc
                  ๏    Web session store
                  ๏    Rails.cache with TorqueBox
                  ๏    Background jobs



Friday, April 27, 12
“Porting” the
                        application

Friday, April 27, 12
Background
                          Jobs

Friday, April 27, 12
Delayed::Job

                  App uses
                  Delayed::Job
                        Replace with
                        TorqueBox
                        Backgroundable

Friday, April 27, 12
Delayed Job
                   controller.rb


         def create
           @export = ExcelExport.create(...)
           job = ExcelExportJob.new
           job.excel_export_id = @export.id
           Delayed::Job.enqueue job
           @export.set_status "Queued for Export"
           @export.save!
         end


Friday, April 27, 12
Delayed Job
                   controller.rb


         def create
           @export = ExcelExport.create(...)
           job = ExcelExportJob.new
           job.excel_export_id = @export.id
                  job = ExcelExportJob.new
           Delayed::Job.enqueue job
                  job.excel_export_id = @export.id
           @export.set_status "Queued for Export"
                  Delayed::Job.enqueue job
           @export.save!
         end


Friday, April 27, 12
Delayed Job
                   excel_export_job.rb



         class ExcelExportJob < Struct.new(:excel_export_id)
           def perform
             ExcelExport.find(self.excel_export_id).generate_report
           end
         end




Friday, April 27, 12
Delayed Job
                   excel_export.rb

         class ExcelExport < ActiveRecord::Base
           def generate_report
             begin
               set_status 'Processing'
               spreadsheet = Spreadsheet.new(self.businesses) 
               spreadsheet.write_workbook self.workbook_file
               set_status 'Storing on S3'
               File.open(self.workbook_file) {|out|self.output = out}    
               File.delete(self.workbook_file)    
               set_status 'Complete'
             rescue
               set_status 'Export Error'
             end
           end
         end




Friday, April 27, 12
Delayed Job


                  Mayhap you need to
                  run a worker, also...


Friday, April 27, 12
Delayed::Job

                       Exporter < AR::Base   Database




                       ExportJob < Struct     Worker




Friday, April 27, 12
That's pretty explicit

                  TorqueBox allows you
                  to very easily run
                  methods
                  asynchronously.

Friday, April 27, 12
Backgroundable
                   excel_export.rb
         class ExcelExport < ActiveRecord::Base
           always_background :generate_report

           def generate_report
             begin
               set_status 'Processing'
               ...
             rescue
               set_status 'Export Error'
             end
           end

         end  


Friday, April 27, 12
Backgroundable
                   excel_export.rb
         class ExcelExport < ActiveRecord::Base
           always_background :generate_report
               always_background :generate_report
           def generate_report
             begin
               set_status 'Processing'
               ...
             rescue
               set_status 'Export Error'
             end
           end

         end  


Friday, April 27, 12
Backgroundable
                   export_controller.rb



         def create
           @export = ExcelExport.create(...)
           @export.set_status "Queued for Export"
           @export.save
           @export.generate_report
         end



Friday, April 27, 12
Backgroundable
                   export_controller.rb



         def create
           @export = ExcelExport.create(...)
           @export.set_status "Queued for Export"
           @export.save
           @export.generate_report
                 @export.generate_report
         end



Friday, April 27, 12
Backgroundable
                   excel_export_job.rb




         $ git rm excel_export_job.rb

                                                  i t !
                                          i l l
                                         K
Friday, April 27, 12
Backgroundable
                       Implicit!magic!

                                  Queue           Processor




                            Exporter < AR::Base   Database




                            ExportJob < Struct     Worker




Friday, April 27, 12
Caching


Friday, April 27, 12
Caching

                  ๏    template.rb does the work
                       ๏ Web sessions

                       ๏ Fragment and other caching




Friday, April 27, 12
No more
                       memcached!

Friday, April 27, 12
Cache


         cache = TorqueBox::Infinispan::Cache.new
         cache.put(“something”, anything)
         cache.get(“something”)




Friday, April 27, 12
cron
                       0 0 2 * * ?/WTF??




Friday, April 27, 12
Heroku Cron

                  ๏ Free version runs 1x daily
                  ๏ Implemented as a rake task

                  ๏ Includes app environment




Friday, April 27, 12
Heroku Cron
                   Rakefile

         desc "This task is called by the heroku cron add-on"
         task :cron => [:environment,
                        :heroku_backup,
                        :refresh_trip_planner]

         desc "Refresh the trip planner business data cache"
         task :refresh_trip_planner => :environment do
           #
           # update GIS cache
           #
         end



Friday, April 27, 12
Scheduled Jobs


                  In TorqueBox, a scheduled job
                  is a component of your
                  application.



Friday, April 27, 12
Straight-forward
                   refresh_trip_planner.rb

         class RefreshTripPlanner
           def run()
             #
             # update the GIS cache
             #
           end
         end

Friday, April 27, 12
Configuration
                   torquebox.yml


         jobs:
           cache.updater:
             job:         RefreshTripPlanner
             cron:        '0 0 2 * * ?'
             description: Refresh trip cache




Friday, April 27, 12
But...

                  Doing a huge query
                  once-a-day isn't
                  ideal, it was just
                  "free".

Friday, April 27, 12
Services


Friday, April 27, 12
TorqueBox Services


                  ๏Avoid the huge query
                  ๏Keep data more fresher




Friday, April 27, 12
Keep it fresher
                   trip_planner_service.rb
          class TripPlannerService
           def initialize( options={} )
             @queue = TorqueBox::Messaging::Queue.new('/queues/trip_planner')
           end
           
           def start
             Thread.new do
               initialize_cache
               while should_run
                 update_cache(@queue.receive)
               end
             end
           end

           def update_cache( business_id )
             TripPlanner.insert_or_update business_id
           end
           # initialize_cache(), stop(), etc
         end



Friday, April 27, 12
Keep it fresher
                   trip_planner_service.rb
          TripPlannerService
           def initialize( options={} )
          def initialize( options={} )
             @queue = TorqueBox::Messaging::Queue.new( '/queues/trip_planner' )
            @queue = TorqueBox::Messaging::Queue.new( ...
           end                                                                    )
           
          end
           def start
             Thread.new do
               initialize_cache
               while should_run
                 update_cache @queue.receive
               end
             end
           end

           def update_cache( business_id )
             TripPlanner.insert_or_update business_id
           end
           # initialize_cache(), stop(), etc
         end



Friday, April 27, 12
Keep it fresher
                   trip_planner_service.rb
          TripPlannerService
           def initialize( options={} )
                             def start
             @queue = TorqueBox::Messaging::Queue.new( '/queues/trip_planner' )
           end
                               Thread.new do
           def start
             Thread.new do       initialize_cache
                                 while should_run
               initialize_cache
               while should_run
                                   update_cache(@queue.receive)
                 update_cache @queue.receive
               end
             end                 end
           end                 end
           def               end
                       update_cache( business_id )
             TripPlanner.insert_or_update business_id
           end
           # initialize_cache(), stop(), etc
         end



Friday, April 27, 12
Keep it fresher
                   app/models/business.rb

         require 'torquebox-messaging'

         class Business < ActiveRecord::Base

           after_save :update_trip_planner

           def update_trip_planner
             queue = TorqueBox::Messaging::Queue.new('/queues/trip_planner')
             queue.publish( self.id )
           end

         end




Friday, April 27, 12
Keep it fresher
                   app/models/business.rb

         require 'torquebox-messaging'

         class Business < ActiveRecord::Base

           after_save :update_trip_planner

           def update_trip_planner
              queue = TorqueBox::Messaging::Queue.new(...)
             queue = TorqueBox::Messaging::Queue.new('/queues/trip_planner')
             queue.publish( self.id )
           end
              queue.publish( self.id )

         end




Friday, April 27, 12
Queue, Service, Cache

                                             Queue

                       Non-blocking

                              ActiveRecord
                             Business                Service



                                                     Cache



Friday, April 27, 12
Production!


Friday, April 27, 12
(Remember, I work for Red Hat)

Friday, April 27, 12
Set up the server
           $ yum install 
               java-1.6.0-openjdk 
               httpd 
               mod_cluster 
               git 
               postgresql-server

Friday, April 27, 12
Launch on
                         boot

Friday, April 27, 12
init.d


                  Install
                  /etc/init.d/jboss-as
                  from the stock distribution



Friday, April 27, 12
JBoss configuration
                   /etc/jboss-as/jboss-as.conf

         #      General configuration for the init.d script
         #      Place this file in /etc/jboss-as/jboss-as.conf
         #      and copy $JBOSS_HOME/bin/init.d/jboss-as-standalone.sh
         #      to /etc/init.d/jboss-as-standalone

         JBOSS_USER=torquebox
         JBOSS_HOME=/opt/torquebox/current/jboss
         JBOSS_PIDFILE=/var/run/torquebox/torquebox.pid
         JBOSS_CONSOLE_LOG=/var/log/torquebox/console.log
         JBOSS_CONFIG=standalone-ha.xml




Friday, April 27, 12
Load Balance
                   with mod_cluster


Friday, April 27, 12
mod_cluster
                   httpd.conf

         LoadModule     slotmem_module         modules/mod_slotmem.so
         LoadModule     proxy_cluster_module   modules/mod_proxy_cluster.so
         LoadModule     advertise_module       modules/mod_advertise.so
         LoadModule     manager_module         modules/mod_manager.so

         <Location /mod_cluster_manager>
             SetHandler mod_cluster-manager
             AllowDisplay On
         </Location>

         Listen torquebox-balancer:6666




Friday, April 27, 12
mod_cluster
                   httpd.conf (continued)
         <VirtualHost torquebox-balancer:6666>
          
           <Directory />
             Order deny,allow
             Deny from all
             Allow from all
           </Directory>
          
           KeepAliveTimeout 60
           MaxKeepAliveRequests 0

           EnableMCPMReceive
          
           ManagerBalancerName torquebox-balancer
           AllowDisplay On
           AdvertiseFrequency 5
           AdvertiseSecurityKey secret
          
         </VirtualHost>


Friday, April 27, 12
Deploy with
                       Capistrano

Friday, April 27, 12
Capistrano

                  Regular capistrano deployments
                  are supported given the recipes
                  provided by torquebox-capistrano-
                  support.gem




Friday, April 27, 12
Deployed


           [root@torquebox opt]#   ls -l apps/buyappalachian.org/
           total 8
           lrwxrwxrwx 1   23 Mar   16 15:10 current -> releases/20120315230553
           drwxrwxr-x 5 4096 Mar   15 19:05 releases
           drwxrwxr-x 6 4096 Mar   15 17:29 shared




Friday, April 27, 12
And then it grows...

                  As your app evolves, you
                  might add stuff like
                  WebSockets/STOMP, or HA or
                  other facilities already in the tin.



Friday, April 27, 12
Can we go
                        further?

Friday, April 27, 12
What's a PaaS?


                       Cache                     Jobs
                                Application



                           DB                 Email

                                 Queues




Friday, April 27, 12
OPENSHIFT


                       http://openshift.redhat.com
     https://github.com/torquebox/torquebox-openshift-express




Friday, April 27, 12
Roadmap & Status

                  ๏ Current 2.0.1
                  ๏ Continued Red Hat investment

                  ๏ Interop with other languages,
                    such as Clojure via Immutant



Friday, April 27, 12
Resources

           http://torquebox.org/

           @torquebox on Twitter

           #torquebox on IRC


Friday, April 27, 12
Question
                       everything.

Friday, April 27, 12
Creative Commons BY-SA 3.0




Friday, April 27, 12

More Related Content

Similar to Complex Made Simple: Sleep Better With TorqueBox

Erlang for video delivery
Erlang for video deliveryErlang for video delivery
Erlang for video deliveryHugh Watkins
 
Architecting for Change: QCONNYC 2012
Architecting for Change: QCONNYC 2012Architecting for Change: QCONNYC 2012
Architecting for Change: QCONNYC 2012Kellan
 
Deploying JRuby Web Applications
Deploying JRuby Web ApplicationsDeploying JRuby Web Applications
Deploying JRuby Web ApplicationsJoe Kutner
 
Testing mysql creatively in a sandbox
Testing mysql creatively in a sandboxTesting mysql creatively in a sandbox
Testing mysql creatively in a sandboxGiuseppe Maxia
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBossJBug Italy
 
Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)Stoyan Zhekov
 
GitHub Notable OSS Project
GitHub  Notable OSS ProjectGitHub  Notable OSS Project
GitHub Notable OSS Projectroumia
 
Consideration for Building a Private Cloud
Consideration for Building a Private CloudConsideration for Building a Private Cloud
Consideration for Building a Private CloudOpenStack Foundation
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deploymentzeeg
 
OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky InfrastructureJonathan Wage
 
Asset pipeline osdc
Asset pipeline   osdcAsset pipeline   osdc
Asset pipeline osdcwildjcrt
 
Operating your OpenStack Private Cloud.pdf
Operating your OpenStack Private Cloud.pdfOperating your OpenStack Private Cloud.pdf
Operating your OpenStack Private Cloud.pdfOpenStack Foundation
 
Merb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksMerb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksRowan Hick
 
Deploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRubyDeploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRubyJoe Kutner
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampAlvaro Videla
 
Pinterest arch summit august 2012 - scaling pinterest
Pinterest arch summit   august 2012 - scaling pinterestPinterest arch summit   august 2012 - scaling pinterest
Pinterest arch summit august 2012 - scaling pinterestdrewz lin
 

Similar to Complex Made Simple: Sleep Better With TorqueBox (20)

Erlang for video delivery
Erlang for video deliveryErlang for video delivery
Erlang for video delivery
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Architecting for Change: QCONNYC 2012
Architecting for Change: QCONNYC 2012Architecting for Change: QCONNYC 2012
Architecting for Change: QCONNYC 2012
 
Deploying JRuby Web Applications
Deploying JRuby Web ApplicationsDeploying JRuby Web Applications
Deploying JRuby Web Applications
 
Testing mysql creatively in a sandbox
Testing mysql creatively in a sandboxTesting mysql creatively in a sandbox
Testing mysql creatively in a sandbox
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
 
Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)
 
GitHub Notable OSS Project
GitHub  Notable OSS ProjectGitHub  Notable OSS Project
GitHub Notable OSS Project
 
Consideration for Building a Private Cloud
Consideration for Building a Private CloudConsideration for Building a Private Cloud
Consideration for Building a Private Cloud
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deployment
 
OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky Infrastructure
 
Asset pipeline osdc
Asset pipeline   osdcAsset pipeline   osdc
Asset pipeline osdc
 
Operating your OpenStack Private Cloud.pdf
Operating your OpenStack Private Cloud.pdfOperating your OpenStack Private Cloud.pdf
Operating your OpenStack Private Cloud.pdf
 
Merb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksMerb The Super Bike Of Frameworks
Merb The Super Bike Of Frameworks
 
Einführung in Node.js
Einführung in Node.jsEinführung in Node.js
Einführung in Node.js
 
Deploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRubyDeploy, Scale and Sleep at Night with JRuby
Deploy, Scale and Sleep at Night with JRuby
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
 
Pinterest arch summit august 2012 - scaling pinterest
Pinterest arch summit   august 2012 - scaling pinterestPinterest arch summit   august 2012 - scaling pinterest
Pinterest arch summit august 2012 - scaling pinterest
 

Recently uploaded

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 

Recently uploaded (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 

Complex Made Simple: Sleep Better With TorqueBox

  • 1. Complex Made Simple Sleep Better With TorqueBox Lance Ball Senior Software Engineer Red Hat Creative Commons BY-SA 3.0 Friday, April 27, 12
  • 2. Complex Made Simple Sleep Better With TorqueBox Lance Ball Senior Software Engineer Red Hat Creative Commons BY-SA 3.0 Friday, April 27, 12
  • 3. Who am I? Lance Ball ๏ Senior Software Engineer @ Red Hat ๏ TorqueBox core developer ๏ Part of the project:odd team ๏ Open source contributor Friday, April 27, 12
  • 4. Scenario You've got a Ruby application to deploy, for production. Friday, April 27, 12
  • 5. Ruby App Sinatra Rails Rack Passenger/Thin Apache/Nginx Friday, April 27, 12
  • 6. But... The app you deploy today will grow in the future, if you’re successful. Friday, April 27, 12
  • 8. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Resque/ DelayedJob Apache/Nginx Friday, April 27, 12
  • 9. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crond Friday, April 27, 12
  • 10. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crond Daemons god/monit Friday, April 27, 12
  • 14. What is TorqueBox? TorqueBox is a Ruby Application Server. Based on JRuby and JBoss AS7. Friday, April 27, 12
  • 15. TorqueBox AS Sinatra Rails Rack Tasks Procs Jobs Daemons Web Messaging Scheduling Services JBoss AS Clustering Load Balancing HA Friday, April 27, 12
  • 16. Roll your own ๏ Install OS ๏ Install packages ๏ Configure everything ๏ Manage everything Friday, April 27, 12
  • 17. Roll your own ๏ Apache httpd ๏ Load balancer ๏ Unicorn, pack of Mongrels ๏ crontab ๏ SMTP ๏ memcached ๏ Database ๏ deployment ๏ monitoring Friday, April 27, 12
  • 18. Or outsource some... Friday, April 27, 12
  • 19. Roll your own >> ๏ Apache httpd ๏ Load balancer ๏ Unicorn, pack of Mongrels ๏ crontab ๏ SMTP Amazon SES, SendGrid ๏ memcached ๏ Database ๏ deployment Capistrano ๏ monitoring New Relic Friday, April 27, 12
  • 20. Use a Paas Outsource everything but your app. Friday, April 27, 12
  • 21. Heroku ๏ Apache httpd Heroku ๏ Load balancer Heroku ๏ Unicorn, pack of Mongrels Heroku ๏ crontab Heroku ๏ SMTP SendGrid ๏ memcached Heroku ๏ Database Heroku ๏ deployment Heroku ๏ monitoring New Relic Friday, April 27, 12
  • 22. TorqueBox ๏ Apache httpd ๏ Load balancer JBoss mod_cluster ๏ Unicorn, pack of Mongrels TorqueBox ๏ crontab TorqueBox ๏ SMTP Amazon SES, SendGrid ๏ memcached TorqueBox ๏ Database ๏ deployment Capistrano ๏ monitoring NewRelic Friday, April 27, 12
  • 24. Appalachian Sustainable Agriculture Project (ASAP) Friday, April 27, 12
  • 25. Application Needs ๏ Rails 2.x web app ๏ Caching ๏ Background tasks ๏ Cron jobs ๏ Deployment from SCM ๏ Sending email ๏ Database queries ๏ Monitoring & metrics Friday, April 27, 12
  • 26. As deployed on Heroku Friday, April 27, 12
  • 27. Migration Motivation In this particular case, client feels it could save money, and have a better system by moving to an affordable VPS, letting TorqueBox absorb some of the roll-your-own complexity. Friday, April 27, 12
  • 28. Install $ rvm install jruby-1.6.7 $ rvm use jruby-1.6.7 $ gem install torquebox-server Friday, April 27, 12
  • 29. Templatize $ torquebox rails myapp Friday, April 27, 12
  • 30. torquebox.rb template ๏ torquebox-* and activerecord-jdbc- adapter gems ๏ torquebox-rake-support ๏ Directories for services, jobs, etc ๏ Web session store ๏ Rails.cache with TorqueBox ๏ Background jobs Friday, April 27, 12
  • 31. “Porting” the application Friday, April 27, 12
  • 32. Background Jobs Friday, April 27, 12
  • 33. Delayed::Job App uses Delayed::Job Replace with TorqueBox Backgroundable Friday, April 27, 12
  • 34. Delayed Job controller.rb def create   @export = ExcelExport.create(...)   job = ExcelExportJob.new   job.excel_export_id = @export.id   Delayed::Job.enqueue job   @export.set_status "Queued for Export"   @export.save! end Friday, April 27, 12
  • 35. Delayed Job controller.rb def create   @export = ExcelExport.create(...)   job = ExcelExportJob.new   job.excel_export_id = @export.id job = ExcelExportJob.new   Delayed::Job.enqueue job job.excel_export_id = @export.id   @export.set_status "Queued for Export" Delayed::Job.enqueue job   @export.save! end Friday, April 27, 12
  • 36. Delayed Job excel_export_job.rb class ExcelExportJob < Struct.new(:excel_export_id)   def perform     ExcelExport.find(self.excel_export_id).generate_report   end end Friday, April 27, 12
  • 37. Delayed Job excel_export.rb class ExcelExport < ActiveRecord::Base   def generate_report     begin       set_status 'Processing'       spreadsheet = Spreadsheet.new(self.businesses)        spreadsheet.write_workbook self.workbook_file       set_status 'Storing on S3'       File.open(self.workbook_file) {|out|self.output = out}           File.delete(self.workbook_file)           set_status 'Complete'     rescue       set_status 'Export Error'     end   end end Friday, April 27, 12
  • 38. Delayed Job Mayhap you need to run a worker, also... Friday, April 27, 12
  • 39. Delayed::Job Exporter < AR::Base Database ExportJob < Struct Worker Friday, April 27, 12
  • 40. That's pretty explicit TorqueBox allows you to very easily run methods asynchronously. Friday, April 27, 12
  • 41. Backgroundable excel_export.rb class ExcelExport < ActiveRecord::Base   always_background :generate_report   def generate_report     begin       set_status 'Processing' ...     rescue       set_status 'Export Error'     end   end end   Friday, April 27, 12
  • 42. Backgroundable excel_export.rb class ExcelExport < ActiveRecord::Base   always_background :generate_report   always_background :generate_report   def generate_report     begin       set_status 'Processing' ...     rescue       set_status 'Export Error'     end   end end   Friday, April 27, 12
  • 43. Backgroundable export_controller.rb def create   @export = ExcelExport.create(...)   @export.set_status "Queued for Export"   @export.save @export.generate_report end Friday, April 27, 12
  • 44. Backgroundable export_controller.rb def create   @export = ExcelExport.create(...)   @export.set_status "Queued for Export"   @export.save @export.generate_report @export.generate_report end Friday, April 27, 12
  • 45. Backgroundable excel_export_job.rb $ git rm excel_export_job.rb i t ! i l l K Friday, April 27, 12
  • 46. Backgroundable Implicit!magic! Queue Processor Exporter < AR::Base Database ExportJob < Struct Worker Friday, April 27, 12
  • 48. Caching ๏ template.rb does the work ๏ Web sessions ๏ Fragment and other caching Friday, April 27, 12
  • 49. No more memcached! Friday, April 27, 12
  • 50. Cache cache = TorqueBox::Infinispan::Cache.new cache.put(“something”, anything) cache.get(“something”) Friday, April 27, 12
  • 51. cron 0 0 2 * * ?/WTF?? Friday, April 27, 12
  • 52. Heroku Cron ๏ Free version runs 1x daily ๏ Implemented as a rake task ๏ Includes app environment Friday, April 27, 12
  • 53. Heroku Cron Rakefile desc "This task is called by the heroku cron add-on" task :cron => [:environment, :heroku_backup, :refresh_trip_planner] desc "Refresh the trip planner business data cache" task :refresh_trip_planner => :environment do   #   # update GIS cache # end Friday, April 27, 12
  • 54. Scheduled Jobs In TorqueBox, a scheduled job is a component of your application. Friday, April 27, 12
  • 55. Straight-forward refresh_trip_planner.rb class RefreshTripPlanner   def run() #     # update the GIS cache #   end end Friday, April 27, 12
  • 56. Configuration torquebox.yml jobs:   cache.updater:     job: RefreshTripPlanner     cron: '0 0 2 * * ?'     description: Refresh trip cache Friday, April 27, 12
  • 57. But... Doing a huge query once-a-day isn't ideal, it was just "free". Friday, April 27, 12
  • 59. TorqueBox Services ๏Avoid the huge query ๏Keep data more fresher Friday, April 27, 12
  • 60. Keep it fresher trip_planner_service.rb class TripPlannerService   def initialize( options={} )     @queue = TorqueBox::Messaging::Queue.new('/queues/trip_planner')   end      def start     Thread.new do       initialize_cache       while should_run         update_cache(@queue.receive)       end     end   end   def update_cache( business_id )     TripPlanner.insert_or_update business_id   end # initialize_cache(), stop(), etc end Friday, April 27, 12
  • 61. Keep it fresher trip_planner_service.rb TripPlannerService   def initialize( options={} ) def initialize( options={} )     @queue = TorqueBox::Messaging::Queue.new( '/queues/trip_planner' )   @queue = TorqueBox::Messaging::Queue.new( ...   end )    end   def start     Thread.new do       initialize_cache       while should_run         update_cache @queue.receive       end     end   end   def update_cache( business_id )     TripPlanner.insert_or_update business_id   end # initialize_cache(), stop(), etc end Friday, April 27, 12
  • 62. Keep it fresher trip_planner_service.rb TripPlannerService   def initialize( options={} ) def start     @queue = TorqueBox::Messaging::Queue.new( '/queues/trip_planner' )   end      Thread.new do   def start     Thread.new do     initialize_cache     while should_run       initialize_cache       while should_run       update_cache(@queue.receive)         update_cache @queue.receive       end     end     end   end   end   def end update_cache( business_id )     TripPlanner.insert_or_update business_id   end # initialize_cache(), stop(), etc end Friday, April 27, 12
  • 63. Keep it fresher app/models/business.rb require 'torquebox-messaging' class Business < ActiveRecord::Base   after_save :update_trip_planner   def update_trip_planner     queue = TorqueBox::Messaging::Queue.new('/queues/trip_planner')     queue.publish( self.id )   end end Friday, April 27, 12
  • 64. Keep it fresher app/models/business.rb require 'torquebox-messaging' class Business < ActiveRecord::Base   after_save :update_trip_planner   def update_trip_planner queue = TorqueBox::Messaging::Queue.new(...)     queue = TorqueBox::Messaging::Queue.new('/queues/trip_planner')     queue.publish( self.id )   end queue.publish( self.id ) end Friday, April 27, 12
  • 65. Queue, Service, Cache Queue Non-blocking ActiveRecord Business Service Cache Friday, April 27, 12
  • 67. (Remember, I work for Red Hat) Friday, April 27, 12
  • 68. Set up the server $ yum install java-1.6.0-openjdk httpd mod_cluster git postgresql-server Friday, April 27, 12
  • 69. Launch on boot Friday, April 27, 12
  • 70. init.d Install /etc/init.d/jboss-as from the stock distribution Friday, April 27, 12
  • 71. JBoss configuration /etc/jboss-as/jboss-as.conf # General configuration for the init.d script # Place this file in /etc/jboss-as/jboss-as.conf # and copy $JBOSS_HOME/bin/init.d/jboss-as-standalone.sh # to /etc/init.d/jboss-as-standalone JBOSS_USER=torquebox JBOSS_HOME=/opt/torquebox/current/jboss JBOSS_PIDFILE=/var/run/torquebox/torquebox.pid JBOSS_CONSOLE_LOG=/var/log/torquebox/console.log JBOSS_CONFIG=standalone-ha.xml Friday, April 27, 12
  • 72. Load Balance with mod_cluster Friday, April 27, 12
  • 73. mod_cluster httpd.conf LoadModule slotmem_module modules/mod_slotmem.so LoadModule proxy_cluster_module modules/mod_proxy_cluster.so LoadModule advertise_module modules/mod_advertise.so LoadModule manager_module modules/mod_manager.so <Location /mod_cluster_manager>     SetHandler mod_cluster-manager     AllowDisplay On </Location> Listen torquebox-balancer:6666 Friday, April 27, 12
  • 74. mod_cluster httpd.conf (continued) <VirtualHost torquebox-balancer:6666>     <Directory />     Order deny,allow     Deny from all     Allow from all   </Directory>     KeepAliveTimeout 60   MaxKeepAliveRequests 0   EnableMCPMReceive     ManagerBalancerName torquebox-balancer   AllowDisplay On   AdvertiseFrequency 5   AdvertiseSecurityKey secret   </VirtualHost> Friday, April 27, 12
  • 75. Deploy with Capistrano Friday, April 27, 12
  • 76. Capistrano Regular capistrano deployments are supported given the recipes provided by torquebox-capistrano- support.gem Friday, April 27, 12
  • 77. Deployed [root@torquebox opt]# ls -l apps/buyappalachian.org/ total 8 lrwxrwxrwx 1 23 Mar 16 15:10 current -> releases/20120315230553 drwxrwxr-x 5 4096 Mar 15 19:05 releases drwxrwxr-x 6 4096 Mar 15 17:29 shared Friday, April 27, 12
  • 78. And then it grows... As your app evolves, you might add stuff like WebSockets/STOMP, or HA or other facilities already in the tin. Friday, April 27, 12
  • 79. Can we go further? Friday, April 27, 12
  • 80. What's a PaaS? Cache Jobs Application DB Email Queues Friday, April 27, 12
  • 81. OPENSHIFT http://openshift.redhat.com https://github.com/torquebox/torquebox-openshift-express Friday, April 27, 12
  • 82. Roadmap & Status ๏ Current 2.0.1 ๏ Continued Red Hat investment ๏ Interop with other languages, such as Clojure via Immutant Friday, April 27, 12
  • 83. Resources http://torquebox.org/ @torquebox on Twitter #torquebox on IRC Friday, April 27, 12
  • 84. Question everything. Friday, April 27, 12
  • 85. Creative Commons BY-SA 3.0 Friday, April 27, 12