Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

26
Scalable & Polyglot application platform on JVM Tehran JUG meeting Aug-2014 By: Saeed Zarinfam

description

Vert.x Tehran JUG meeting Aug-2014 By: Saeed Zarinfam

Transcript of Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Page 1: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Scalable & Polyglotapplication platform on JVM

Tehran JUG meeting Aug-2014By: Saeed Zarinfam

Page 2: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Intro

Scalable application platform Real-time system (web applications, game and ...) Similar to Node.js but not a clone! Some characteristics like Erlang Started by Tim Fox (RabbitMQ , HornetQ , Red Hat

Middlewares) in 2011 Sponsored by VMWare (SpringSource) and Red Hat! Manged by Eclipse Foundation

Page 3: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Requirements

JDK 7 or later (Oracle distribution or OpenJDK) server.js

$ vertx run server.js -instance 10

Page 4: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

server.js in Java

Page 5: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Architecture

Slim and lightweight core Everything else as module Reusable modules

Page 6: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Features

Polyglot Asynchronous programming model (Non blocking

I/O and event-driven) Actor-like concurrency Distributed Event Bus (spans the client and server

side) Embedded as a library Module system

Page 7: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Big picture

Page 8: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Polyglot

Java JavaScript Python Ruby Groovy Clojure Scala

* PHP, Ceylon (under development)

Page 9: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Polyglot

New JDK 7 Feature (better support for Dynamically Typed Languages in the JVM)

e.g. invokedynamic bytecode instruction Support for a New Language as module!

Page 10: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Asynchronous programming model

Full Asynchronous core APIs Event-driven (event handlers) Java NIO libraries (non blocking) Netty 4

Page 11: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Sample TCP Server (Getting Notified of Incoming Connections)

Page 12: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Distributed Event Bus

Communication mechanism between applications components (Clustered)

Spans the client and server side Use same API in the browser Pub-Sub, Request/Response

Page 13: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
Page 14: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Actor-like concurrency

No more synchronized, volatile or explicit locking

Write all your code as single threaded Components communicate with each other

over the event bus by exchanging messages. Number of threads to be equal to the number

of available cores on the machine.

Page 15: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Concurrency Model (Thread model)

Hybrid threading model Event Loops = number of threads to the available

cores on the server Multi-reactor pattern (more than one event loop) The Golden Rule - Don't block the event loop! Worker Verticles can block - never executed

concurrent (JDBC , …) Shared map (immutable, distributed)

Page 16: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Verticle

Verticle run insdide a vert.x instance verticle instance is never executed by more

than one thread concurrently (single threaded). verticle instances communicate with each

other over the event bus by exchanging messages.

verticle instances correspond to actors. (more coarse grained than actors)

Page 17: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Vert.x Instances

Vert.x instance runs inside its own JVM instance

The vert.x instances can be configured to cluster with each other

Page 18: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
Page 19: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
Page 20: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Module System

Public module registry Auto-redeploy of Modules JSON configuration New non-core features done as modules Runnable modules vs. includable modules Even new language support is done via

modules!

Page 21: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Vert.x APIContainer API

TCP/SSL servers and clients

UDP

HTTP/HTTPS servers and clients

WebSockets servers and clients

The distributed event bus

Periodic and one-off timers

Buffers

Flow control

File-system access

Shared map and sets

Accessing configuration

SockJS

Logging (JUL)

DNS Client

Page 22: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

How Vert.x scale

Many instance of one verticle Clustering (auto-magic, configurable) Eventbus spans through all machine in cluster and browser Use all available core Hybrid thread model Automatic failover (-ha and "bare" Vert.x instances) HA groups (-hagroup) Quora (network partitions)(-quorum) Automatic load-balancing for TCP and HTTP ( available cores)

Page 23: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Sample web application

Page 24: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Other capabilities

Gradle template Maven archtype Testing Framework provided (Intergration-

Testing and Unit Testing) Logging (JUL logging)

Page 25: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

Usage

Nodyn: Nodyn is a Node.js compatible framework, running on the JVM powered by the DynJS Javascript runtime with an embedded Vert.x

Yoke: Yoke is a minimal and flexible Vert.x web application framework

Edge

Page 26: Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam

تشکر

. .zarinfam s@gmail com

:// .http javabyab com