SlideShare une entreprise Scribd logo
1  sur  98
Télécharger pour lire hors ligne
TorqueBox
The  expressiveness  of  Ruby
     The  power  of  Java

       Bob  McWhirter
        JBoss  Fellow
Bob  McWhirter
‣ JBoss  Fellow  at  Red  Hat
‣ Founder  of...
  ‣ The  Codehaus
  ‣ Drools
  ‣ TorqueBox
  ‣ DeltaCloud  API
but  it’s  a  team
What  is  TorqueBox?

TorqueBox  glues  JRuby  to  
the  JBoss  Java  Application  
Server  (JBoss  AS).
Why  JRuby
‣ Real  threads
‣ Many  garbage-­collection  options
‣ Lots  of  JVM  research
‣ Integration  with  Java
‣ Fast!
What  is  JBoss  AS?

JBoss  AS  is  full  JavaEE  
application  server,  providing  
web,  caching,  messaging,  
clustering,  failover,  etc.
Ruby!APIs!/!Programming!Models                               Java!APIs!/!Programming!Models

                                            Message
                                           Processors
                                                              Polyglot
                         WebSockets                           Injection
Sinatra      Rails                            Jobs
                          STOMP                                             POJO        REST      Servlet

      Rack                   Daemons         Tasks                          Spring      JMS       JavaEE


          JRuby!Component!Deployers!&!Gems                                   Java!Enterprise!Services

                                                                                     JBoss Web
           Messaging

                                                                                     Infinispan
             Cache
                                       TorqueBox                                      HornetQ
          Transactions                    Core
                                                                                      Quartz

            Security                   TorqueBox
                                          Core                                       PicketLink



            JRuby with JIT                                   Managed Services Container


                                           Java Virtual Machine
But  Java  is  enterprisey,  
while  Ruby  is  agile...!
“Java  is  a  DSL  for  
taking  large  XML  files  
and  converting  them  
to  stack  traces”
               Scott  Bellware
One  of  our  mantras:


XML  means  we’ve  

<failed/>
First  Order  Goals
Be  a  great  traditional  Ruby  environment
  ‣ Rack
  ‣ Rails
  ‣ Sinatra
  ‣ Padrino
Second  Order  Goals
Be  better  than  a  traditional  environment:
 ‣   Services              ‣ Caching
 ‣   Jobs                  ‣ WebSockets
 ‣   Messaging             ‣ HA/Failover
 ‣   Transactions
First:  web
Your  app
myapp/
    config.ru
    config/
        application.rb
        database.yml
        torquebox.yml
    app/
        views/
        controllers/
        models/
1  AS,  many  apps
                       config/torquebox.yml

application:
    root:  /path/to/myapp

web:
    context:  /
    host:  www.myapp.com

environment:
    RAILS_ENV:  production
    MAIL_HOST:  mail.myapp.com
Compare  to...
                                                                         WEB-­INF/web.xml
<?xml  version="1.0"  encoding="UTF-­8"?>
<web-­app  version="2.5"  
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-­instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-­app_2_5.xsd">

  <context-­param>
      <param-­name>mail.host</param-­name>
      <param-­value>mail.myapp.com</param-­value>
  </context-­param>

  <servlet>
      <display-­name>Servlet1</display-­name>
      <servlet-­name>Servlet1</servlet-­name>
      <servlet-­class>test.Servlet1</servlet-­class>
  </servlet>

  <servlet-­mapping>
      <servlet-­name>Servlet1</servlet-­name>
      <url-­pattern>/Servlet1</url-­pattern>
  </servlet-­mapping>

  <welcome-­file-­list>
      <welcome-­file>index.html</welcome-­file>
  </welcome-­file-­list>

</web-­app>
Make  Love,  not  WAR

Live,  where  it  sits  on  disk.

         No  archive  required.
(caveat)
Requires  runtime  reloading  
support  in  your  framework,  
but  not  redeployment.

 Rails                Rack::Reloader
Works  as  
expected,
almost  
boring

              http://www.flickr.com/photos/djbadly/2052098189/
Second  order  goal:


services
Daemons!
start()


          ...time  passes...


                               stop()
Example  service
                  app/services/my_service.rb
class  MyServer

    def  initialize(opts)
    end

    def  start
    end

    def  stop
    end

end
Service  config
                           config/torquebox.yml


services:

    MyService:
        some_key:  some_value

    MyCriticalService:
        singleton:  true
singleton?
             true
 Ensures  one  (and  only  one)  
instance  is  running  within  the  
cluster  at  a  time,  with  failover.
singleton?
  false
   (default)
Second  order  goal:

scheduled  jobs
cron-­like

-­ every  3  hours...
-­ the  first  of  each  month...
-­ on  Tuesdays...
-­ when  the  world  ends...



                                http://www.flickr.com/photos/spine/2408967576/
Job  example
                              apps/jobs/my_job.rb

class  MyJob
    
    def  run()

        #  your  code  here

    end

end
Job  config
                        config/torquebox.yml
jobs:
    monthly_reminder:
        description:  sends  reminders
        job:  MyJob
        cron:  ‘0  0  0  1  *  ?’
        singleton:  true

    file_cleaner:
        description:  clean  files  on  node
        job:  FileCleaner
        cron:  ‘5  *  *  *  *  ?’
Second  order  goal:

messaging
           messaging
                           messaging
           (we  really  like  messaging)
Darn  zippy  JMS  broker
Where  to,  my  friend?
                          config/torquebox.yml


queues:
    /queues/puppies:
    /queues/kittens:
        durable:  false

topics:
    /topics/memes:
Consumer           Consumer   Consumer           Consumer




           Topic                         Queue
Let’s  go!
                          arbitrary_app_stuff.rb

class  MyController  <  ApplicationController

    include  TorqueBox::Injectors  

    def  index
        @queue  =  inject(  ‘/queues/puppies’  )
        @queue.publish(  “Oh,  puppies!”  )
    end

end
Now  arriving...
                app/processors/my_processor
include  TorqueBox::Messaging

class  MyProcessor  <  MessageProcessor

    def  initialize(opts)
    end

    def  on_message(body)
        #  your  code  here.
    end

end
Processor  config
                          config/torquebox.yml

messaging:
    /queues/puppies:
        MyHandler:
            concurrency:  5
            config:
                some_key:  some_value

    /queues/kittens:
        MyOtherHandler:
            singleton:  true
But  that’s  not  all!
What  makes  
messaging  special?
Async



http://www.flickr.com/photos/photogaby/4129740673/
Backgroundables

Go  asynchronous  
without  having  to  think  
about  messaging.
Enabling
                           my_arbitrary_file.rb

class  User

    include  TorqueBox::Messaging::Backgroundable

    def  do_something_slowly()
        upload_over_300baud_modem()
    end

end
What?

Teaches  your  class  how  to  
invoke  methods  across  an  
implicit  queue.
               Yay  mix-­ins!
Using  explicitly
                 my_other_arbitrary_file.rb



u  =  User.new
u.do_something_slowly()
u.background.do_something_slowly()
Forcing
                           my_arbitrary_file.rb

class  User

    include  TorqueBox::Messaging::Backgroundable
    always_background  :do_something_slowly

    def  do_something_slowly()
        upload_over_300baud_modem()
    end

end
Using  implicitly
             my_other_arbitrary_file.rb




u  =  User.new
u.do_something_slowly()
The  FUTURE!
future  =  user.do_something_slowly()
future.started?
future.complete?
future.error?
future.result
Progress!
class  User

    include  TorqueBox::Backgroundable
    always_background  :do_something_slowly

    def  do_something_slowly
        upload_over_modem()
        future.status  =  “uploaded”

        alert_authorities
        future.status  =  “alerted”
    end
end
Query

future  =  user.do_something_slowly()
future.status_changed?
future.status  #  =>  “uploaded”
Second  order  goal:


transactions
Transactions
Queue               Database   Infinispan




        Your!Code                Topic
[                                                ]
          Transactions
  Queue               Database         Infinispan




          Your!Code                      Topic



XA  distributed,  multi-­resource  transaction
XA
  Everything  succeeds  or  everything  fails

‣ HornetQ  supports  XA
‣ Infinispan  supports  XA
‣ TorqueBox  makes  ActiveRecord  
  support  XA,  if  your  database  does.
Second  order  goal:


caching        and  more
Infinispan

Node            Node      Node         Node


Item #1        Item #1    Item #2      Item #3
Item #4        Item #2    Item #3      Item #4



          Replicated  &  Distributed
Replace  
       memcached

Places  Rails  can  use  memcached?
Now  you’re  using  Infinispan.
As  an  object-­store


Usable  behind  DataMapper  through  
dm-­infinispan-­adapter.
Directly
                        my_arbitrary_file.rb


my_cache  =  TorqueBoxStore.new(
                          :name=>‘my-­cache’,
                          :mode=>:replicated
                      )
my_cache.put(...)
my_cache.get(...)
Clustered  web  sessions...
Second  order  goal:


websockets
to  the  browser



Stream-­Oriented  Message  Protocol


 (I  did  say  we  really  really  liked  messaging)
http://www.flickr.com/photos/greencolander/4299692892/




 Bare  WebSockets  and  
clusters  don’t  get  along.
WebSockets  is  already  
frame-­based,  not  streaming...


          Use  messaging!
But  directly  exposing  your  JMS  
to  the  internet  seems  unwise...




        http://www.flickr.com/photos/ell-­r-­brown/4686613540/
Stomplets  act  as  a  controller  
between  user  and  JMS.
Browser   Stomplet   JMS!Stuff
Example  Stomplet
              app/stomplets/my_stomplet.rb
class  MyStomplet

    def  on_subscribe(subscriber)
    end

    def  on_unsubscribe(subscriber)
    end

    def  on_message(stomp_message,  session)
    end

end
Configuration
                         config/torquebox.yml



stomp:
    stomplets:
        animals:
            route:  ‘/animals/:type’
            class:  MyStomplet
JMS  helpers


subscribe_to(  subscriber,  jms_dest  )

send_to(  jms_dest,  message,  headers={}  )
Second  order  goal:


injection
Resource  Injection

‣ Inversion  of  control
‣ Allows  for  easier  testing
‣ Inject  non-­Ruby  things
Injectables

‣ Services
‣ Queues  &  Topics
‣ Java  CDI  components
Destinations


inject(  ‘/queues/kittens’  ).publish(...)

inject(  ‘/topics/puppies’  ).publish(...)
CDI
                    MyJavaThing.java

package  com.mycorp;;
@ApplicationScoped
public  class  MyJavaThing  {
    public  void  frob()  {  ...}
}
CDI
                      my_arbitrary_file.rb




inject(  com.mycorp.MyJavaThing  ).frob()
Clustering
There  is  no  cluster  (noun),
but  things  can  cluster  (verb).
Clusterstuff
‣ Web  sessions
‣ Web  load-­balancing
‣ Caches
‣ Messaging  destinations
‣ HA  coordination
JGroups
Many  discovery  and  communication  
options.
‣ Multicast
‣ Rendezvous
‣ S3                              except  
                           eat:
                       (Cav netQ)
‣ File                    Hor
mod_cluster

     httpd!+!mod_cluster




AS           AS            AS
performance
Throughput
120



80



40



 0

                  40min

      TorqueBox
      Unicorn
      Passenger
                          Higher  is  better
      Trinidad
Latency
  65s


  16s


   4s



   1s


256ms

64ms

                       40min

        TorqueBox
        Unicorn
        Passenger
                               Lower  is  better
        Trinidad
CPU  Usage
80


60


40


20


 0

                 40min

     TorqueBox
     Unicorn
     Passenger
                         Lower  is  better
     Trinidad
Free  Memory
7gb

6gb

5gb

4gb

3gb

2gb

1gb

  0

                  40min

      TorqueBox
      Unicorn
      Passenger
                          Higher  is  better
      Trinidad
Management
Managing  groups  of  servers  is  
orthogonal  to  the  clustering  of  
servers.
API




                         Domain!Controller



                 API                          API

      Host!Controller                         Host!Controller

API                                                             API

AS          AS          AS               AS         AS           AS
Ecosystem
Backstage

Dashboard  to  monitor  and  control  
Ruby  components.


With  a  RESTful  API.
StompBox

Git-­based  application  
deployment  straight  to  
your  server.
TorqueSpec

RSpec  enhancements  for  integration  
testing.
Start  TorqueBox  &  deploy  apps  are  
part  of  your  specs.
In-­container  testing,  too!
Cloudrific!
‣   Ruby
‣   Java
‣   PHP      openshift.redhat.com
‣   Python
‣   Perl
‣ Multi-­tenant  machines
‣ High  density  (let  OS  swap)
‣ Git-­based  deployment


‣ Constrained  to  achieve  density
‣ SELinux  to  secure  tenants
Resources

‣ http://torquebox.org/
‣ http://github.com/torquebox/torquebox
‣ #torquebox  on  Freenode
‣ @torquebox  on  Twitter
‣ The  tall  guy  up  front
http://www.flickr.com/photos/21496790@N06/5065834411/
Hey,  

thanks  
for  having  me!



                   http://www.flickr.com/photos/stevendepolo/4582437563/

Contenu connexe

Tendances

TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosBruno Oliveira
 
JUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBoxJUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBoxmarekgoldmann
 
JUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinderJUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrindermarekgoldmann
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011tobiascrawley
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011tobiascrawley
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprisebenbrowning
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121WANGCHOU LU
 
Apache camel overview dec 2011
Apache camel overview dec 2011Apache camel overview dec 2011
Apache camel overview dec 2011Marcelo Jabali
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th yearKoichi Sasada
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)ngotogenome
 
Spring into rails
Spring into railsSpring into rails
Spring into railsHiro Asari
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013Stéphane Maldini
 
Apache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source IntegrationApache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source Integrationprajods
 

Tendances (20)

TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
 
JUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBoxJUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBox
 
JUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinderJUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinder
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Ruby 2.4 Internals
Ruby 2.4 InternalsRuby 2.4 Internals
Ruby 2.4 Internals
 
Apache camel overview dec 2011
Apache camel overview dec 2011Apache camel overview dec 2011
Apache camel overview dec 2011
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
First Day With J Ruby
First Day With J RubyFirst Day With J Ruby
First Day With J Ruby
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th year
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013
 
Apache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source IntegrationApache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source Integration
 

Similaire à TorqueBox at DC:JBUG - November 2011

RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteDr Nic Williams
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best PracticesEric Bottard
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - DeploymentFabio Akita
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)Flowdock
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Toolsguest05c09d
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 
Advanced Container Management and Scheduling
Advanced Container Management and SchedulingAdvanced Container Management and Scheduling
Advanced Container Management and SchedulingAmazon Web Services
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvarsSam Marley-Jarrett
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
Deploying JRuby Web Applications
Deploying JRuby Web ApplicationsDeploying JRuby Web Applications
Deploying JRuby Web ApplicationsJoe Kutner
 
Spring, Functions, Serverless and You
Spring, Functions, Serverless and YouSpring, Functions, Serverless and You
Spring, Functions, Serverless and YouVMware Tanzu
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2Merixstudio
 
Embulk, an open-source plugin-based parallel bulk data loader
Embulk, an open-source plugin-based parallel bulk data loaderEmbulk, an open-source plugin-based parallel bulk data loader
Embulk, an open-source plugin-based parallel bulk data loaderSadayuki Furuhashi
 
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012Saleem Ansari
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails DevsDiacode
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task QueueRichard Leland
 

Similaire à TorqueBox at DC:JBUG - November 2011 (20)

RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
Introducing spring
Introducing springIntroducing spring
Introducing spring
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Advanced Container Management and Scheduling
Advanced Container Management and SchedulingAdvanced Container Management and Scheduling
Advanced Container Management and Scheduling
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Deploying JRuby Web Applications
Deploying JRuby Web ApplicationsDeploying JRuby Web Applications
Deploying JRuby Web Applications
 
Spring, Functions, Serverless and You
Spring, Functions, Serverless and YouSpring, Functions, Serverless and You
Spring, Functions, Serverless and You
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2
 
Embulk, an open-source plugin-based parallel bulk data loader
Embulk, an open-source plugin-based parallel bulk data loaderEmbulk, an open-source plugin-based parallel bulk data loader
Embulk, an open-source plugin-based parallel bulk data loader
 
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
 
Deployment de Rails
Deployment de RailsDeployment de Rails
Deployment de Rails
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 

Dernier

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
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
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
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
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Dernier (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
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
 
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
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
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
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

TorqueBox at DC:JBUG - November 2011

  • 1. TorqueBox The  expressiveness  of  Ruby The  power  of  Java Bob  McWhirter JBoss  Fellow
  • 2. Bob  McWhirter ‣ JBoss  Fellow  at  Red  Hat ‣ Founder  of... ‣ The  Codehaus ‣ Drools ‣ TorqueBox ‣ DeltaCloud  API
  • 4. What  is  TorqueBox? TorqueBox  glues  JRuby  to   the  JBoss  Java  Application   Server  (JBoss  AS).
  • 5. Why  JRuby ‣ Real  threads ‣ Many  garbage-­collection  options ‣ Lots  of  JVM  research ‣ Integration  with  Java ‣ Fast!
  • 6. What  is  JBoss  AS? JBoss  AS  is  full  JavaEE   application  server,  providing   web,  caching,  messaging,   clustering,  failover,  etc.
  • 7. Ruby!APIs!/!Programming!Models Java!APIs!/!Programming!Models Message Processors Polyglot WebSockets Injection Sinatra Rails Jobs STOMP POJO REST Servlet Rack Daemons Tasks Spring JMS JavaEE JRuby!Component!Deployers!&!Gems Java!Enterprise!Services JBoss Web Messaging Infinispan Cache TorqueBox HornetQ Transactions Core Quartz Security TorqueBox Core PicketLink JRuby with JIT Managed Services Container Java Virtual Machine
  • 8. But  Java  is  enterprisey,   while  Ruby  is  agile...!
  • 9. “Java  is  a  DSL  for   taking  large  XML  files   and  converting  them   to  stack  traces” Scott  Bellware
  • 10. One  of  our  mantras: XML  means  we’ve   <failed/>
  • 11. First  Order  Goals Be  a  great  traditional  Ruby  environment ‣ Rack ‣ Rails ‣ Sinatra ‣ Padrino
  • 12. Second  Order  Goals Be  better  than  a  traditional  environment: ‣ Services ‣ Caching ‣ Jobs ‣ WebSockets ‣ Messaging ‣ HA/Failover ‣ Transactions
  • 14. Your  app myapp/    config.ru    config/        application.rb        database.yml        torquebox.yml    app/        views/        controllers/        models/
  • 15. 1  AS,  many  apps config/torquebox.yml application:    root:  /path/to/myapp web:    context:  /    host:  www.myapp.com environment:    RAILS_ENV:  production    MAIL_HOST:  mail.myapp.com
  • 16. Compare  to... WEB-­INF/web.xml <?xml  version="1.0"  encoding="UTF-­8"?> <web-­app  version="2.5"          xmlns="http://java.sun.com/xml/ns/javaee"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-­instance"        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-­app_2_5.xsd">  <context-­param>      <param-­name>mail.host</param-­name>      <param-­value>mail.myapp.com</param-­value>  </context-­param>  <servlet>      <display-­name>Servlet1</display-­name>      <servlet-­name>Servlet1</servlet-­name>      <servlet-­class>test.Servlet1</servlet-­class>  </servlet>  <servlet-­mapping>      <servlet-­name>Servlet1</servlet-­name>      <url-­pattern>/Servlet1</url-­pattern>  </servlet-­mapping>  <welcome-­file-­list>      <welcome-­file>index.html</welcome-­file>  </welcome-­file-­list> </web-­app>
  • 17. Make  Love,  not  WAR Live,  where  it  sits  on  disk. No  archive  required.
  • 18. (caveat) Requires  runtime  reloading   support  in  your  framework,   but  not  redeployment. Rails                Rack::Reloader
  • 19. Works  as   expected, almost   boring http://www.flickr.com/photos/djbadly/2052098189/
  • 21. Daemons! start() ...time  passes... stop()
  • 22. Example  service app/services/my_service.rb class  MyServer    def  initialize(opts)    end    def  start    end    def  stop    end end
  • 23. Service  config config/torquebox.yml services:    MyService:        some_key:  some_value    MyCriticalService:        singleton:  true
  • 24. singleton? true Ensures  one  (and  only  one)   instance  is  running  within  the   cluster  at  a  time,  with  failover.
  • 25. singleton? false (default)
  • 27. cron-­like -­ every  3  hours... -­ the  first  of  each  month... -­ on  Tuesdays... -­ when  the  world  ends... http://www.flickr.com/photos/spine/2408967576/
  • 28. Job  example apps/jobs/my_job.rb class  MyJob        def  run()        #  your  code  here    end end
  • 29. Job  config config/torquebox.yml jobs:    monthly_reminder:        description:  sends  reminders        job:  MyJob        cron:  ‘0  0  0  1  *  ?’        singleton:  true    file_cleaner:        description:  clean  files  on  node        job:  FileCleaner        cron:  ‘5  *  *  *  *  ?’
  • 30.
  • 31. Second  order  goal: messaging messaging messaging (we  really  like  messaging)
  • 32. Darn  zippy  JMS  broker
  • 33. Where  to,  my  friend? config/torquebox.yml queues:    /queues/puppies:    /queues/kittens:        durable:  false topics:    /topics/memes:
  • 34. Consumer Consumer Consumer Consumer Topic Queue
  • 35. Let’s  go! arbitrary_app_stuff.rb class  MyController  <  ApplicationController    include  TorqueBox::Injectors      def  index        @queue  =  inject(  ‘/queues/puppies’  )        @queue.publish(  “Oh,  puppies!”  )    end end
  • 36. Now  arriving... app/processors/my_processor include  TorqueBox::Messaging class  MyProcessor  <  MessageProcessor    def  initialize(opts)    end    def  on_message(body)        #  your  code  here.    end end
  • 37. Processor  config config/torquebox.yml messaging:    /queues/puppies:        MyHandler:            concurrency:  5            config:                some_key:  some_value    /queues/kittens:        MyOtherHandler:            singleton:  true
  • 41. Backgroundables Go  asynchronous   without  having  to  think   about  messaging.
  • 42. Enabling my_arbitrary_file.rb class  User    include  TorqueBox::Messaging::Backgroundable    def  do_something_slowly()        upload_over_300baud_modem()    end end
  • 43. What? Teaches  your  class  how  to   invoke  methods  across  an   implicit  queue. Yay  mix-­ins!
  • 44. Using  explicitly my_other_arbitrary_file.rb u  =  User.new u.do_something_slowly() u.background.do_something_slowly()
  • 45. Forcing my_arbitrary_file.rb class  User    include  TorqueBox::Messaging::Backgroundable    always_background  :do_something_slowly    def  do_something_slowly()        upload_over_300baud_modem()    end end
  • 46. Using  implicitly my_other_arbitrary_file.rb u  =  User.new u.do_something_slowly()
  • 47. The  FUTURE! future  =  user.do_something_slowly() future.started? future.complete? future.error? future.result
  • 48. Progress! class  User    include  TorqueBox::Backgroundable    always_background  :do_something_slowly    def  do_something_slowly        upload_over_modem()        future.status  =  “uploaded”        alert_authorities        future.status  =  “alerted”    end end
  • 51. Transactions Queue Database Infinispan Your!Code Topic
  • 52. [ ] Transactions Queue Database Infinispan Your!Code Topic XA  distributed,  multi-­resource  transaction
  • 53. XA Everything  succeeds  or  everything  fails ‣ HornetQ  supports  XA ‣ Infinispan  supports  XA ‣ TorqueBox  makes  ActiveRecord   support  XA,  if  your  database  does.
  • 55. Infinispan Node Node Node Node Item #1 Item #1 Item #2 Item #3 Item #4 Item #2 Item #3 Item #4 Replicated  &  Distributed
  • 56. Replace   memcached Places  Rails  can  use  memcached? Now  you’re  using  Infinispan.
  • 57. As  an  object-­store Usable  behind  DataMapper  through   dm-­infinispan-­adapter.
  • 58. Directly my_arbitrary_file.rb my_cache  =  TorqueBoxStore.new(                          :name=>‘my-­cache’,                          :mode=>:replicated                      ) my_cache.put(...) my_cache.get(...)
  • 61. to  the  browser Stream-­Oriented  Message  Protocol (I  did  say  we  really  really  liked  messaging)
  • 63. WebSockets  is  already   frame-­based,  not  streaming... Use  messaging!
  • 64. But  directly  exposing  your  JMS   to  the  internet  seems  unwise... http://www.flickr.com/photos/ell-­r-­brown/4686613540/
  • 65. Stomplets  act  as  a  controller   between  user  and  JMS.
  • 66. Browser Stomplet JMS!Stuff
  • 67. Example  Stomplet app/stomplets/my_stomplet.rb class  MyStomplet    def  on_subscribe(subscriber)    end    def  on_unsubscribe(subscriber)    end    def  on_message(stomp_message,  session)    end end
  • 68. Configuration config/torquebox.yml stomp:    stomplets:        animals:            route:  ‘/animals/:type’            class:  MyStomplet
  • 69. JMS  helpers subscribe_to(  subscriber,  jms_dest  ) send_to(  jms_dest,  message,  headers={}  )
  • 71. Resource  Injection ‣ Inversion  of  control ‣ Allows  for  easier  testing ‣ Inject  non-­Ruby  things
  • 72. Injectables ‣ Services ‣ Queues  &  Topics ‣ Java  CDI  components
  • 74. CDI MyJavaThing.java package  com.mycorp;; @ApplicationScoped public  class  MyJavaThing  {    public  void  frob()  {  ...} }
  • 75. CDI my_arbitrary_file.rb inject(  com.mycorp.MyJavaThing  ).frob()
  • 77. There  is  no  cluster  (noun), but  things  can  cluster  (verb).
  • 78. Clusterstuff ‣ Web  sessions ‣ Web  load-­balancing ‣ Caches ‣ Messaging  destinations ‣ HA  coordination
  • 79. JGroups Many  discovery  and  communication   options. ‣ Multicast ‣ Rendezvous ‣ S3  except   eat: (Cav netQ) ‣ File Hor
  • 80. mod_cluster httpd!+!mod_cluster AS AS AS
  • 82. Throughput 120 80 40 0 40min TorqueBox Unicorn Passenger Higher  is  better Trinidad
  • 83. Latency 65s 16s 4s 1s 256ms 64ms 40min TorqueBox Unicorn Passenger Lower  is  better Trinidad
  • 84. CPU  Usage 80 60 40 20 0 40min TorqueBox Unicorn Passenger Lower  is  better Trinidad
  • 85. Free  Memory 7gb 6gb 5gb 4gb 3gb 2gb 1gb 0 40min TorqueBox Unicorn Passenger Higher  is  better Trinidad
  • 87. Managing  groups  of  servers  is   orthogonal  to  the  clustering  of   servers.
  • 88. API Domain!Controller API API Host!Controller Host!Controller API API AS AS AS AS AS AS
  • 90. Backstage Dashboard  to  monitor  and  control   Ruby  components. With  a  RESTful  API.
  • 91. StompBox Git-­based  application   deployment  straight  to   your  server.
  • 92. TorqueSpec RSpec  enhancements  for  integration   testing. Start  TorqueBox  &  deploy  apps  are   part  of  your  specs. In-­container  testing,  too!
  • 94. Ruby ‣ Java ‣ PHP openshift.redhat.com ‣ Python ‣ Perl
  • 95. ‣ Multi-­tenant  machines ‣ High  density  (let  OS  swap) ‣ Git-­based  deployment ‣ Constrained  to  achieve  density ‣ SELinux  to  secure  tenants
  • 96. Resources ‣ http://torquebox.org/ ‣ http://github.com/torquebox/torquebox ‣ #torquebox  on  Freenode ‣ @torquebox  on  Twitter ‣ The  tall  guy  up  front
  • 98. Hey,   thanks   for  having  me! http://www.flickr.com/photos/stevendepolo/4582437563/