Building decoupled polyglot applications with

Toby Crawley

CodeMash 2014

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.”

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.”

Lightweight

Small distribution: 5 MB

Efficient with resources

Small, generally consistent API

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.”

High Performance

650,000 requests/second - http://bit.ly/vertxbench

Based on Netty - http://netty.io

Primarily asynchronous

Why Async?

Why Async?

standing2.jpg

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.”

Application Platform

Run multiple applications (Verticles) in one instance

Simple inter-component communication (EventBus)

Clustering

High Availability

Polyglot

Polyglot

  • Java
  • JRuby
  • Jython
  • JavaScript/CoffeeScript (Rhino, DynJS*, Nashorn*)
  • Groovy
  • Scala*
  • PHP*
  • Ceylon*
  • Clojure*

(* in progress)

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.”

The JVM

A mature VM

Not just Java

Massive amount of libraries

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.”

Enterprise

enterprise.png

Mobile, Enterprise

mobile-enterprise.png

Mobile, Web, Enterprise

enterprise-all.png

Mobile, Web, Enterprise

Many connections

Constrained resources (To The Cloud!)

Simple without being simplistic.

Reactor Loop

reactor-loop.png

Reactor Loop(s)

Defaults to one/core

Verticle tied to one loop

Thread confinement

Distributed Event Bus

  • Simple (String, int, byte[], etc) & structured (JSON) messages
  • String-based addressing
  • Publish/Subscribe
  • Point-to-point
  • Request/Response
  • Clusterable (Hazelcast, browser)
  • Transient

Sample App

fireside-chat.jpg

Sample Application

fireside-dia-simple.png

(URL of sample app was here)

Sample Application

fireside-dia-simple.png

Sample Application

fireside-dia.png

Features

  • HTTP(S), TCP, UDP, WebSocket, SockJS servers
  • HTTP(S), TCP, UDP, WebSocket, DNS clients
  • Distributed Event Bus
  • Timers
  • Async FS
  • SharedData
  • Embeddable

Gains

  • Efficient
  • Distributed Event Bus
  • Thread Safety
  • Polyglot
  • Clusterable

Losses

Language ecosystems

Async complexity

Don't block the reactor loop

Don't block…

reactor2.jpg

Don't block the reactor loop

  • Thread.sleep()
  • CountDownLatch.await() or any other blocking operating from java.util.concurrent
  • while(true) {puts "King of the world!"}
  • Long-lived computationally intensive operations
  • Blocking operations that might take some time to complete (e.g. DB query)

Worker Verticles

Runs on a thread pool, so can block.

Still thread-confined by default.

Resources

http://vertx.io / https://github.com/vert-x/

NoDyn - http://nodyn.io

Yoke - http://pmlopes.github.io/yoke/

Vert.x Module Registry - http://modulereg.vertx.io/

https://github.com/tobias/vertx-codemash-2014/

Takeaways

  • Build application components in any (supported) language
  • Decouple components with the EventBus
  • Fast & efficient
  • Async, but not always

Questions?

hands.jpg

Credits