TorqueBox for Rubyists
Upcoming SlideShare
Loading in...5
×
 

TorqueBox for Rubyists

on

  • 2,532 views

Presentation of TorqueBox for Rubyists at Asheville.rb

Presentation of TorqueBox for Rubyists at Asheville.rb

Statistics

Views

Total Views
2,532
Views on SlideShare
2,328
Embed Views
204

Actions

Likes
5
Downloads
29
Comments
0

5 Embeds 204

http://torquebox.org 195
http://www.jboss.org 6
http://www.jboss.org:80 1
http://www.slideshare.net 1
http://localhost 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

TorqueBox for Rubyists TorqueBox for Rubyists Presentation Transcript

  • TorqueBox Enterprise-Grade Ruby Application Server Bob McWhirter Asheville.rb Asheville, North Carolina 2 December 2009 Creative Commons BY-SA 3.0
  • Bob McWhirter • Started in C++ • Moved to Java with JDK 1.1.8 • Began Ruby and Rails in 2005 • Lived in Asheville for 4 years • Did some open-source along the way 2
  • Open-Source 3
  • Currently Linux + Java + Bob 4
  • == Ruby? 5
  • Actual R&D I get to actually research things, and develop new stuff. Honest- to-goodness technology R&D investment. 6
  • TorqueBox ...in a nutshell 7
  • What is it? A merging of the Ruby language with the Java Virtual Machine. 8
  • Why bother? As Ruby matures, it’s quickly being used to solve larger, more difficult problems. Problems we’ve solved in the enterprise with Java already. 9
  • Such as...? • Scalability • Efficient & asynchronous messaging • Scheduled jobs • Telephony 10
  • Scalability ...because “Rails doesn’t scale” 11
  • Web Scalability 12
  • mongrel-style Ruby mongrel 13
  • mongrel-style Ruby mongrel Ruby mongrel httpd Ruby mongrel Ruby mongrel 14
  • mongrel-style Ruby mongrel Ruby mongrel httpd Ruby mongrel Ruby mongrel 15
  • passenger style Conservative Spawning Rails Rails httpd Passenger Ruby Rails Rails 16
  • passenger style Smart Spawning Worker Worker httpd Passenger Ruby Rails Worker Worker 17
  • TorqueBox style TorqueBox http queues MyApp Ruby Rails scheduler 18
  • Clustering Multiplicity rocks. 19
  • Concerns When clustering, we care about sessions and load balancing. 20
  • Sessions With multiple application servers, sessions must be shared, or session affinity must be used. 21
  • Session Sharing Sharing sessions requires using a central store, such as memcached or ActiveRecord session stores. 22
  • Session Sharing Worker Worker memcached Worker Worker 23
  • Session Sharing But what if the central session store is unavailable, or overwhelmed? Single point of failure! 24
  • Session Sharing Worker Worker memcached Worker Worker 25
  • Session Affinity Session affinity is making sure the same back-end server handles all of Todd’s requests. 26
  • Session Affinity Worker Todd’s Worker server Todd Balancer Worker Worker 27
  • Session Affinity But what if the back-end server handling Todd’s requests becomes unavailable? 28
  • Session Affinity Worker Todd’s Worker server Todd Balancer Worker Worker 29
  • Use Both! Use session affinity when you can, but allow workers to replicate session information when necessary. 30
  • Use Both! Worker Cache Worker Cache Balancer Worker Cache Worker Cache 31
  • Spanning Hosts Host Worker Cache Host Worker Cache Balancer Host Worker Cache Host Worker Cache 32
  • Balancer in the cluster Using mod_cluster for Apache httpd, the balancer participates in the cluster view. 33
  • mod_cluster As server nodes join and leave the cluster, the balancer (mod_cluster) is aware of these changes. 34
  • mod_proxy_ajp The Apache JServ Protocol (AJP) is an efficient pipeline for shuffling HTTP requests to a Java application-server for handling. 35
  • Oh yeah... • Multiple apps per server or cluster. • Virtual-host support baked in. • Context-path support. • Full Rack support (bare, Sinatra, etc). • Full Java-EE stack. 36
  • And bundles myapp.rails myapp.rack 37
  • And bundles Single ZIP file bundle of an app. Easily move specific artifact between staging and production. Required for cluster auto-farming deployment. 38
  • Rails scales! ...but there’s more than just port 80. 39
  • Task Queues Simply install Erlang, set up RabbitMQ, use an AMQP gem... 40
  • Or just use TorqueBox ...and just write a Ruby class. 41
  • app/queues/**_queue.rb • A class per queue. • A method per task handled by the queue. • A simple API to toss stuff around. 42
  • my_first_queue.rb class MyFirstQueue include TorqueBox::Queues::Base def task_one(payload={}) o = Thing.find_by_id( payload[:thing_id] ) o.frob! o.save! end end 43
  • my_first_queue.rb class MyFirstQueue include TorqueBox::Queues::Base def task_one(payload={}) o = Thing.find_by_id( payload[:thing_id] ) o.frob! o.save! end end 44
  • my_first_queue.rb class MyFirstQueue include TorqueBox::Queues::Base def task_one(payload={}) o = Thing.find_by_id( payload[:thing_id] ) o.frob! o.save! end end 45
  • my_first_queue.rb class MyFirstQueue include TorqueBox::Queues::Base def task_one(payload={}) o = Thing.find_by_id( payload[:thing_id] ) o.frob! o.save! end end 46
  • my_first_queue.rb class MyFirstQueue include TorqueBox::Queues::Base def task_one(payload={}) o = Thing.find_by_id( payload[:thing_id] ) o.frob! o.save! end end 47
  • Enqueue TorqueBox::Queues.enqueue( ‘MyFirstQueue’, :task_one, { :thing_id=>42 } ) 48
  • Enqueue TorqueBox::Queues.enqueue( ‘MyFirstQueue’, :task_one, { :thing_id=>42 } ) 49
  • Enqueue TorqueBox::Queues.enqueue( ‘MyFirstQueue’, :task_one, { :thing_id=>42 } ) 50
  • Enqueue TorqueBox::Queues.enqueue( ‘MyFirstQueue’, :task_one, { :thing_id=>42 } ) 51
  • Enqueue Use from your controllers, ActiveRecord observers, or other queues. 52
  • Enqueue class User < ActiveRecord::Base has_attached_file :avatar, ... after_save do |user| TorqueBox::Queues.enqueue( :image_processor_queue, :process_user_avatar, user.id ) if user.avatar_needs_processing? end end 53
  • Enqueue class User < ActiveRecord::Base has_attached_file :avatar, ... after_save do |user| TorqueBox::Queues.enqueue( :image_processor_queue, :process_user_avatar, user.id ) if user.avatar_needs_processing? end end 54
  • Enqueue class User < ActiveRecord::Base has_attached_file :avatar, ... after_save do |user| TorqueBox::Queues.enqueue( :image_processor_queue, :process_user_avatar, user.id ) if user.avatar_needs_processing? end end 55
  • Enqueue class User < ActiveRecord::Base has_attached_file :avatar, ... after_save do |user| TorqueBox::Queues.enqueue( :image_processor_queue, :process_user_avatar, user.id ) if user.avatar_needs_processing? end end 56
  • Queue Benefits • No additional systems or languages to setup and maintain. • Clustering/HA available (including durable messages). • No explicit queue configuration required. 57
  • Scheduled Jobs Just write a script, and a crontab, and deploy it with your app. Don’t forget to undeploy and update it also. And check cron.log for errors. 58
  • Or just use TorqueBox ...and just write a Ruby class. 59
  • app/jobs/**.rb • A class per queue. • A method called run() • Configure it via jobs.yml 60
  • my_first_job.rb class MyFirstJob include TorqueBox::Jobs::Base def run() subscriptions = Subscription.find(:all) subscriptions.each do |e| send_newsletter( e ) end end end 61
  • my_first_job.rb class MyFirstJob include TorqueBox::Jobs::Base def run() subscriptions = Subscription.find(:all) subscriptions.each do |e| send_newsletter( e ) end end end 62
  • my_first_job.rb class MyFirstJob include TorqueBox::Jobs::Base def run() subscriptions = Subscription.find(:all) subscriptions.each do |e| send_newsletter( e ) end end end 63
  • my_first_job.rb class MyFirstJob include TorqueBox::Jobs::Base def run() subscriptions = Subscription.find(:all) subscriptions.each do |e| send_newsletter( e ) end end end 64
  • config/jobs.yml subscription.mailer: description: send out newsletters job: MyFirstJob cron: 20 7 1 * * ? 65
  • config/jobs.yml subscription.mailer: description: send out newsletters job: MyFirstJob cron: 20 7 1 * * ? 66
  • config/jobs.yml subscription.mailer: description: send out newsletters job: MyFirstJob cron: 20 7 1 * * ? 67
  • config/jobs.yml subscription.mailer: description: send out newsletters job: MyFirstJob cron: 20 7 1 * * ? 68
  • config/jobs.yml subscription.mailer: description: send out newsletters job: MyFirstJob cron: 20 7 1 * * ? 69
  • config/jobs.yml 20 7 1 * * ? sec hour mon min d.o.m. d.o.y 70
  • config/jobs.yml 20 7 1 * * ? Every day, at 1:07:20 am 71
  • Scheduler Benefits • Uses existing Ruby interpreter when jobs fire. No waiting for Ruby/Rails to load. • No external system (crontab) to maintain. • No additional daemons to monitor (daemonize) • Full Rails environment (AR models, queues, lib/) 72
  • Telephony Just... um... something... with Asterisk? 73
  • Or just use TorqueBox ...and just write a Ruby class. 74
  • Initiate Calls By doing SIP magic, your application can initiate calls, or connect multiple parties. 75
  • Press 2 to STFU Using the Media Server, automated messages, interactive voice response (IVR) and other advanced systems can be built. 76
  • OMGWTFBBQPONIES! Have your app (for instance, upon successful job completion) fire off an SMS. 77
  • Telephony Benefits • It’s just freakin’ cool. 78
  • Manageability Okay, sorta speculative, forward- looking dreaming, but... 79
  • Manageable Everything ultimately maps to a managed object within the Java application-server. We have the JOPR management console. 80
  • But not yet But we haven’t exposed everything in a super nice fashion. Yet. 81
  • All-in-One Everything’s in the tin. Everything works together. 82
  • More information... http://torquebox.org/ http://github.com/torquebox http://twitter.com/torquebox 83
  • Thanks + Q&A Creative Commons BY-SA 3.0 84