Addressing the Problem• event-driven / asynchronous architecture – Many long lived connections are a feature of modern applications – OS threads are a precious resource – Blocked OS threads are bad!• => Service many connections with a small number of threads• Reactor Pattern (Douglas C. Schmidt, 1995) – Event Loop• different programming model => on which abstraction? http://en.wikipedia.org/wiki/Reactor_pattern
Different Programming ModelClients delegate long Workers running jobs & IO Event Loop (single request thread, non blocking) callback response
Demo (vert.x not blocking on 100concurrent longrunning requests) siege -c100 -b -r100 "http://localhost:8081/?longrunning"
The Vert.x Project• Open-source (on Github, ASL 2.0)• Age: ~1.5 years• Sponsor: VMWare• Based on: Netty, Hazelcast, SockJS sockjs Rhino
Core APIs• TCP/SSL clients and servers• HTTP/HTTPS clients and servers – including WebSockets• Event bus• File system• 100% asynchronous
Scaling• Scale by creating more Verticle instances• Use message passing to communicate• Fine-tune “pools” of verticles• For TCP and HTTP servers Vert.x does automatic load-balancing
Event Loops are no Silver Bullet• Don’t block the event loop!• Long running calculations• Blocking APIs (i.e. JDBC)• Most traditional Java libraries have blocking APIs• => Hybrid Threading Model – Worker Verticles can block – Communication by message passing (Event Bus) – Leverage ecosystem of Java libraries
Concurrency Model• A verticle instance is always single-threaded• Very different approach from “Java-Style” multi-threaded concurrency – No more synchronized, volatile or locking – Avoid many classic race conditions
Event Bus Demo Vertx Instance Event Loop Background Workers Worker Worker Worker Worker WorkerServer Server Event Bus JVM
Web Application Demo Vertx Instance Module Module ModuleBrowser vertx. vertx. vertx. web-server aut-mgr mongo- Mongo DB persistor(WebSocket) Event Bus JVM
The Future• Scala & Closure support• Management, including GUI console• Developer experience – IDE integration, testing• Promises API?• Direct-style API using continuations?
Summary • Polyglot – use the language(s) you want • Simple concurrency – wave goodbye to most race conditions • Leverage existing Java library ecosystem • Powerful distributed event bus which spans client and server • Powerful module systemVert.x is the platform for a new generation of polyglot web and enterprise applications.
The big picture• Alternative approaches (Java): – Servlet 3.0 – NIO connections
Who is using it? game-gorilla.com gvmtool.net Helsinki Trip Planner
Would I use it now?• Maybe -> where the distributed architecture really fits• Might get interesting in the future…• I don’t buy the polyglot story…• I don’t fully buy the concurrency story …