JRuby
Практика применения
Short history
Short history

• 2001 - the first version of JRuby(by Jan
  Arne Petersen)
Short history

• 2001 - the first version of JRuby(by Jan
  Arne Petersen)
• 2006 - version 0.9.0(by Charles Nutter,
  Thomas Enebo, Ola Bini and Nick Siege)
Short history

• 2001 - the first version of JRuby(by Jan
  Arne Petersen)
• 2006 - version 0.9.0(by Charles Nutter,
  Thomas Enebo, Ola Bini and Nick Siege)
• 2007 - version 1.0(passed all Rails tests)
Why JRuby?
Why JRuby?
• Multithreading
Why JRuby?
• Multithreading
• JVM
Why JRuby?
• Multithreading
• JVM
• Cross-platform
Why JRuby?
• Multithreading
• JVM
• Cross-platform
• Just another .jar
Why JRuby?
• Multithreading
• JVM
• Cross-platform
• Just another .jar
• GUI
Why JRuby?
• Multithreading
• JVM
• Cross-platform
• Just another .jar
• GUI
• Android
JVM
JVM

• Concurrent threading
JVM

• Concurrent threading
• Garbage collectors
JVM

• Concurrent threading
• Garbage collectors
• JIT compiler
JVM

• Concurrent threading
• Garbage collectors
• JIT compiler
• invokedynamic(JDK 7)
Missing features
Missing features
• Memory footprint
Missing features
• Memory footprint
• No Kernel#fork
Missing features
• Memory footprint
• No Kernel#fork
• No continuations(callcc)
Missing features
• Memory footprint
• No Kernel#fork
• No continuations(callcc)
• ObjectSpace off by default(-X+O to enable)
Missing features
• Memory footprint
• No Kernel#fork
• No continuations(callcc)
• ObjectSpace off by default(-X+O to enable)
• set_trace_func off by default(--debug to
  enable)
C extensions


since JRuby 1.6(still experimental)
Easy installing

• rvm install jruby
• rbenv install jruby-1.6.6 (*)
• Download from http://jruby.org
Compatibilities


 Ruby 1.8.7 & 1.9.2 compatible
              (default 1.8)
flag `jruby --1.9` for 1.9.2 compatibility
Nailgun
(since 1.3.0 version)
Nailgun
             (since 1.3.0 version)

Nailgun is a client, protocol, and server for
   running Java programs in the server.
Nailgun
             (since 1.3.0 version)

Nailgun is a client, protocol, and server for
   running Java programs in the server.


          $ jruby --ng-server &
          $ jruby --ng -e "puts 1"
Multi-VM support
  many apps in one process
Multi-VM support
  many apps in one process




            JVM
Multi-VM support
        many apps in one process


JRuby      JRuby   JRuby   JRuby   JRuby




                   JVM
Benchmarks
jruby 1.7.0.dev(JDK 6)   jruby 1.7.0.dev(JDK 7) invokedynamic=false
jruby 1.7.0.dev(JDK 7)   ruby 1.9.3-p0
Benchmarks
    jruby 1.7.0.dev(JDK 6)           jruby 1.7.0.dev(JDK 7) invokedynamic=false
    jruby 1.7.0.dev(JDK 7)           ruby 1.9.3-p0

4


3


2


1


0
                             bench/bench_red_black.rb (sec)
Benchmarks
    jruby 1.7.0.dev(JDK 6)           jruby 1.7.0.dev(JDK 7) invokedynamic=false
    jruby 1.7.0.dev(JDK 7)           ruby 1.9.3-p0

4


3


2


1


0
                             bench/bench_red_black.rb (sec)
Benchmarks
    jruby 1.7.0.dev(JDK 6)           jruby 1.7.0.dev(JDK 7) invokedynamic=false
    jruby 1.7.0.dev(JDK 7)           ruby 1.9.3-p0

4


3


2


1


0
                             bench/bench_red_black.rb (sec)
Benchmarks
    jruby 1.7.0.dev(JDK 6)           jruby 1.7.0.dev(JDK 7) invokedynamic=false
    jruby 1.7.0.dev(JDK 7)           ruby 1.9.3-p0

4


3


2


1


0
                             bench/bench_red_black.rb (sec)
Benchmarks
    jruby 1.7.0.dev(JDK 6)           jruby 1.7.0.dev(JDK 7) invokedynamic=false
    jruby 1.7.0.dev(JDK 7)           ruby 1.9.3-p0

4


3


2


1


0
                             bench/bench_red_black.rb (sec)
jvisualvm
jvisualvm
jvisualvm
JVM + JRuby
JVM + JRuby

• Swing, SWT
JVM + JRuby

• Swing, SWT
• JavaFX
JVM + JRuby

• Swing, SWT
• JavaFX
• Spring & Hibernate
JVM + JRuby

• Swing, SWT
• JavaFX
• Spring & Hibernate
• Scala, Groovy, Jython, Clojure, ...
JVM + JRuby
    Swing
JVM + JRuby
    Swing
RedCar
  SWT
Java + Ruby
Java + Ruby
• require ‘java’
Java + Ruby
• require ‘java’
• Java namespace
Java + Ruby
• require ‘java’
• Java namespace
• Snake case(get_some vs getSome)
Java + Ruby
• require ‘java’
• Java namespace
• Snake case(get_some vs getSome)
• Ruby-style accessors(length= vs setLength)
Java + Ruby
• require ‘java’
• Java namespace
• Snake case(get_some vs getSome)
• Ruby-style accessors(length= vs setLength)
• Converting types
Java + Ruby
• require ‘java’
• Java namespace
• Snake case(get_some vs getSome)
• Ruby-style accessors(length= vs setLength)
• Converting types
• Swing IRB(command: jirb_swing)
Java bridge
  Collections
Java bridge
                 Collections


Java List:
java_list[0]
java_list << 5
java_list += 7
Java bridge
                 Collections


Java List:             Java Map:
java_list[0]           java_list[‘key’]
java_list << 5         java_list[‘key’] = 5
java_list += 7
Java bridge
                 Collections


Java List:             Java Map:
java_list[0]           java_list[‘key’]
java_list << 5         java_list[‘key’] = 5
java_list += 7

         Ruby List:
         [1, 2, 3].to_java :int
         [“string”].to_java :string
Java bridge
                Overloading


Java:
public class Test {
  public boolean isSome(String arg) {...}
  public boolean isSome(int arg) {...}
  public boolean isSome(long arg) {...}
  public boolean isSome(Object arg) {...}
}
Java bridge
                    Overloading


Ruby:
Test.new.java_send :isSome, [Java::long], 1_000
or
class Test
  java_alias :is_some, :isSome, [Java::long]
  ...
end
Java bridge
               Annotations



Java:
@Bean(scope = Scope.PROTOTYPE)
public class Person {
    ...
}
Java bridge
                    Annotations

Ruby:
java_import Bean
java_import Scope

class Person
end

Person.add_class_annotation(Bean: {
   ‘scope’ => Scope.PROTOTYPE
})
Person.become_java!
Java bridge
            Interfaces




Ruby:
class Posts
  include java.util.Iterator
end
JRuby compiler
           Ahead-Of-Time Compilation

$ jrubyc <script name>.rb
$ java -cp .:/path/to/jruby.jar <script name>
JRuby compiler
         Generate .java classes from .rb

$ jrubyc --java <script name>.rb
JRuby compiler

Ruby:
require 'java'

class Vec
  def initialize(x, y)
   @xcoord = x
   @ycoord = y
  end
end
JRuby compiler
Ruby:
require 'java'

class Vec
  java_signature 'Vec(double x, double y)'
  def initialize(x, y)
    @xcoord = x
    @ycoord = y
  end
end
JRuby compiler
Java:
import org.jruby.Ruby;
import org.jruby.RubyObject;
import org.jruby.RubyClass;
...
public class Vec extends RubyObject {
   ...
   public Vec(double x, double y) {
      ...
   }
}
Rake + Ant
Rake + Ant

Ant tasks like Rake tasks:
task :ant_import do
  ant_import
end
Buildr
                 http://buildr.apache.org



    Apache Buildr is a build system for Java-based
applications, including support for Scala, Groovy and a
     growing number of JVM languages and tools.
Buildr
http://buildr.apache.org
Buildr
              http://buildr.apache.org


•   Projects and sub-projects
Buildr
              http://buildr.apache.org


•   Projects and sub-projects
•   Compiling, copying and filtering resources,
    test cases, Javadoc and more
Buildr
              http://buildr.apache.org


•   Projects and sub-projects
•   Compiling, copying and filtering resources,
    test cases, Javadoc and more
•   Builds what has changed since the last release
Buildr
              http://buildr.apache.org


•   Projects and sub-projects
•   Compiling, copying and filtering resources,
    test cases, Javadoc and more
•   Builds what has changed since the last release
•   Support Maven 2.0
Buildr
              http://buildr.apache.org


•   Projects and sub-projects
•   Compiling, copying and filtering resources,
    test cases, Javadoc and more
•   Builds what has changed since the last release
•   Support Maven 2.0
•   Support Ant
Buildr
              http://buildr.apache.org


•   Projects and sub-projects
•   Compiling, copying and filtering resources,
    test cases, Javadoc and more
•   Builds what has changed since the last release
•   Support Maven 2.0
•   Support Ant
•   Buildr is Ruby all the way down
Buildr
                               http://buildr.apache.org
buildfile:
repositories.remote "http://repo.typesafe.com/typesafe/releases/"

desc "The Springmongodb project"
define "SpringMongoDB" do
 project.version = "0.1"
 project.group = "SpringMongoDB"

 run.with "org.jruby:jruby-complete:jar:1.6.6",
       "org.mongodb:mongo-java-driver:jar:2.7.2",
       "org.springframework:spring-core:jar:3.1.0.RELEASE",
       "org.springframework:spring-context:jar:3.1.0.RELEASE",
       "org.springframework:spring-beans:jar:3.1.0.RELEASE",
       'org.springframework.data:spring-data-commons-core:jar:1.1.0.RELEASE',
       "org.springframework.data:spring-data-mongodb:jar:1.0.0.RC1"

 run.using main: ['org.jruby.Main', _(:src, :main, :ruby, "app.rb")]
end
Rawr
                    http://rawr.rubyforge.org




Rawr, a packaging and deployment tool, that allows turns your
code into an executable jar, a .exe for Windows, and a .app for
OS X.
Rawr
http://rawr.rubyforge.org


 $ gem install rawr
 $ rawr install
 ...
 $ rake rawr:jar
Deployment
JRuby-Rack

 Servlet     JRuby-Rack               Rack
                            Rack
container   servlet filter          application
JRuby servers
JRuby servers

    WEBrick
JRuby servers

    WEBrick

    Trinidad
JRuby servers

    WEBrick

    Trinidad

   TorqueBox
TorqueBox
http://torquebox.org
TorqueBox
http://torquebox.org
TorqueBox
                http://torquebox.org




Installation:
jruby -S gem install torquebox-server --pre
TorqueBox
        http://torquebox.org




Usage:
torquebox deploy ~/Projects/rails_app
torquebox run
Warbler

 Warbler is a gem to make a Java jar or war file
out of any Ruby, Rails, Merb, or Rack application.
Warbler

Installation:
jruby -S gem install warbler
Warbler
Usage:
Warbler
Warbler
Standalone application:
Tuning flags
Tuning flags

• --server - server compiler
Tuning flags

• --server - server compiler
• -Xmx - max heap size
Tuning flags

• --server - server compiler
• -Xmx - max heap size
• -XX:+UnlockExperimentalVMOptions
  -XX:+UseG1GC - new GC(JDK 7)
Clouds
• Amazon Elastic Beans(http://aws.amazon.com/
  elasticbeanstalk/)

• Jelastic(http://jelastic.com)
• Engine Yard(http://www.engineyard.com)
• Google App Engine(http://
  appengine.google.com)
Hot Spot
Bot Hunter
Bot Hunter


• Multithreading
Bot Hunter


• Multithreading
• Some logic on Scala
Yukihiro Matsumoto: “I would remove the
thread and add actors or some other more
advanced concurrency features”.
Akka
              http://akka.io/



Simpler Concurrency, Scalability & Fault-
       tolerance through Actors




                                    slidesha.re/akka-scala-days-2010
Actor Model of
 Concurrency




             slidesha.re/akka-scala-days-2010
Actor Model of
        Concurrency
• Implements Message-Passing Concurrency




                                   slidesha.re/akka-scala-days-2010
Actor Model of
        Concurrency
• Implements Message-Passing Concurrency
• Share nothing




                                   slidesha.re/akka-scala-days-2010
Actor Model of
        Concurrency
• Implements Message-Passing Concurrency
• Share nothing
• Isolated lightweight process


                                   slidesha.re/akka-scala-days-2010
Actor Model of
        Concurrency
• Implements Message-Passing Concurrency
• Share nothing
• Isolated lightweight process
• Communicates through messages

                                   slidesha.re/akka-scala-days-2010
Actor Model of
        Concurrency
• Implements Message-Passing Concurrency
• Share nothing
• Isolated lightweight process
• Communicates through messages
• Asynchronous and non-blocking
                                   slidesha.re/akka-scala-days-2010
Actor Model of
        Concurrency
• Implements Message-Passing Concurrency
• Share nothing
• Isolated lightweight process
• Communicates through messages
• Asynchronous and non-blocking
• Each actor has a mailbox(message queue)
                                    slidesha.re/akka-scala-days-2010
Two different models




                 slidesha.re/akka-scala-days-2010
Two different models

• Thread-based




                  slidesha.re/akka-scala-days-2010
Two different models

• Thread-based
• Event-based



                  slidesha.re/akka-scala-days-2010
Two different models

• Thread-based
• Event-based
 • Very lightweight(~300 bytes per actor)


                                   slidesha.re/akka-scala-days-2010
Two different models

• Thread-based
• Event-based
 • Very lightweight(~300 bytes per actor)
 • Can easily create millions on a single
    workstation


                                   slidesha.re/akka-scala-days-2010
Example


          slidesha.re/akka-scala-days-2010
Server code
class HelloWorldActor extends UntypedActor {
  public void onReceive(Object msg) {
     getContext().tryReply(msg + " World");
  }
}
remote().start("localhost", 2552).register(
  "hello-service",
    actorOf(HelloWorldActor.class));




                                         slidesha.re/akka-scala-days-2010
Client code

actor = Actors.remote.actorFor(
  "hello-service", "localhost", 2552)
res = actor.ask("Hello").get




                                        slidesha.re/akka-scala-days-2010
The Bad
java.lang.NullPointerException
Groovy
Questions?


Email: klimtimothy@gmail.com

Практики применения JRuby

  • 1.
  • 2.
  • 3.
    Short history • 2001- the first version of JRuby(by Jan Arne Petersen)
  • 4.
    Short history • 2001- the first version of JRuby(by Jan Arne Petersen) • 2006 - version 0.9.0(by Charles Nutter, Thomas Enebo, Ola Bini and Nick Siege)
  • 5.
    Short history • 2001- the first version of JRuby(by Jan Arne Petersen) • 2006 - version 0.9.0(by Charles Nutter, Thomas Enebo, Ola Bini and Nick Siege) • 2007 - version 1.0(passed all Rails tests)
  • 6.
  • 7.
  • 8.
  • 9.
    Why JRuby? • Multithreading •JVM • Cross-platform
  • 10.
    Why JRuby? • Multithreading •JVM • Cross-platform • Just another .jar
  • 11.
    Why JRuby? • Multithreading •JVM • Cross-platform • Just another .jar • GUI
  • 12.
    Why JRuby? • Multithreading •JVM • Cross-platform • Just another .jar • GUI • Android
  • 13.
  • 14.
  • 15.
  • 16.
    JVM • Concurrent threading •Garbage collectors • JIT compiler
  • 17.
    JVM • Concurrent threading •Garbage collectors • JIT compiler • invokedynamic(JDK 7)
  • 18.
  • 19.
  • 20.
    Missing features • Memoryfootprint • No Kernel#fork
  • 21.
    Missing features • Memoryfootprint • No Kernel#fork • No continuations(callcc)
  • 22.
    Missing features • Memoryfootprint • No Kernel#fork • No continuations(callcc) • ObjectSpace off by default(-X+O to enable)
  • 23.
    Missing features • Memoryfootprint • No Kernel#fork • No continuations(callcc) • ObjectSpace off by default(-X+O to enable) • set_trace_func off by default(--debug to enable)
  • 24.
    C extensions since JRuby1.6(still experimental)
  • 25.
    Easy installing • rvminstall jruby • rbenv install jruby-1.6.6 (*) • Download from http://jruby.org
  • 26.
    Compatibilities Ruby 1.8.7& 1.9.2 compatible (default 1.8) flag `jruby --1.9` for 1.9.2 compatibility
  • 27.
  • 28.
    Nailgun (since 1.3.0 version) Nailgun is a client, protocol, and server for running Java programs in the server.
  • 29.
    Nailgun (since 1.3.0 version) Nailgun is a client, protocol, and server for running Java programs in the server. $ jruby --ng-server & $ jruby --ng -e "puts 1"
  • 30.
    Multi-VM support many apps in one process
  • 31.
    Multi-VM support many apps in one process JVM
  • 32.
    Multi-VM support many apps in one process JRuby JRuby JRuby JRuby JRuby JVM
  • 33.
    Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0
  • 34.
    Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0 4 3 2 1 0 bench/bench_red_black.rb (sec)
  • 35.
    Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0 4 3 2 1 0 bench/bench_red_black.rb (sec)
  • 36.
    Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0 4 3 2 1 0 bench/bench_red_black.rb (sec)
  • 37.
    Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0 4 3 2 1 0 bench/bench_red_black.rb (sec)
  • 38.
    Benchmarks jruby 1.7.0.dev(JDK 6) jruby 1.7.0.dev(JDK 7) invokedynamic=false jruby 1.7.0.dev(JDK 7) ruby 1.9.3-p0 4 3 2 1 0 bench/bench_red_black.rb (sec)
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
    JVM + JRuby •Swing, SWT
  • 44.
    JVM + JRuby •Swing, SWT • JavaFX
  • 45.
    JVM + JRuby •Swing, SWT • JavaFX • Spring & Hibernate
  • 46.
    JVM + JRuby •Swing, SWT • JavaFX • Spring & Hibernate • Scala, Groovy, Jython, Clojure, ...
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
    Java + Ruby •require ‘java’
  • 52.
    Java + Ruby •require ‘java’ • Java namespace
  • 53.
    Java + Ruby •require ‘java’ • Java namespace • Snake case(get_some vs getSome)
  • 54.
    Java + Ruby •require ‘java’ • Java namespace • Snake case(get_some vs getSome) • Ruby-style accessors(length= vs setLength)
  • 55.
    Java + Ruby •require ‘java’ • Java namespace • Snake case(get_some vs getSome) • Ruby-style accessors(length= vs setLength) • Converting types
  • 56.
    Java + Ruby •require ‘java’ • Java namespace • Snake case(get_some vs getSome) • Ruby-style accessors(length= vs setLength) • Converting types • Swing IRB(command: jirb_swing)
  • 57.
    Java bridge Collections
  • 58.
    Java bridge Collections Java List: java_list[0] java_list << 5 java_list += 7
  • 59.
    Java bridge Collections Java List: Java Map: java_list[0] java_list[‘key’] java_list << 5 java_list[‘key’] = 5 java_list += 7
  • 60.
    Java bridge Collections Java List: Java Map: java_list[0] java_list[‘key’] java_list << 5 java_list[‘key’] = 5 java_list += 7 Ruby List: [1, 2, 3].to_java :int [“string”].to_java :string
  • 61.
    Java bridge Overloading Java: public class Test { public boolean isSome(String arg) {...} public boolean isSome(int arg) {...} public boolean isSome(long arg) {...} public boolean isSome(Object arg) {...} }
  • 62.
    Java bridge Overloading Ruby: Test.new.java_send :isSome, [Java::long], 1_000 or class Test java_alias :is_some, :isSome, [Java::long] ... end
  • 63.
    Java bridge Annotations Java: @Bean(scope = Scope.PROTOTYPE) public class Person { ... }
  • 64.
    Java bridge Annotations Ruby: java_import Bean java_import Scope class Person end Person.add_class_annotation(Bean: { ‘scope’ => Scope.PROTOTYPE }) Person.become_java!
  • 65.
    Java bridge Interfaces Ruby: class Posts include java.util.Iterator end
  • 66.
    JRuby compiler Ahead-Of-Time Compilation $ jrubyc <script name>.rb $ java -cp .:/path/to/jruby.jar <script name>
  • 67.
    JRuby compiler Generate .java classes from .rb $ jrubyc --java <script name>.rb
  • 68.
    JRuby compiler Ruby: require 'java' classVec def initialize(x, y) @xcoord = x @ycoord = y end end
  • 69.
    JRuby compiler Ruby: require 'java' classVec java_signature 'Vec(double x, double y)' def initialize(x, y) @xcoord = x @ycoord = y end end
  • 70.
    JRuby compiler Java: import org.jruby.Ruby; importorg.jruby.RubyObject; import org.jruby.RubyClass; ... public class Vec extends RubyObject { ... public Vec(double x, double y) { ... } }
  • 71.
  • 72.
    Rake + Ant Anttasks like Rake tasks: task :ant_import do ant_import end
  • 73.
    Buildr http://buildr.apache.org Apache Buildr is a build system for Java-based applications, including support for Scala, Groovy and a growing number of JVM languages and tools.
  • 74.
  • 75.
    Buildr http://buildr.apache.org • Projects and sub-projects
  • 76.
    Buildr http://buildr.apache.org • Projects and sub-projects • Compiling, copying and filtering resources, test cases, Javadoc and more
  • 77.
    Buildr http://buildr.apache.org • Projects and sub-projects • Compiling, copying and filtering resources, test cases, Javadoc and more • Builds what has changed since the last release
  • 78.
    Buildr http://buildr.apache.org • Projects and sub-projects • Compiling, copying and filtering resources, test cases, Javadoc and more • Builds what has changed since the last release • Support Maven 2.0
  • 79.
    Buildr http://buildr.apache.org • Projects and sub-projects • Compiling, copying and filtering resources, test cases, Javadoc and more • Builds what has changed since the last release • Support Maven 2.0 • Support Ant
  • 80.
    Buildr http://buildr.apache.org • Projects and sub-projects • Compiling, copying and filtering resources, test cases, Javadoc and more • Builds what has changed since the last release • Support Maven 2.0 • Support Ant • Buildr is Ruby all the way down
  • 81.
    Buildr http://buildr.apache.org buildfile: repositories.remote "http://repo.typesafe.com/typesafe/releases/" desc "The Springmongodb project" define "SpringMongoDB" do project.version = "0.1" project.group = "SpringMongoDB" run.with "org.jruby:jruby-complete:jar:1.6.6", "org.mongodb:mongo-java-driver:jar:2.7.2", "org.springframework:spring-core:jar:3.1.0.RELEASE", "org.springframework:spring-context:jar:3.1.0.RELEASE", "org.springframework:spring-beans:jar:3.1.0.RELEASE", 'org.springframework.data:spring-data-commons-core:jar:1.1.0.RELEASE', "org.springframework.data:spring-data-mongodb:jar:1.0.0.RC1" run.using main: ['org.jruby.Main', _(:src, :main, :ruby, "app.rb")] end
  • 82.
    Rawr http://rawr.rubyforge.org Rawr, a packaging and deployment tool, that allows turns your code into an executable jar, a .exe for Windows, and a .app for OS X.
  • 83.
    Rawr http://rawr.rubyforge.org $ geminstall rawr $ rawr install ... $ rake rawr:jar
  • 84.
  • 85.
    JRuby-Rack Servlet JRuby-Rack Rack Rack container servlet filter application
  • 86.
  • 87.
  • 88.
    JRuby servers WEBrick Trinidad
  • 89.
    JRuby servers WEBrick Trinidad TorqueBox
  • 90.
  • 91.
  • 92.
    TorqueBox http://torquebox.org Installation: jruby -S gem install torquebox-server --pre
  • 93.
    TorqueBox http://torquebox.org Usage: torquebox deploy ~/Projects/rails_app torquebox run
  • 94.
    Warbler Warbler isa gem to make a Java jar or war file out of any Ruby, Rails, Merb, or Rack application.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
    Tuning flags • --server- server compiler
  • 101.
    Tuning flags • --server- server compiler • -Xmx - max heap size
  • 102.
    Tuning flags • --server- server compiler • -Xmx - max heap size • -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC - new GC(JDK 7)
  • 103.
    Clouds • Amazon ElasticBeans(http://aws.amazon.com/ elasticbeanstalk/) • Jelastic(http://jelastic.com) • Engine Yard(http://www.engineyard.com) • Google App Engine(http:// appengine.google.com)
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
    Yukihiro Matsumoto: “Iwould remove the thread and add actors or some other more advanced concurrency features”.
  • 109.
    Akka http://akka.io/ Simpler Concurrency, Scalability & Fault- tolerance through Actors slidesha.re/akka-scala-days-2010
  • 110.
    Actor Model of Concurrency slidesha.re/akka-scala-days-2010
  • 111.
    Actor Model of Concurrency • Implements Message-Passing Concurrency slidesha.re/akka-scala-days-2010
  • 112.
    Actor Model of Concurrency • Implements Message-Passing Concurrency • Share nothing slidesha.re/akka-scala-days-2010
  • 113.
    Actor Model of Concurrency • Implements Message-Passing Concurrency • Share nothing • Isolated lightweight process slidesha.re/akka-scala-days-2010
  • 114.
    Actor Model of Concurrency • Implements Message-Passing Concurrency • Share nothing • Isolated lightweight process • Communicates through messages slidesha.re/akka-scala-days-2010
  • 115.
    Actor Model of Concurrency • Implements Message-Passing Concurrency • Share nothing • Isolated lightweight process • Communicates through messages • Asynchronous and non-blocking slidesha.re/akka-scala-days-2010
  • 116.
    Actor Model of Concurrency • Implements Message-Passing Concurrency • Share nothing • Isolated lightweight process • Communicates through messages • Asynchronous and non-blocking • Each actor has a mailbox(message queue) slidesha.re/akka-scala-days-2010
  • 117.
    Two different models slidesha.re/akka-scala-days-2010
  • 118.
    Two different models •Thread-based slidesha.re/akka-scala-days-2010
  • 119.
    Two different models •Thread-based • Event-based slidesha.re/akka-scala-days-2010
  • 120.
    Two different models •Thread-based • Event-based • Very lightweight(~300 bytes per actor) slidesha.re/akka-scala-days-2010
  • 121.
    Two different models •Thread-based • Event-based • Very lightweight(~300 bytes per actor) • Can easily create millions on a single workstation slidesha.re/akka-scala-days-2010
  • 122.
    Example slidesha.re/akka-scala-days-2010
  • 123.
    Server code class HelloWorldActorextends UntypedActor { public void onReceive(Object msg) { getContext().tryReply(msg + " World"); } } remote().start("localhost", 2552).register( "hello-service", actorOf(HelloWorldActor.class)); slidesha.re/akka-scala-days-2010
  • 124.
    Client code actor =Actors.remote.actorFor( "hello-service", "localhost", 2552) res = actor.ask("Hello").get slidesha.re/akka-scala-days-2010
  • 125.
  • 126.
  • 127.
  • 128.