6. TorqueBox: what?
•A “real” app server for Ruby
•Founded in 2008
•100% open-source, LGPL license
•Based on JBoss AS and JRuby
•Just released 1.0.0.CR2!
14. AS = Application Server
•interpreter” server +
Not just “web
•appshost multiple, disparate
Can
simultaneously
•apps it hosts services to all the
Provides basic
15. JBoss AS6
•Tomcat for web
•Infinispan for caching
•HornetQ for messaging
•Quartz for scheduling
•PicketBox for authentication
•mod_cluster for clustering
21. Easy Install
(download 1.0.0.CR2 from torquebox.org)
$ unzip torquebox-dist-1.0.0.CR1-bin.zip the jruby
Make sure
found in your path
$ export TORQUEBOX_HOME=$PWD/torquebox-1*
is in $JRUBY_HOME/
$ export JBOSS_HOME=$TORQUEBOX_HOME/jboss
$ export JRUBY_HOME=$TORQUEBOX_HOME/jruby
$ export PATH=$JRUBY_HOME/bin:$PATH
22. Easy Install
(download 1.0.0.CR2 from torquebox.org)
$ unzip torquebox-dist-1.0.0.CR1-bin.zip the jruby
Make sure
found in your path
$ export TORQUEBOX_HOME=$PWD/torquebox-1*
is in $JRUBY_HOME/
$ export JBOSS_HOME=$TORQUEBOX_HOME/jboss
$ export JRUBY_HOME=$TORQUEBOX_HOME/jruby
$ export PATH=$JRUBY_HOME/bin:$PATH
27. Rake Tasks
rake torquebox:run
Run TorqueBox server
rake torquebox:deploy[context_path]
Deploy the app in the current directory
rake torquebox:undeploy
Undeploy the app in the current directory
28. Rake Tasks
Start torquebox:run in its own
shell and leave it running.
Instead of script/server or
shotgun or thin or whatever
else, use torquebox:run.
30. Hot Deployment
$TORQUEBOX_HOME/apps/
• anything added to
apps/ will get deployed
• anything removed from
apps/ will get
undeployed
• anything updated in
apps/ will get
redeployed
• TorqueBox deployers
make JBoss grok YAML
31. Hot Deployment
$TORQUEBOX_HOME/apps/
deployment
•descriptors to
anything added
apps/ will get deployed
• anything removed from
apps/ will get
undeployed
• anything updated in
apps/ will get
redeployed
• TorqueBox deployers
make JBoss grok YAML
32. Hot Deployment
$TORQUEBOX_HOME/apps/
deployment
•descriptors to
anything added
apps/ will get deployed
• anything removed from
apps/ will get
undeployed
• anything updated in
apps/ will get
redeployed
• TorqueBox deployers
make JBoss grok YAML
33. Hot Deployment
$TORQUEBOX_HOME/apps/
• anything added to
apps/ will get deployed
• anything removed from
apps/ will get
undeployed
knob files (zip
•archives)
anything updated in
apps/ will get
redeployed
• TorqueBox deployers
make JBoss grok YAML
34. Hot Deployment
$TORQUEBOX_HOME/apps/
• anything added to
apps/ will get deployed
• anything removed from
apps/ will get
undeployed
knob files (zip
•archives)
anything updated in
apps/ will get
redeployed
• TorqueBox deployers
make JBoss grok YAML
36. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp
env: development
web: The fully-qualified
context: myapp
path to the app.
host: www.yourhost.com
static: public This will be the
environment: value of either
RAILS_ROOT or
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
RACK_ROOT
37. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp
env: development
web: The fully-qualified
context: myapp
path to the app.
host: www.yourhost.com
static: public This will be the
environment: value of either
RAILS_ROOT or
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
RACK_ROOT
38. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp
env: development
web:
context: myapp The runtime mode
host: www.yourhost.com the app. This
of
static: public will be either
environment:
RAILS_ENV or
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com RACK_ENV
39. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp
env: development
web:
context: myapp The runtime mode
host: www.yourhost.com the app. This
of
static: public will be either
environment:
RAILS_ENV or
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com RACK_ENV
40. Deployment Descriptors
The app’s context path
apps/myapp-knob.yml (or “sub URI”):
http://localhost:8080/myapp
application: Can be set via rake:
root: rake torquebox:deploy[myapp]
/path/to/myapp
env: development The default is root:
web: http://localhost:8080/
context: myapp
host: www.yourhost.com
static: public
environment:
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
41. Deployment Descriptors
The app’s context path
apps/myapp-knob.yml (or “sub URI”):
http://localhost:8080/myapp
application: Can be set via rake:
root: rake torquebox:deploy[myapp]
/path/to/myapp
env: development The default is root:
web: http://localhost:8080/
context: myapp
host: www.yourhost.com
static: public
environment:
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
42. Deployment Descriptors
apps/myapp-knob.yml
application:
A list of virtual
root: /path/to/myapp
env: development hostnames to
web: which to bind the
context: myapp
host: www.yourhost.com
static: public
environment:
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
43. Deployment Descriptors
apps/myapp-knob.yml
application:
A list of virtual
root: /path/to/myapp
env: development hostnames to
web: which to bind the
context: myapp
host: www.yourhost.com
static: public
environment:
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
44. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp
env: development The location of
web: the app’s static
context: myapp content, either
host: www.yourhost.com
static: public
absolute or
environment: relative to the
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
45. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp
env: development The location of
web: the app’s static
context: myapp content, either
host: www.yourhost.com
static: public
absolute or
environment: relative to the
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
46. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp Any
env: development
web: environment
context: myapp variables
host: www.yourhost.com
static: public
environment:
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
47. Deployment Descriptors
apps/myapp-knob.yml
application:
root: /path/to/myapp Any
env: development
web: environment
context: myapp variables
host: www.yourhost.com
static: public
environment:
MAIL_HOST: mail.yourhost.com
REPLY_TO: you@yourhost.com
51. jruby-rack
•supported: rails, sinatra, etc
All rack-based frameworks
•deploy from where they apps
No packaging required:
sit on
disk
• No redeploy necessary to see
changes when using rack
reloading, shotgun or rails
development mode
• We use it inside Tomcat
55. Jobs
“Fire every half hour from 10am until
1pm on the third Friday of each
month”
0 */30 10-13 ? * FRI#3
Seconds Minutes Hours DOM Month DOW Year
1-7
1-12 1970-
1-31 SUN-
0-59 0-59 0-23 JAN- 2099
?LW SAT
DEC empty
?L#
56. Jobs
•day ofportable. What is the first
More
the week on BSD again?
What’s cron on Windows?
• Self contained within the app.
No external systems to manage
and keep in sync.
• Full application environment
loaded and available.
67. Backgroundable
lib/something.rb
include TorqueBox::Messaging
class WelcomeEmailer
include Backgroundable
always_background :welcome
def welcome(id)
person = Person.find_by_id(id)
person.send_welcome_spam if person
end
def depart(id)
# do something else
end
end
...
@emailer.welcome(an_id)
@something.background.depart(an_id)
68. Backgroundable
lib/something.rb
include TorqueBox::Messaging
class WelcomeEmailer
include Backgroundable
always_background :welcome
def welcome(id)
person = Person.find_by_id(id)
person.send_welcome_spam if person
end
def depart(id)
# do something else
end
end
...
@emailer.welcome(an_id)
@something.background.depart(an_id)
69. Backgroundable
lib/something.rb
include TorqueBox::Messaging
class WelcomeEmailer
include Backgroundable
always_background :welcome
def welcome(id)
person = Person.find_by_id(id)
person.send_welcome_spam if person
end
def depart(id)
# do something else
end
end
...
@emailer.welcome(an_id)
@something.background.depart(an_id)
70. Backgroundable
lib/something.rb
include TorqueBox::Messaging
class WelcomeEmailer
include Backgroundable
always_background :welcome
def welcome(id)
person = Person.find_by_id(id)
person.send_welcome_spam if person
end
def depart(id)
# do something else
end
end
...
@emailer.welcome(an_id)
@something.background.depart(an_id)
71. Background Processing
Call it from your
controllers, models,
and observers, or even
other tasks. Even in
non-Rails apps!
72. Background Processing
•No extra tables in your database
•No external system to manage
•Little to no config required at all
•System gets redeployed w/app
•Efficient loading of rails
environment
•Automatic load balancing and
retries
•Works on Windows, if you care
73. Queues
Tasks and Backgroundable are
built on top of Queues. Of
course, you may build your
own messaging based apps by
defining your own Queues,
Topics, and their message
Processors yourself.
75. Topics
•interface is different, but
behavior
is the same.
•each message, of a only one
all subscribers
but
topic see
subscriber will see any message
from a queue
• use topics: section of
torquebox.yml to define topics
90. Services
•optional initialize(Hash), start()
Represented as a class with
and stop() methods, which
should each return quickly.
• Typically will start a long-
running loop in a thread and
respond to external events.
• Configured via services: section
in torquebox.yml
92. Services
app/services/time_machine.rb
class TimeMachine
def initialize(opts)
@queue = Queue.new(opts['queue'])
end
def start
Thread.new do
until @done
@queue.publish(Time.now)
sleep(1)
end
end
end
def stop; @done = true; end
end
93. Services
app/services/time_machine.rb
class TimeMachine
def initialize(opts)
@queue = Queue.new(opts['queue'])
end
def start
Thread.new do
until @done
@queue.publish(Time.now)
sleep(1)
end
end
end
def stop; @done = true; end
end
94. Services
app/services/time_machine.rb
class TimeMachine
def initialize(opts)
@queue = Queue.new(opts['queue'])
end
def start
Thread.new do
until @done
@queue.publish(Time.now)
sleep(1)
end
end
end
def stop; @done = true; end
end
95. Services
app/services/time_machine.rb
class TimeMachine
def initialize(opts)
@queue = Queue.new(opts['queue'])
end
def start
Thread.new do
until @done
@queue.publish(Time.now)
sleep(1)
end
end
end
def stop; @done = true; end
end
SLOW THE FUCK DOWN - BUILT ON THE SHOULDERS OF GIANTS\nfocus on the non-web\nthe rest of this talk is the 'why'\n\n
two great technologies\nshoulders of giants\n
1.6.1\n
Why wouldn’t you use it?\nlead with rake/rspec\nFFI support there now, C ext. support soon. Both are slower than on MRI\n
\n
\n
\n
Our goal: bring as much JBoss goodness as we can to Ruby\n- TB is new, but based on stable technologies\n
SLOW THE FUCK DOWN\n
Ensure you have Java 6 installed\n
Ensure you have Java 6 installed\n
Ensure you have Java 6 installed\n
Ensure you have Java 6 installed\n
Ensure you have Java 6 installed\n- rvm\n
jruby's gem_home\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
SLOW THE FUCK DOWN\n
\n
- your app appears to be a java app to Tomcat\n- Sinatra reloading is a bit wonky. Shotgun does work, but a safer bet is to touch your deployment descriptor\n
HIDE THIS SLIDE??\n
\n
Can reside anywhere in the load path, app/jobs is preferred\nOnly a run() method is required\nCommon example: send monthly newsletter\n
\n
more granular than standard cron - L=last day of week/month, W=weekday\nThe last day of the month\nThe last weekday of the month\nThe weekday closest to the 15th\n
instead of each cron job spawning your app\n
SLOW THE FUCK DOWN\nThis is what people use Delayed::Job for\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
/app/tasks or /tasks\nsimilar to Delayed::Job functionality\n
\n
payload is a hash\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Or integrate with a legacy Java app through its queues.\n
\n
\n
\n
\n
\n
\n
These can be anywhere in the load path, but lib and/or app/models is typical\n
concurrency - how many processors are allowed to work at once - default is 1\nconfig - passed to class initializer\n
\n
\n
\n
\n
Ruby messages are Marshaled and Base64-encoded\n
\n
\n
\n
\n
\n
anywhere in the load path, but app/services is preferred\nDON’T EXPLAIN - line by line coming up\n
\n
\n
\n
\n
\n
- built on Infinispan Data Grid\n-clustered requires no hosts config (like memcached)\n-ActiveSupport 3 only\n
\n
\n
How we do it, advantages\ngood blog post on tb.org\n
\n
\n
\n
\n
\n
applies to all runtimes for the app (messaging, jobs, services)\n
SLOW THE FUCK DOWN\narticles posted on torquebox.org detailing clustering config\n\n
reverse proxy / load balancer\nAs server nodes join and leave the cluster, the balancer (mod_cluster) is aware of these changes.\n
As server nodes join and leave the cluster, the balancer (mod_cluster) is aware of these changes.\n
\n
\n
\n
local, invalidation, replicated, distributed\n
\n
\n
\n
80 minute test, # clients increasing every 10m\n
\n
community driven\n
\n
\n
\n
\n
design happens in #torquebox \n
- would you use it?\n- RHT is hiring rubyists in rdu - see me after\n- stickers\n- repeat questions\n