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

Like this? Share it with your network

Share

TorqueBox for Rubyists

on

  • 2,563 views

Presentation of TorqueBox for Rubyists at Asheville.rb

Presentation of TorqueBox for Rubyists at Asheville.rb

Statistics

Views

Total Views
2,563
Views on SlideShare
2,358
Embed Views
205

Actions

Likes
5
Downloads
29
Comments
0

5 Embeds 205

http://torquebox.org 196
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 Presentation Transcript

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