Given at Surrey Ruby Users Group in Guildford - Jan 2013
References other talks and videos throughout. Borrows benchmarks and material from the Torquebox team so apologies for the blatant plagiarism.
anywhere • Split into Java API, and JVM • Handles compatibility with host OS • 256 bytecodes*, Java standard classes • Exceptions, GC, memory and threads *of which, only 10 matter
•15 years engineering by whole teams • Free, Open Source • Fastest VM - comparable with C • Best GCs to choose from • All JVMs full parallel threaded • All platforms JRuby • started in 2001! • sponsored by RedHat • Free, Open Source • same memory model / threading as the JVM • Constantly refined for speed and efficiency
•15 years engineering by whole teams • Free, Open Source • Fastest VM - comparable with C • Best GCs to choose from • All JVMs full parallel threaded • All platforms JRuby • started in 2001! • sponsored by RedHat • Free, Open Source • same memory model / threading as the JVM • Constantly refined for speed and efficiency GoGaRuCo 2012- High Performance Ruby - Charles Nutter
2011 • TorqueBox on JRuby 1.6.4 • Trinidad 1.2.3 on JRuby 1.6.4 • Passenger 3.0.9 standalone on REE and Ruby 1.9.2 • Unicorn 4.1.1 on REE and Ruby 1.9.2
require 'java' # With the 'require' above, we can now refer to things that are part of the # standard Java platform via their full paths. frame = javax.swing.JFrame.new("Window") # Creating a Java JFrame label = javax.swing.JLabel.new("Hello") # We can transparently call Java methods on Java objects, just as if they were defined in Ruby. frame.getContentPane.add(label) # Invoking the Java method 'getContentPane'. frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE) frame.pack frame.setVisible(true)
require 'java' require 'path/to/mycode.jar' Java: org.foo.department.Widget Ruby: Java::OrgFooDepartment::Widget These two calls are equivalent java.lang.System.currentTimeMillis java.lang.System.current_time_millis x.getSomething becomes x.something x.setSomething(newValue) becomes x.something = new_value x.isSomething becomes x.something? JavaClass.new or JavaClass.new(x,y,z) generally works as expected
3.x, Sinatra, and others. Rack applications are served as first-class resources within the web container. The web container is clusterable, and web sessions may be shared between nodes without any additional configuration. JDBC High-performance tried-and-true Java Database Connectivity (JDBC) database drivers power your ActiveRecord and other database access. Daemons TorqueBox provides the framework to manage your daemon-like Ruby components. TorqueBox makes sure it starts and stops with your application. What you do in the middle is up to you. Scheduled Jobs Cron-like functionality is provided by the TorqueBox server. Job classes implemented in Ruby have full access to to your Ruby environment and are managed by a durable job scheduler. Messaging Your simple Ruby components can both produce and consume messages from clustered and distributed asynchronous messaging fabric powered by HornetQ. Asynchronous Tasks Leveraging the messaging system, TorqueBox makes it easy to execute simple tasks and methods asynchronously, allows your application to quickly return control to the user.
TorqueBox::Messaging::Queue.new(options['queue_name']) end def start puts "******** Starting PostIdeaGrabber ********" Thread.new do until @done @queue.publish("Random idea #{rand(100)}") sleep 2 end end end def stop @done = true end end