9. the problem
number of mobile users raises
2,1 bln in 2012 -> 7 bln in 2018
Internet of things - 30 bln in 2020!
IPv4 is exhausted
IPv6 is already ready for all of them
9
10. the problem
traditional synchronous approach
■one thread handles one task
■thread is waiting for job to finish
■whole queue of tasks waits
10
11. the problem
traditional synchronous approach
■synchronous code
■scalability problem
■lots of threads
■concurrency that no-one understands ;)
11
12. the problem
12
Tomcat: 200 threads = 200 connections
rest of incoming connections must wait*…
*okay, now you can do nonblocking in Tomcat
https://tomcat.apache.org/tomcat-7.0-doc/aio.html
66. 66
Router router = new RouterImpl(vertx);
router.get("/users/:uid").handler( ctx -> {
String id = ctx.request().getParam("uid");
JsonObject user =
new JsonObject().put("id", id).put("name", "bartek");
ctx.response().end(user.encode());
});
HttpServer server = vertx.createHttpServer();
server.requestHandler(router::accept).listen(8080);
web server ext - neat path and content routing
68. 68
//SessionHandler must be preceded with SessionHandler
router.route().handler(CookieHandler.create());
router.route().handler(
SessionHandler.create(LocalSessionStore.create(vertx)));
router.get("/sessionCounter").handler(ctx -> {
ctx.session().get("counter");
}
web server ext - accessing session
76. verticles:
■are actor-like
■can be addressed
■can subscribe to many addresses
■can do processing jobs
■can send back content
■can have multiple instances of same class
76
vert.x vs akka
78. vertically
■verticle can have multiple instances
■each instance can have own processor core
horizontally
■clustering - lot’s of nodes
■eventbus reaches all nodes
78
how vert.x scales
81. 81
puts "Ruby for the win!"
eb = $vertx.event_bus()
# Send a message every second
$vertx.set_periodic(1000) { |v|
puts "RUBY: sending Ruby message"
eb.publish("producer.address", "Ruby shines!")
}
Ruby shines
82. 82
var eb = vertx.eventBus();
eb.consumer("producer.address", function (message) {
console.log("JAVASCRIPT: Received a message: " + message.body());
});
console.log("Receiver ready!");
For JavaScript dare devils!
84. ■effective use of servers’ resources
■parallel computing
■great as a backend for lots of (mobile)
clients
■nice integration platform
■could be awesome in microservices
84
usecases
89. I’m not the owner of the pictures used. Just found them on:
http://www.rantchic.com/wp-content/uploads/2013/12/Apollo-13.jpg
http://www.gamesaktuell.de/screenshots/1280x1024/2009/04/terminator_2_blu_ray03.jpg
http://tripoutlook.com/wp-content/uploads/2013/03/Car-parking.jpg
http://upload.wikimedia.org/wikipedia/commons/5/52/Parallel_Parking_cars.jpg
http://www.foreverbarcelona.com/wp-content/uploads/2014/02/Taxi-Tips.png
http://www.125p.eu/wp-content/uploads/2009/03/fiat-125p-zmiennicy-5.jpg
http://www.novosti.rs/upload/images/2011/07/2107/bg-taksi.jpg
http://i.livescience.com/images/i/000/024/292/iFF/neurons-120208.jpg?1328727600
89
All the pics used