Date post: | 08-May-2015 |
Category: |
Technology |
Upload: | alvaro-videla |
View: | 5,526 times |
Download: | 3 times |
vert.xÁlvaro Videla | VMware
Polyglot and Scalable Apps on the JVM
Tuesday, October 9, 12
About Me• Developer Advocate for Cloud Foundry
• Blog: http://videlalvaro.github.com/
• Twitter: @old_sound
Tuesday, October 9, 12
About Me• Developer Advocate for Cloud Foundry
• Blog: http://videlalvaro.github.com/
• Twitter: @old_sound
• I created gifsockets™
Tuesday, October 9, 12
About Me
Co-authored
RabbitMQ in Action
http://bit.ly/rabbitmq
Tuesday, October 9, 12
vert.xTuesday, October 9, 12
vert.x
• VMware sponsored OS project
Tuesday, October 9, 12
vert.x
• VMware sponsored OS project
• JVM Based
Tuesday, October 9, 12
vert.x
• VMware sponsored OS project
• JVM Based
• 1+ year
Tuesday, October 9, 12
vert.x
• VMware sponsored OS project
• JVM Based
• 1+ year
• By @timfox from HornetMQ fame
Tuesday, October 9, 12
vert.x
Framework to write polyglot,
highly concurrent apps.
Tuesday, October 9, 12
vert.x
Framework to write polyglot,
highly concurrent apps.
Tuesday, October 9, 12
Javascript
load('vertx.js')
vertx.createHttpServer().requestHandler(function(req) { var file = req.path === '/' ? 'index.html' : req.path; req.response.sendFile('webroot/' + file);}).listen(8080)
Tuesday, October 9, 12
Javascript
load('vertx.js')
vertx.createHttpServer().requestHandler(function(req) { var file = req.path === '/' ? 'index.html' : req.path; req.response.sendFile('webroot/' + file);}).listen(8080)
$ vertx run server.js
Tuesday, October 9, 12
Javascript
load('vertx.js')
vertx.createHttpServer().requestHandler(function(req) { var file = req.path === '/' ? 'index.html' : req.path; req.response.sendFile('webroot/' + file);}).listen(8080)
$ vertx run server.js -instances 32
Tuesday, October 9, 12
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)
$ vertx run server.rb -instances 32
Tuesday, October 9, 12
Pythonimport vertx
server = vertx.create_http_server()
@server.request_handlerdef request_handler(req): file = "index.html" if req.uri == "/" else req.uri req.response.send_file("webroot/%s"%file)server.listen(8080)
$ vertx run server.py -instances 32
Tuesday, October 9, 12
Groovy
vertx.createHttpServer().requestHandler { req -> def file = req.uri == "/" ? "index.html" : req.uri req.response.sendFile "webroot/$file"}.listen(8080)
$ vertx run Server.groovy -instances 32
Tuesday, October 9, 12
Javaimport org.vertx.java.core.Handler;import org.vertx.java.core.http.HttpServerRequest;import org.vertx.java.deploy.Verticle;
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); }}
$ vertx run Server.java -instances 32
Tuesday, October 9, 12
vert.x
Framework to write polyglot,
highly concurrent apps.
Tuesday, October 9, 12
Core Concepts
Tuesday, October 9, 12
Core Concepts
• Verticle
Tuesday, October 9, 12
Core Concepts
• Verticle
• vert.x instances
Tuesday, October 9, 12
Core Concepts
• Verticle
• vert.x instances
• Event Bus
Tuesday, October 9, 12
Verticles run inside a vert.x instance.
A single vert.x instance runs inside its own
JVM instance.
Tuesday, October 9, 12
Tuesday, October 9, 12
vertx run server.js -instances 32
Tuesday, October 9, 12
Programming Model
• Event Based (similar to node.js)
• Event Handlers
• Small set of threads per vert.x instance
• Verticles are executed using the same thread.
• Message Passing Communication
Tuesday, October 9, 12
vert.x core
Tuesday, October 9, 12
vert.x core
• TCP/SSL Servers
Tuesday, October 9, 12
vert.x core
• TCP/SSL Servers
• HTTP/HTTPS Servers
Tuesday, October 9, 12
vert.x core
• TCP/SSL Servers
• HTTP/HTTPS Servers
• Websockets and Sock.js
Tuesday, October 9, 12
vert.x core
• TCP/SSL Servers
• HTTP/HTTPS Servers
• Websockets and Sock.js
• Distributed Event Bus Access
Tuesday, October 9, 12
vert.x core
• TCP/SSL Servers
• HTTP/HTTPS Servers
• Websockets and Sock.js
• Distributed Event Bus Access
• Shared Maps and Sets
Tuesday, October 9, 12
vert.x core
• TCP/SSL Servers
• HTTP/HTTPS Servers
• Websockets and Sock.js
• Distributed Event Bus Access
• Shared Maps and Sets
• Logging
Tuesday, October 9, 12
Event Bus
Tuesday, October 9, 12
Event Bus
• Allows Verticles to talk to each other
Tuesday, October 9, 12
Event Bus
• Allows Verticles to talk to each other
• Works cross language
Tuesday, October 9, 12
Event Bus
• Allows Verticles to talk to each other
• Works cross language
• Works across the cluster
Tuesday, October 9, 12
Event Bus
• Allows Verticles to talk to each other
• Works cross language
• Works across the cluster
• Spans from server to client side
Tuesday, October 9, 12
Event Bus - How
• Register Handlers
Tuesday, October 9, 12
Event Bus - How
• Register Handlers
• Unregister Handlers
Tuesday, October 9, 12
Event Bus - How
• Register Handlers
• Unregister Handlers
• Addresses
Tuesday, October 9, 12
Event Bus - How
• Register Handlers
• Unregister Handlers
• Addresses
• Messages (Transient)
Tuesday, October 9, 12
Register Handler
var eb = vertx.eventBus;
var myHandler = function(message)) { log.info('I received a message ' + message);}
eb.registerHandler('test.address', myHandler);
Tuesday, October 9, 12
Register Handler
var eb = vertx.eventBus;
var myHandler = function(message)) { log.info('I received a message ' + message);}
eb.registerHandler('test.address', myHandler);
eb.unregisterHandler('test.address', myHandler);
Tuesday, October 9, 12
Publish Subscribe
eb.publish('test.address', 'hello world');
Tuesday, October 9, 12
Point to Point
eb.send('test.address', 'hello world');
Tuesday, October 9, 12
RPC Server
var myHandler = function(message, replier) { log.info('I received a message ' + message);
// Do some stuff
// Now reply to it
replier('This is a reply');}
eb.registerHandler('test.address', myHandler);
Tuesday, October 9, 12
RPC Client
eb.send('test.address', 'This is a message', function(reply) { log.info('I received a reply ' + reply);});
Tuesday, October 9, 12
Shared Data
• Shared Maps
Tuesday, October 9, 12
Shared Data
• Shared Maps
• Shared Sets
Tuesday, October 9, 12
Shared Set Example
load('vertx.js')
var conns = vertx.getSet('conns')
var server = vertx.createNetServer().connectHandler(function(socket) { conns.add(socket.writeHandlerID) socket.dataHandler(function(data) { var aconns = conns.toArray(); for (var i = 0; i < aconns.length; i++) { vertx.eventBus.send(aconns[i], data) } }); socket.closedHandler(function() { conns.remove( socket.writeHandlerID) });}).listen(1234)
Tuesday, October 9, 12
Benchmarks
Tuesday, October 9, 12
Benchmarks I
http://vertxproject.wordpress.com/2012/05/09/vert-x-vs-node-js-simple-http-benchmarks/
Tuesday, October 9, 12
Benchmarks II
http://vertxproject.wordpress.com/2012/05/09/vert-x-vs-node-js-simple-http-benchmarks/
Tuesday, October 9, 12
Internals
Tuesday, October 9, 12
Internals
• Netty for network IO
• JRuby for the Ruby Engine
• Groovy
• Mozilla Rhino for JS
• Jython for Python support
• Hazelcast for clustering
Tuesday, October 9, 12
Questions?
Tuesday, October 9, 12
Thanks!http://twitter.com/old_soundhttps://github.com/videlalvaro/
http://www.slideshare.net/old_sound
Tuesday, October 9, 12