Vert.x introduction

26
Asynchronous IO with Vert.x Peter Ledbrook - SpringSource

Transcript of Vert.x introduction

Page 1: Vert.x introduction

Asynchronous IO with Vert.x

Peter Ledbrook - SpringSource

Page 2: Vert.x introduction

New kid on the block

2

Javascript Non-blocking Single-threaded

Reactor pattern

Page 3: Vert.x introduction

What’s it about?

• C10K Problem– How do you handle 10,000+ concurrent connections?– Without grinding to a halt?

• Why?– All those mobile devices!– Rise of long-lived connections

3

Real-time chatInstant messaging

TwitterVoice and video

Page 4: Vert.x introduction

Transloadit

• “Flexible, fast and scalable file uploading and encoding”• Video/audio encoding on the fly

– 500mb/s

4

ClientVideo

TransloaditS3/Cloudfiles/...

Page 5: Vert.x introduction

Voxer

• Walkie-talkie for iOS and Android• Live audio• Large number of connections• Push notifications

5

Page 6: Vert.x introduction

6

Javascript and nothing but Javascript

Page 7: Vert.x introduction

What if?

• Language neutral framework• On the JVM• Polyglot APIs• Easy horizontal scalability• Do non-eventy stuff in a non-eventy way

7

Vert.x!

Page 8: Vert.x introduction

Vert.x

• Written in Java• Built on Netty and NIO 2

– Java 7 only!• Multiple language bindings

– JRuby– Groovy– Javascript– Python/Clojure/Scala planned

• Based on the Reactor pattern

8

Page 9: Vert.x introduction

How it works

• Handlers executed synchronously– on a single thread

• Use handlers to pass messages• Inter/intra application comms

– EventBus with messages– Safe shared data structures

9

Event loop

App registers handlers

Events trigger handlers

Page 10: Vert.x introduction

Features

• Non-blocking stdio• TCP/IP and HTTP servers and clients• Web Socket support• (Non-blocking) Redis & Mongo modules (busmods)• Asynchronous file system access and stream handling

10

ReadStream WriteStreamPump

HTTP Request AsyncFilee.g.

Page 11: Vert.x introduction

Example - Echo socket

11

Page 12: Vert.x introduction

Example - Echo client

12

Page 13: Vert.x introduction

App instance

Scaling

13

App instance

App instance

Page 14: Vert.x introduction

Vertx node

App instance

Scaling

14

App instance

App instance

Event bus

vertx run -instances 3

Page 15: Vert.x introduction

Hazelcast

Vertx node

Scaling

15

Vertx node

Vertx node

Event bus

Page 16: Vert.x introduction

Extensibility via (Bus) Mods

16

Event bus

Mailer Work queueMongoDB Web

server...

Page 17: Vert.x introduction

Mod structure

• Core mods in $VERTX_HOME/mods• User mods in $VERTX_MODS

17

Page 18: Vert.x introduction

A more complex example

Page 19: Vert.x introduction

Realtime logging app

19

App

Browser

Log messages

SockJS

Page 20: Vert.x introduction

Realtime logging app

20

Page 21: Vert.x introduction

Realtime logging app

21

Page 22: Vert.x introduction

Realtime logging app

22

Page 23: Vert.x introduction

Demo

Page 24: Vert.x introduction

Summary

• Event-driven framework for the JVM– Low overhead– Handle large number of connections– Great for working with streams

• Pick your own language!– Which will of course be Groovy ;)

• Published release: 1.0.1– Still early days– Get involved now!

24

Page 25: Vert.x introduction

More info

• w: https://github.com/purplefox/vert.x http://purplefox.github.com/vert.x/

• f: http://groups.google.com/group/vertx

• t: pledbrook• b: http://blog.springsource.com/author/peter-ledbrook/

25

Page 26: Vert.x introduction

26

Thank you!

Questions?