INTRODUCTION TO VERT.X

Dublin Java User Group
@petermd

 

BIO

  • Java Technologist
  • CTO at Donnerwood Media
  • High-Performance Servers
    • Telco, Gaming, Startups
  • Vert.x
    • mod-rxvertx
  • github.com/petermd
 DON"T HOLD BACK

What is Vert.X?

"Vert.x is a lightweight, high performance application platform for the JVM that's designed for modern mobile, web, and enterprise applications..."

MOTIVATION

Platform EVOLUTION

  • New Languages
    • Groovy
    • Scala
    • Clojure
  • Old Languages
    • JRuby
    • JPython
    • Java
  • Great Performance
    • Code
    • VM

NETWORK EVOLUTION

  • New Protocols
    • HTTP
    • XMPP
    • AMQP
    • MQTT
  • New Clients
    • Mobile / Always-on
  • New Deployment Models
    • Containers, Platforms
    • Flexibility / Scale

NODE.JS

THE SCIENCE BIT

"What Makes Node.js Faster Than Java?"
http://strongloop.com/strongblog/node-js-is-faster-than-java/


  • "Built almost twice as fast with fewer people
  • Written in 33% fewer lines of code
  • Constructed with 40% fewer files"

BECAUSE

JAVASCRIPT



NODE.JS

  • Non-blocking I/O - every I/O call must take a callback, whether it is to retrieve information from disk, network or another process.
  • Built-in support for the most important protocols (HTTP, DNS, TLS)
  • Low-level. Do not remove functionality present at the POSIX layer. For example, support half-closed TCP connections.
  • Stream everything; never force the buffering of data.

THE GOOD BITS

  • Lightweight
  • Modular
  • Low-level
  • Popular
  • Fun

BUT...

JAVASCRIPT

VERT.X

  • Started by Tim Fox in 2011
  • Strongly influenced by Node.JS
  • Moved to Eclipse Foundation in 2013


KEY FEATURES

  • Reactive
  • Polyglot
  • Modular
  • High-Performance
  • Concurrent
  • Resilient

    REACTIVE

    AsYNCH I/O

    • VertX is an Async I/O Server built on Netty
    • APIs for
      • HTTP/HTTPS, WebSockets, Sockets, DNS
      • EventBus
      • FileSystem
      • Timer

      ASYNCH I/O

      • High-performance
      • High-concurrency
      • Magical
        • Fast
        • Scalable
        • C10k -> C1M+

      TLDR;


      Callbacks


      POLYGLOT

      JAVASCRIPT

      var vertx = require('vertx');
      
      vertx.createHttpServer().requestHandler(function(req) {    var file = req.path() === '/' ? 'index.html' : req.path();
          req.response.sendFile('webroot/' + file);
      }).listen(8080)

      JAVA

      public class Server extends Verticle {
        public void start() {
          vertx.createHttpServer()
            .requestHandler(new Handler<HttpServerRequest>() {
              public void handle(HttpServerRequest req) {
                String file=req.path().equals("/")?"index.html":req.path();
                req.response().sendFile("webroot/" + file);
              }
            })
            .listen(8080);
        }
      } 

      GROOVY

       vertx.createHttpServer().requestHandler { req ->
            def file = req.uri == "/" ? "index.html" : req.uri
            req.response.sendFile "webroot/$file"
        }.listen(8080)

      PYTHON

      import vertx
      
      server = vertx.create_http_server()
      
      @server.request_handler
      def request_handler(req):
          file = "index.html" if req.uri == "/" else req.uri
          req.response.send_file("webroot/%s"%file)
      
      server.listen(8080)

      RUBY

      require "vertx"
      
      Vertx::HttpServer.new.request_handler do |req|
        file = req.uri == "/" ? "index.html" : req.uri
        req.response.send_file "webroot/#{file}"
      end.listen(8080)

      MODULAR

      MODEL

      • Verticle
        • Single class or file
        • Single-threaded
        • Startup
          • Register Handlers
          • Start Servers
        • Instances
      • Routing
        • EventBus send() vs publish()
        • HttpServer/NetServer

      EVENT BUS

      • Async Message Bus
        • Simple, Binary or JSON
        • Immutable
        • Direct Reply
      • JavaScript Bridge
      • Similarities
        • Actors
        • Processes

      MODULE

      • Set of Verticles
      • Dependencies
        • Runnable
        • Non-Runnable
      • Application
        • runMod or fatJar
      PERFORMANCE

      NEED FOR SPEED

      • Netty 4
      • Small Footprint
      • Limited Features
        • Lightweight EventBus
        • No guaranteed messaging
        • No transactions

      Benchmarks

      TechEmpower


      Benchmarks

      TechEmpower


       

      CONCURRENT

      THREADING MODEL

      • Event Loop (IO Driven)
        • One per Core
      • Each Verticle bound to a single Event Loop
        • Single-threaded execution
        • No Synchronisation
        • Callbacks on same Thread
      • Communication
        • EventBus
        • SharedData

      WORKER VERTICLE

      • Isolate blocking code
      • Uses separate Thread-Pool
      • No Thread-Affinity
      • Care-needed
       

      RESILIANT

      CLUSTERING

      • Pluggable Cluster Module
        • Hazelcast as standard
        • Cluster management
        • Shared Data
      • EventBus
        • Distributed message bus
        • Cluster-wide addressing
          • registerLocal()
        • No guarantees

      AVAILABILITY

      • Fail Over
        • Module based
        • Unexpected failure
      • HA Groups
        • Subset of cluster nodes
      • Quora
        • Minimum partition size

      REAL WORLD

      • Existing App
        • Presence Server (Servlet/MySQL)
        • Session Server (Servlet/Memcache)
      • VertX
        • Event Bus Microservices
        • HTTP (XML/JSON) FrontEnd
      • New App
        • Presence Service (Mongo)
        • Session Server (Redis)
        • Notification Bus (EventBus) 
        • AMQP*
        • WebSockets*

      INTEGRATION

      • Databases
        • MySQL / PostGres / Mongo / Cassandra /Riak
        • Memcache / Redis
      • Messaging
        • AMQP / Stomp / ZeroMQ
      • Presentation
        • Yoke
      • Computation
        • Vertigo
      • Futures
        • Promises / when.java / RxJava

      GOTCHAS

      • Classloaders
      • Debugging is still hard
      • Change is inevitable
      • Modules support can vary

      GET INVOLVED

      SUMMARY

      • New Platform
      • Similar to Node.JS
        • but better!
      • Lean, Fast, Extendable 
      • Rapid Progress
      • Try it!

      Thanks

      Q&A

      Introduction to Vert.x

      By petermd

      Introduction to Vert.x

      Presention to Dublin Java User Group - Feb 20th 2014

      • 5,018