Vert.x:                   This ain’t your Dad’s Node!                                           Matt Stine   Tim Fox      ...
TheC10K Problem
SERVER PUSH
Ryan DahlFather of Node.js  How?!?!
2008:Thread Per Request/Response
http://www.xtranormal.com/watch/6995033/mongo-db-is-web-scale
Non-blocking UNIX sockets
But Nodehas someshortcomings... 1. JavaScript! 2. Vertical Scaling 3. Interprocess Communication 4. Event Loop
http://vertx.io
Problem #1:                       JavaScript   Brendan EichFather of JavaScript
WAThttps://www.destroyallsoftware.com/talks/wat
Solution #1:                                   Polyglot                                 Programming           Neal FordFat...
Hello Worldin every Vert.x language!
Java
Ruby
Python
JavaScript
FUTURETheoretically, any JVM language or language that compilesto a supported language (e.g. ClojureScript ➔ JavaScript)
Problem #2:    Vertical    ScalingLars BakFather of V8
http://nodejs.org/about/
Node: Up and RunningExample 3-11: Using cluster to distribute work
Solution #2:                 The                 JVMJames GoslingFather of Java
The Verticle               - Unit of DeploymentVerticle               - Script/Java Class
Vert.x Instance  How it works it works it works it works          How      How      How                             Event ...
Vert.x Instance              How it works it works it works it works                      How      How      How           ...
Concurrency• Verticle instance assigned thread/event loop.• Verticle instance ALWAYS executes on  assigned thread.• Vertic...
Tony Hoare        Father of CSP        (http://dl.acm.org/citation.cfm?        doid=359576.359585)              Problem #3...
Node.js Communication Options• TCP/UDP/UNIX Sockets• Redis Pub/Sub (http://redis.io/)• ZeroMQ (http://www.zeromq.org/)• Pr...
Solution #3.1:                       The                      Event                       Bus    Alan KayFather of Smalltalk
How it works it works it works it works        How      How      How                           Event loop Event loop Event...
Addressing• Simply a String• Dot-style namespacing recommended• e.g. “messages.inbound.A”
Handler Registration                     Handler Xmessages.inbound.A   Handler Y                     Handler Z
Handler Registration
Pub/Sub                              Handler XSender   messages.inbound.A   Handler Y                              Handler Z
Pub/Sub
P2P                              Handler XSender   messages.inbound.A   Handler Y                              Handler Z
P2P
Sender:Receiver:
Message Types• String• Primitives (int, long, short, float, double, ...)• Boxed Primitives• boolean/Boolean• org.vertx.java...
Distributed Vert.x orks it works it works it works How       How     How                                             How i...
Into the Browser! orks it works it works it works How       How     How                                             How it...
The Server
The Client
Demo
Solution #3.2:                      Shared                    Immutable                       State  Rich HickeyFather of ...
e.g. In-memory Web        Cache
MessageAI L        Passing?      F
Shared state onlydangerous if it is   MUTABLE!
Vert.x Shared State• SharedData Object (vertx.sharedData()) • collection of    java.util.concurrent.ConcurrentMap<K,V> • c...
Allowed Values• Strings• Boxed Primitives•byte[]                              R !•org.vertx.java.core.buffer.Buffer• Imple...
Shared Map
Shared Set
Problem #4:                                 The                                Event                                Loop  ...
Reactorw it works           Pattern Review                     Event loop   Application                     ...eventspp re...
Reactor Pattern Review• Single thread / single event loop• EVERYTHING runs on it• You MUST NOT block the event loop
Reactor Pattern Problems• Some work is naturally blocking: • Intensive data crunching • 3rd-party blocking API’s (e.g. JDB...
Solution #4:                             Worker                            Verticles       Carl HewittFather of the Actor ...
Worker Verticles• Not assigned a Vert.x event loop thread• Executes on background thread pool• Never executed concurrently...
The “Multi-reactor”How it works it works it works it works        How       How     How                           Event lo...
Problem/Solution Summary• Node.js compels the use of JavaScript• Vert.x is Polyglot• Node.js is inherently single-threaded...
Problem/Solution Summary• Node.js doesn’t help much w/ interprocess  communication• Vert.x features a distributed event bu...
Other Goodies• Growing Module        • TCP/SSL servers/clients  Repository            • HTTP/HTTPS servers/               ...
Case Studyhttps://github.com/mstine/twitx
Get Involved!• Google Group: http://groups.google.com/  group/vertx• GitHub: https://github.com/vert-x/vert.x• IRC: irc://...
Vert.x:                                     This ain’t your Dad’s Node!                                                   ...
Image Credits•   Tim Fox: https://twitter.com/timfox•   BSOD Phone: http://www.flickr.com/photos/markhillary/3413357033•   ...
Vert.x
Vert.x
Vert.x
Vert.x
Vert.x
Vert.x
Vert.x
Vert.x
Upcoming SlideShare
Loading in...5
×

Vert.x

5,883

Published on

Vert.x: This ain't your Dad's Node! (As presented at http://sfjava.org on 10/9/2012)

Published in: Technology
0 Comments
28 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,883
On Slideshare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
173
Comments
0
Likes
28
Embeds 0
No embeds

No notes for slide

Vert.x

  1. 1. Vert.x: This ain’t your Dad’s Node! Matt Stine Tim Fox Enterprise Java/Cloud ConsultantFather of Vert.x matt.stine@gmail.com http://mattstine.com Twitter: @mstine
  2. 2. TheC10K Problem
  3. 3. SERVER PUSH
  4. 4. Ryan DahlFather of Node.js How?!?!
  5. 5. 2008:Thread Per Request/Response
  6. 6. http://www.xtranormal.com/watch/6995033/mongo-db-is-web-scale
  7. 7. Non-blocking UNIX sockets
  8. 8. But Nodehas someshortcomings... 1. JavaScript! 2. Vertical Scaling 3. Interprocess Communication 4. Event Loop
  9. 9. http://vertx.io
  10. 10. Problem #1: JavaScript Brendan EichFather of JavaScript
  11. 11. WAThttps://www.destroyallsoftware.com/talks/wat
  12. 12. Solution #1: Polyglot Programming Neal FordFather of Polyglot Programming http://memeagora.blogspot.com/2006/12/polyglot-programming.html
  13. 13. Hello Worldin every Vert.x language!
  14. 14. Java
  15. 15. Ruby
  16. 16. Python
  17. 17. JavaScript
  18. 18. FUTURETheoretically, any JVM language or language that compilesto a supported language (e.g. ClojureScript ➔ JavaScript)
  19. 19. Problem #2: Vertical ScalingLars BakFather of V8
  20. 20. http://nodejs.org/about/
  21. 21. Node: Up and RunningExample 3-11: Using cluster to distribute work
  22. 22. Solution #2: The JVMJames GoslingFather of Java
  23. 23. The Verticle - Unit of DeploymentVerticle - Script/Java Class
  24. 24. Vert.x Instance How it works it works it works it works How How How Event loop Event loop Event loop Event loopEvent Loops App registers App registers App registers App registers trigger Events trigger Events trigger Events trigg Events handlers handlers handlers handlershandlers handlers handlers handlers • Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers – on a single threada single threada single threada single thread – on – on – on • Use handlersUse handlersUse handlersUse handlers to pass messages • to pass messages messages messages • to pass • to pass • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms – EventBus with EventBus with EventBus with EventBus with messages – messages – messages – messages – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared Verticle 9 9 9Runtime.availableProcessors() == 4
  25. 25. Vert.x Instance How it works it works it works it works How How How Event loop Event loop Event loop Event loop Event Loops App registers App registers App registers App registers trigger Events trigger Events trigger Events trigg Events handlers handlers handlers handlershandlers handlers handlers handlers • Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers – on a single threada single threada single threada single thread – on – on – on • Use handlersUse handlersUse handlersUse handlers to pass messages • to pass messages messages messages • to pass • to pass vertx run • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms HelloWorld with EventBus with EventBus with EventBus with messages – EventBus – messages – messages – messages – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared-instances 4 Verticle Verticle Verticle Verticle 9 9 9 Runtime.availableProcessors() == 4
  26. 26. Concurrency• Verticle instance assigned thread/event loop.• Verticle instance ALWAYS executes on assigned thread.• Verticles have isolated classloaders and cannot share global state (static members, global variables, etc.)• Can write all code assuming single threading.
  27. 27. Tony Hoare Father of CSP (http://dl.acm.org/citation.cfm? doid=359576.359585) Problem #3: InterprocessCommunication
  28. 28. Node.js Communication Options• TCP/UDP/UNIX Sockets• Redis Pub/Sub (http://redis.io/)• ZeroMQ (http://www.zeromq.org/)• Process Signaling/Cluster Module• Eventing Frameworks: Hook.io (dead), JS- Signals, Bean, etc.• Memcached• Etc...
  29. 29. Solution #3.1: The Event Bus Alan KayFather of Smalltalk
  30. 30. How it works it works it works it works How How How Event loop Event loop Event loop Event loop App registers App registers App registers App registers trigger Events trigger Events trigger Events trigger Events handlers handlers handlers handlershandlers handlers handlers handlers• Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers – on a single threada single threada single threada single thread – on – on – on• Use handlersUse handlersUse handlersUse handlers to pass messages • to pass messages messages messages • to pass • to pass• Inter/intra application comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms – EventBus with EventBus with EventBus with EventBus with messages – messages – messages – messages – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared Verticle Verticle Verticle Verticle 9 9 9 9 Event Bus
  31. 31. Addressing• Simply a String• Dot-style namespacing recommended• e.g. “messages.inbound.A”
  32. 32. Handler Registration Handler Xmessages.inbound.A Handler Y Handler Z
  33. 33. Handler Registration
  34. 34. Pub/Sub Handler XSender messages.inbound.A Handler Y Handler Z
  35. 35. Pub/Sub
  36. 36. P2P Handler XSender messages.inbound.A Handler Y Handler Z
  37. 37. P2P
  38. 38. Sender:Receiver:
  39. 39. Message Types• String• Primitives (int, long, short, float, double, ...)• Boxed Primitives• boolean/Boolean• org.vertx.java.core.json.JsonObject• org.vertx.java.core.buffer.Buffer
  40. 40. Distributed Vert.x orks it works it works it works How How How How it works it works it works it works How How How How it works it works it works it works How How How Event loop Event loop Event loop Event loop Event loop Event loop Event loop Event loop Event loop Event loop Event loop Event looprs App registers App registers App registers trigger Events trigger Events trigger Events trigger registers App registers trigger Events trigger Events trigger Events trigger registers App registers trigger Events trigger Events trigger Events App registers App registers App Events App registers App registers App Events handlers handlers handlershandlers handlers handlers handlers handlers handlers handlers handlershandlers handlers handlers handlers handlers handlers handlers handlershandlers handlers handlersexecuted synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers • Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers • Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlersle threada single threada single threada single thread – on – on – on – on a single threada single threada single threada single thread – on – on – on – on a single threada single threada single threada single thread – on – on – onersUsepass messages messages messages messages handlersUsepass messages messages messages messages handlersUse handlersUsepass messages messages messages • to handlersUse handlersUsepass • to pass • to handlers to pass • Use • to handlersUse handlersUsepass • to pass • to handlers to pass • Use • to pass messages • to handlersUse handlers to pass • to passapplication comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms• Inter/intra application comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms Inter/intra application comms • • Inter/intra application comms • Inter/intra application comms • Inter/intra application commss with EventBus with EventBus with EventBus with messages – messages – messages – messages – EventBus with EventBus with EventBus with EventBus with messages – messages – messages – messages – EventBus with EventBus with EventBus with EventBus with messages – messages – messages – messagesred data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared Verticle Verticle Verticle 9 Verticle9 9 Verticle 9 Verticle Verticle 9 Verticle 9 9 Verticle 9 Verticle Verticle 9 Verticle 9 9 Event Bus
  41. 41. Into the Browser! orks it works it works it works How How How How it works it works it works it works How How How Event loop Event loop Event loop Event loop Event loop Event loop Event loop Event looprs App registers App registers App registers trigger Events trigger Events trigger Events trigger registers App registers trigger Events trigger Events trigger Events trigger Events App registers App registers App Events handlers handlers handlershandlers handlers handlers handlers handlers handlers handlers handlershandlers handlers handlers handlersexecuted synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers • Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlersle threada single threada single threada single thread – on – on – on – on a single threada single threada single threada single thread – on – on – onersUsepass messages messages messages messages handlersUsepass messages messages messages messages • to handlersUse handlersUsepass • to pass • to handlers to pass • Use • to handlersUse handlersUsepass • to pass • to handlers to passapplication comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms• Inter/intra application comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application commss with EventBus with EventBus with EventBus with messages – messages – messages – messages – EventBus with EventBus with EventBus with EventBus with messages – messages – messages – messagesred data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared Verticle Verticle Verticle 9 Verticle9 9 Verticle 9 Verticle Verticle 9 Verticle 9 9 9 SockJS Bridge Event Bus
  42. 42. The Server
  43. 43. The Client
  44. 44. Demo
  45. 45. Solution #3.2: Shared Immutable State Rich HickeyFather of Clojure
  46. 46. e.g. In-memory Web Cache
  47. 47. MessageAI L Passing? F
  48. 48. Shared state onlydangerous if it is MUTABLE!
  49. 49. Vert.x Shared State• SharedData Object (vertx.sharedData()) • collection of java.util.concurrent.ConcurrentMap<K,V> • collection of java.util.Set<E> (backed by ConcurrentMap)• Elements MUST be immutable values (well, sort of...)• Currently only available within a Vertx. instance, not across a cluster.
  50. 50. Allowed Values• Strings• Boxed Primitives•byte[] R !•org.vertx.java.core.buffer.Buffer• Implementors of G E Shareable AN org.vertx.java.core.shareddata. D
  51. 51. Shared Map
  52. 52. Shared Set
  53. 53. Problem #4: The Event Loop Douglas SchmidtFather of the Reactor Pattern
  54. 54. Reactorw it works Pattern Review Event loop Application ...eventspp registers registers Events t trigger handlers handl handlers... handlers. Event Loopandlers executed synchronouslyon a single threadse handlers to pass messages
  55. 55. Reactor Pattern Review• Single thread / single event loop• EVERYTHING runs on it• You MUST NOT block the event loop
  56. 56. Reactor Pattern Problems• Some work is naturally blocking: • Intensive data crunching • 3rd-party blocking API’s (e.g. JDBC)• Pure reactor (e.g. Node.js) is not a good fit for this kind of work!
  57. 57. Solution #4: Worker Verticles Carl HewittFather of the Actor Model
  58. 58. Worker Verticles• Not assigned a Vert.x event loop thread• Executes on background thread pool• Never executed concurrently by more than one thread• Not allowed to use TCP or HTTP clients/ servers• Communicate using the event bus• Should be kept to a minimum
  59. 59. The “Multi-reactor”How it works it works it works it works How How How Event loop Event loop Event loop Event loop BG BG App registers App registers App registers App registers trigger Events trigger Events trigger Events trigger Events handlers handlers handlers handlershandlers handlers Pool handlers Pool handlers• Handlers executed synchronously executed synchronously • Handlers executed synchronously executed synchronously • Handlers • Handlers – on a single threada single threada single threada single thread – on – on – on• Use handlersUse handlersUse handlersUse handlers to pass messages • to pass messages messages messages • to pass • to pass• Inter/intra application comms • Inter/intra application comms • Inter/intra application comms • Inter/intra application comms – EventBus with EventBus with EventBus with EventBus with messages – messages – messages – messages – Safe shared data structuresdata structuresdata structuresdata structures – Safe shared – Safe shared – Safe shared Worker Worker Verticle Verticle Verticle Verticle Verticle Verticle 9 9 9 9 Event Bus
  60. 60. Problem/Solution Summary• Node.js compels the use of JavaScript• Vert.x is Polyglot• Node.js is inherently single-threaded• Vert.x leverages the multi-threaded JVM
  61. 61. Problem/Solution Summary• Node.js doesn’t help much w/ interprocess communication• Vert.x features a distributed event bus which reaches all the way into the browser• Node.js requires all code to run on the event loop• Vert.x features background workers that allow blocking work to be done off of the event loops
  62. 62. Other Goodies• Growing Module • TCP/SSL servers/clients Repository • HTTP/HTTPS servers/ clients • web server • persistors (Mongo, • WebSockets support JDBC, ...) • SockJS support • work queue • Timers • authentication • Buffers manager • Streams and Pumps • session manager • Routing • Socket.IO • Asynchronous File I/O
  63. 63. Case Studyhttps://github.com/mstine/twitx
  64. 64. Get Involved!• Google Group: http://groups.google.com/ group/vertx• GitHub: https://github.com/vert-x/vert.x• IRC: irc://freenode.net/vertx• Needs: • language implementations • modules (esp. persistence, security, ...) • examples/blogs/documentation help
  65. 65. Vert.x: This ain’t your Dad’s Node! Matt Stine Enterprise Java/Cloud Consultant Please fill out an evaluation: matt.stine@gmail.com http://mattstine.comhttp://speakerrate.com/talks/16821 Twitter: @mstine
  66. 66. Image Credits• Tim Fox: https://twitter.com/timfox• BSOD Phone: http://www.flickr.com/photos/markhillary/3413357033• V8: http://www.flickr.com/photos/gorbould/3479298062• Ryan Dahl: http://www.flickr.com/photos/franksvalli/5163205409• Shortcomings: http://www.flickr.com/photos/hendricksphotos/3340896056• Brendan Eich: http://www.flickr.com/photos/equanimity/4055148344• Neal Ford: http://nealford.com/images/Neal-2012-headshot.jpg• Lars Bak: http://www.flickr.com/photos/niallkennedy/2822229099• James Gosling: http://www.flickr.com/photos/skrb/2499736195• Tony Hoare: http://www.flickr.com/photos/adewale_oshineye/3687557065• Alan Kay: http://www.flickr.com/photos/mwichary/3010026816• Rich Hickey: http://www.flickr.com/photos/hlship/3603090614• Douglas Schmidt: http://www.cs.wustl.edu/~schmidt/gifs/SchmidtD.jpg• Carl Hewitt: http://www.flickr.com/photos/jeanbaptisteparis/3098594954
  1. A particular slide catching your eye?

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

×