Your SlideShare is downloading. ×
0
+   =                              Christopher SpringThursday 07 February 13
@autonomous                          chris.spring@gmail.comThursday 07 February 13
Thursday 07 February 13
Thursday 07 February 13
“Java is a DSL for                          converting large XML                          files into Stack Traces”        ...
... and that’s all I have to                       say about thatThursday 07 February 13
Thursday 07 February 13
StructureThursday 07 February 13
jRuby                                     Core         Java   Bytecode                          Parser                    ...
jRuby                                    Core         Java   Bytecode                          Parser                     ...
“We could stop working                          on jRuby and it would                          continue to get faster.”   ...
PerformanceThursday 07 February 13
require benchmark                          def fib(n)                            return 1 if n < 2                        ...
Time in seconds                    60                          52.8                    45                    30           ...
Time in seconds                    60                          52.8                    45                    30           ...
REE - 183.8                                 Time in seconds                    60                          52.8           ...
get / do                            1_000.times do                              MultiJson.encode({                        ...
ab -n 1000 -c 32 http://localhost:4567/Thursday 07 February 13
Thursday 07 February 13
Time in seconds                    30                          24.946                 22,5                    15          ...
Thursday 07 February 13
Time in seconds                    30                          24.946                 22,5                    15          ...
Thursday 07 February 13
Time in seconds                    30                          24.946                 22,5                    15          ...
Runtime optimizationsThursday 07 February 13
method_one    method_two   method_threeThursday 07 February 13
method_one method_two method_threeThursday 07 February 13
ThreadingThursday 07 February 13
vs.Thursday 07 February 13
• No GIL                          • Native threads                          • One process for all coresThursday 07 Februar...
Concurrency threshold                          100 process system                                vs.                      ...
Java LibrariesThursday 07 February 13
<html><head>                              <style type="text/css">                                body{                    ...
require stringio                  require itext                  require flying_saucer                  io = StringIO.new ...
htmlThursday 07 February 13
pdfThursday 07 February 13
A loads more....!!!                    • Choice of GC                    • Cross platform                    • GUI apps   ...
Thursday 07 February 13
Let’s take a step back...Thursday 07 February 13
Your AppThursday 07 February 13
Your App                          Background                          JobsThursday 07 February 13
Your App                          Background                          JobsThursday 07 February 13
Your App                          Background              Scheduled                          Jobs                    JobsT...
Your App                          Background              Scheduled                          Jobs                    Jobs ...
Thursday 07 February 13
TorqueBoxThursday 07 February 13
TorqueBoxThursday 07 February 13
TorqueBox                                      App1                                      App2                             ...
TorqueBox                            App1                            App2                            App3Thursday 07 Febru...
TorqueBox                                      Background     Async.                       App1                      App2 ...
TorqueBox                                       Background         Async.                       App1                      ...
Some of the toys...                    • HornetQ                    • Infinispan                    • Quartz SchedulerThurs...
Thursday 07 February 13
It’s still just                          business as usualThursday 07 February 13
Asynchronous                              StuffsThursday 07 February 13
class Charge < ActiveRecord::Base                        # id      :integer      not null, primary key                    ...
class Charge < ActiveRecord::Base                        # id      :integer      not null, primary key                    ...
class Charge < ActiveRecord::Base                        # id      :integer      not null, primary key                    ...
class Charge < ActiveRecord::Base                        # id      :integer      not null, primary key                    ...
class Charge < ActiveRecord::Base                        # id      :integer      not null, primary key                    ...
class ChargesController < ActionController::Base                      include TorqueBox::Injectors                      de...
class ChargesController < ActionController::Base                      include TorqueBox::Injectors                      de...
/queue/charges                      ChargeProcessor                    class ChargesController < ActionController::Base   ...
fetch(/queue/charges).publish( @charge.id )                                  # config/torquebox.rb                        ...
# app/processors/charge_processor.rb   class ChargeProcessor < TorqueBox::Messaging::MessageProcessor     def on_message( ...
# app/processors/charge_processor.rb   class ChargeProcessor < TorqueBox::Messaging::MessageProcessor     def on_message( ...
# app/processors/charge_processor.rb   class ChargeProcessor < TorqueBox::Messaging::MessageProcessor     def on_message( ...
# app/processors/charge_processor.rb   class ChargeProcessor < TorqueBox::Messaging::MessageProcessor     def on_message( ...
Queue   Processor                                  Processor                          Topic   Processor                   ...
# config/torquebox.rb                          TorqueBox.configure do                            queue /queue/charges do  ...
And WebSockets?Thursday 07 February 13
Hells yes!!Thursday 07 February 13
Stomplet                    Topic/Queue                  Client                          ProcessorThursday 07 February 13
Stomplet                                                 ‘/stomp/statuses’                    Topic/Queue                 ...
Stomplet              ‘/topics/charge_status’            ‘/stomp/statuses’                    Topic/Queue                 ...
# config/torquebox.rb                          stomplet ChargeStatusStomplet do                            route /stomp/st...
# app/stomplets/charge_status_stomplet      class ChargeStatusStomplet < TorqueBox::Stomp::JmsStomplet        def on_subsc...
javascript_include_tag /stilts-stompThursday 07 February 13
module ApplicationHelper             include TorqueBox::Injectors             def stomp_url               inject(stomp-end...
Thursday 07 February 13
Thursday 07 February 13
Thanks for Listening!Thursday 07 February 13
Questions?Thursday 07 February 13
Upcoming SlideShare
Loading in...5
×

jRuby and TorqueBox

2,554

Published on

Published in: Technology

Transcript of "jRuby and TorqueBox"

  1. 1. + = Christopher SpringThursday 07 February 13
  2. 2. @autonomous chris.spring@gmail.comThursday 07 February 13
  3. 3. Thursday 07 February 13
  4. 4. Thursday 07 February 13
  5. 5. “Java is a DSL for converting large XML files into Stack Traces” @ davetron5000Thursday 07 February 13
  6. 6. ... and that’s all I have to say about thatThursday 07 February 13
  7. 7. Thursday 07 February 13
  8. 8. StructureThursday 07 February 13
  9. 9. jRuby Core Java Bytecode Parser Classes Integ JIT JVM Native Threads GC C API JIT Charles Nutter - Euroko2012Thursday 07 February 13
  10. 10. jRuby Core Java Bytecode Parser Classes Integ JIT Charles Nutter - Euroko2012Thursday 07 February 13
  11. 11. “We could stop working on jRuby and it would continue to get faster.” Charles Nutter - Euroko2012Thursday 07 February 13
  12. 12. PerformanceThursday 07 February 13
  13. 13. require benchmark def fib(n) return 1 if n < 2 fib(n - 2) + fib(n - 1) end arr = [] puts Benchmark.measure{ 40.times{ |i| arr << fib(i) } } puts arr.inspect # [1, 1, 2, 3, 5, 8, 13, 21, ... ]Thursday 07 February 13
  14. 14. Time in seconds 60 52.8 45 30 15 0Thursday 07 February 13
  15. 15. Time in seconds 60 52.8 45 30 15 10.4 0Thursday 07 February 13
  16. 16. REE - 183.8 Time in seconds 60 52.8 45 30 15 10.4 0Thursday 07 February 13
  17. 17. get / do 1_000.times do MultiJson.encode({ one: one, date: Date.today, two: 2 }) end end # ruby jsonator.rb -s PumaThursday 07 February 13
  18. 18. ab -n 1000 -c 32 http://localhost:4567/Thursday 07 February 13
  19. 19. Thursday 07 February 13
  20. 20. Time in seconds 30 24.946 22,5 15 7,5 0Thursday 07 February 13
  21. 21. Thursday 07 February 13
  22. 22. Time in seconds 30 24.946 22,5 15 8.489 7,5 0Thursday 07 February 13
  23. 23. Thursday 07 February 13
  24. 24. Time in seconds 30 24.946 22,5 15 8.489 7,5 2.892 0Thursday 07 February 13
  25. 25. Runtime optimizationsThursday 07 February 13
  26. 26. method_one method_two method_threeThursday 07 February 13
  27. 27. method_one method_two method_threeThursday 07 February 13
  28. 28. ThreadingThursday 07 February 13
  29. 29. vs.Thursday 07 February 13
  30. 30. • No GIL • Native threads • One process for all coresThursday 07 February 13
  31. 31. Concurrency threshold 100 process system vs. 100 thread systemThursday 07 February 13
  32. 32. Java LibrariesThursday 07 February 13
  33. 33. <html><head> <style type="text/css"> body{ font-family: sans-serif; text-align: center; background-color: #efefef; } h1{ color: blue; font-weight: bold;} div{ border: 4px dashed red; padding: 2em;margin: 2em; } </style> </head> <body> <h1>PDFs with Flying Saucer and jRuby</h1> <div> <p>Im a lumberjack, and Im ok...</p> <img src="flower.jpeg"></img> </div> </body> </html>Thursday 07 February 13
  34. 34. require stringio require itext require flying_saucer io = StringIO.new content = File.read(example.html) renderer = org.xhtmlrenderer.pdf.ITextRenderer.new renderer.set_document_from_string(content) renderer.layout renderer.create_pdf(io.to_outputstream) File.write(pdf_result.pdf, io.string)Thursday 07 February 13
  35. 35. htmlThursday 07 February 13
  36. 36. pdfThursday 07 February 13
  37. 37. A loads more....!!! • Choice of GC • Cross platform • GUI apps • Great tooling • Massive ecosystemThursday 07 February 13
  38. 38. Thursday 07 February 13
  39. 39. Let’s take a step back...Thursday 07 February 13
  40. 40. Your AppThursday 07 February 13
  41. 41. Your App Background JobsThursday 07 February 13
  42. 42. Your App Background JobsThursday 07 February 13
  43. 43. Your App Background Scheduled Jobs JobsThursday 07 February 13
  44. 44. Your App Background Scheduled Jobs Jobs CronThursday 07 February 13
  45. 45. Thursday 07 February 13
  46. 46. TorqueBoxThursday 07 February 13
  47. 47. TorqueBoxThursday 07 February 13
  48. 48. TorqueBox App1 App2 App3Thursday 07 February 13
  49. 49. TorqueBox App1 App2 App3Thursday 07 February 13
  50. 50. TorqueBox Background Async. App1 App2 Tasks Messages App3 Scheduled Long running Tasks servicesThursday 07 February 13
  51. 51. TorqueBox Background Async. App1 App2 Tasks Messages App3 Scheduled Long running Tasks services JBoss AS Clustering Load balancing High availabilityThursday 07 February 13
  52. 52. Some of the toys... • HornetQ • Infinispan • Quartz SchedulerThursday 07 February 13
  53. 53. Thursday 07 February 13
  54. 54. It’s still just business as usualThursday 07 February 13
  55. 55. Asynchronous StuffsThursday 07 February 13
  56. 56. class Charge < ActiveRecord::Base # id :integer not null, primary key # cents :integer default(0) # state :string(255) default("pending") endThursday 07 February 13
  57. 57. class Charge < ActiveRecord::Base # id :integer not null, primary key # cents :integer default(0) # state :string(255) default("pending") endThursday 07 February 13
  58. 58. class Charge < ActiveRecord::Base # id :integer not null, primary key # cents :integer default(0) # state :string(255) default("pending") endThursday 07 February 13
  59. 59. class Charge < ActiveRecord::Base # id :integer not null, primary key # cents :integer default(0) # state :string(255) default("pending") endThursday 07 February 13
  60. 60. class Charge < ActiveRecord::Base # id :integer not null, primary key # cents :integer default(0) # state :string(255) default("pending") endThursday 07 February 13
  61. 61. class ChargesController < ActionController::Base include TorqueBox::Injectors def create @charge = Charge.create( params[:charge] ) fetch(/queue/charges).publish( @charge.id ) msg = Slaves turtles doing thy bidding redirect_to( charges_url, notice: msg ) end endThursday 07 February 13
  62. 62. class ChargesController < ActionController::Base include TorqueBox::Injectors def create @charge = Charge.create( params[:charge] ) fetch(/queue/charges).publish( @charge.id ) msg = Slaves turtles doing thy bidding redirect_to( charges_url, notice: msg ) end endThursday 07 February 13
  63. 63. /queue/charges ChargeProcessor class ChargesController < ActionController::Base include TorqueBox::Injectors def create @charge = Charge.create( params[:charge] ) fetch(/queue/charges).publish( @charge.id ) msg = Slaves turtles doing thy bidding redirect_to( charges_url, notice: msg ) end endThursday 07 February 13
  64. 64. fetch(/queue/charges).publish( @charge.id ) # config/torquebox.rb TorqueBox.configure do queue /queue/charges do processor ChargeProcessor end endThursday 07 February 13
  65. 65. # app/processors/charge_processor.rb class ChargeProcessor < TorqueBox::Messaging::MessageProcessor def on_message( charge_id ) # ... end def on_error( exception ) # optionally deal with exception # ... end endThursday 07 February 13
  66. 66. # app/processors/charge_processor.rb class ChargeProcessor < TorqueBox::Messaging::MessageProcessor def on_message( charge_id ) @charge = Charge.find( charge_id ) result = PaymentGateway.process( @charge ) generate_receipt if result.success? broadcast_status end endThursday 07 February 13
  67. 67. # app/processors/charge_processor.rb class ChargeProcessor < TorqueBox::Messaging::MessageProcessor def on_message( charge_id ) @charge = Charge.find( charge_id ) result = PaymentGateway.process( @charge ) generate_receipt if result.success? broadcast_status end def generate_receipt fetch(queue/receipts).publish( @charge.id ) end endThursday 07 February 13
  68. 68. # app/processors/charge_processor.rb class ChargeProcessor < TorqueBox::Messaging::MessageProcessor def on_message( charge_id ) @charge = Charge.find( charge_id ) result = PaymentGateway.process( @charge ) generate_receipt if result.success? broadcast_status end def generate_receipt fetch(queue/receipts).publish( @charge.id ) end def broadcast_status fetch(topics/charge_status).publish( @charge.id ) end endThursday 07 February 13
  69. 69. Queue Processor Processor Topic Processor ProcessorThursday 07 February 13
  70. 70. # config/torquebox.rb TorqueBox.configure do queue /queue/charges do # processors/charge_processor.rb processor ChargeProcessor end topic /topic/charge_status do processor StatusProcessor processor TesterProcessor processor AlertAdminProcessor end endThursday 07 February 13
  71. 71. And WebSockets?Thursday 07 February 13
  72. 72. Hells yes!!Thursday 07 February 13
  73. 73. Stomplet Topic/Queue Client ProcessorThursday 07 February 13
  74. 74. Stomplet ‘/stomp/statuses’ Topic/Queue Client ProcessorThursday 07 February 13
  75. 75. Stomplet ‘/topics/charge_status’ ‘/stomp/statuses’ Topic/Queue Client ProcessorThursday 07 February 13
  76. 76. # config/torquebox.rb stomplet ChargeStatusStomplet do route /stomp/status endThursday 07 February 13
  77. 77. # app/stomplets/charge_status_stomplet class ChargeStatusStomplet < TorqueBox::Stomp::JmsStomplet def on_subscribe( client ) topic = destination_for(/topics/charge_status, :topic) subscribe_to( client , topic ) end # configure(config) # destroy() # on_subscribe(subscriber) # on_unsubscribe(subscriber) # on_message(message) endThursday 07 February 13
  78. 78. javascript_include_tag /stilts-stompThursday 07 February 13
  79. 79. module ApplicationHelper include TorqueBox::Injectors def stomp_url inject(stomp-endpoint) end end var stompUrl = #{stomp_url} $( function() { if (stompUrl) { var client = Stomp.client(stompUrl); client.connect( username, password, function() { client.subscribe( /stomp/status, function(msg) { alert(msg.body); }); }); } });Thursday 07 February 13
  80. 80. Thursday 07 February 13
  81. 81. Thursday 07 February 13
  82. 82. Thanks for Listening!Thursday 07 February 13
  83. 83. Questions?Thursday 07 February 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×