Creating polyglot and scalable applications on the jvm using Vert.x
description
Transcript of Creating polyglot and scalable applications on the jvm using Vert.x
![Page 1: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/1.jpg)
Jettro Coenradie@gridshore
Creating Polyglot and Scalable Applications on the JVM with Vert.x
dinsdag 30 oktober 12
The butterfly represents the lightweight scalable architecture
![Page 2: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/2.jpg)
http://maps.google.com
dinsdag 30 oktober 12
Does this territory look familiar?
![Page 3: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/3.jpg)
http://maps.google.com
dinsdag 30 oktober 12
Tripoint of countries: The netherlands, Germany and BelgiumPeople here speak multiple languages and are therefore Polyglot
![Page 4: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/4.jpg)
Polyglot applications
http://maps.google.com
dinsdag 30 oktober 12
- Polyglot applications is not about writing them in Dutch, German and French- Discuss combining multiple jvm languages in one application
![Page 5: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/5.jpg)
1996
1
1997
1.1
JDBC, Reflection
1998
1.2
JIT Compiler, Collections framework
2000
1.3
Hotspot JVM, JNDI
2002
1.4
Reg Exp, NIO, XML parsing
2004
5
Generics, Varargs, enums
2006
6
Scripting Language Support
2011
7
Dynamic languages on JVM
dinsdag 30 oktober 12
The history of the JVM and the introduction of Dynamic languages on the JVM and the importance for a polyglot application on the JVM.
![Page 6: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/6.jpg)
Polyglot applications on the JVM
dinsdag 30 oktober 12
Now the JVM supports creating Polyglot applications.
![Page 7: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/7.jpg)
C10K Problem
http://www.tumblr.com/tagged/rockconcert?before=1346635427dinsdag 30 oktober 12
C10k problemThe crowd becomes to big for your platform
![Page 8: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/8.jpg)
http://en.wikipedia.org/wiki/C10k_problem
dinsdag 30 oktober 12
Wikipedia page about the C10K problem showing the main characteristics of available solutions: event-driven, non-blocking and asynchronous
![Page 9: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/9.jpg)
Scalable applications on the JVM
dinsdag 30 oktober 12
Some of the mentioned solutions run on the JVM and the JVM is the right tools for the job when you want to create non-blocking, event-driven, asynchronous applications.
![Page 10: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/10.jpg)
Vert.x
@timfox
✦Netty✦JRuby✦Groovy✦Rhino✦Jython✦Hazelcast
dinsdag 30 oktober 12
Introduction of vertx, the creator and the main technologies used.
![Page 11: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/11.jpg)
Polyglot application platform
JavaScript
dinsdag 30 oktober 12
The available languages for vert.x and the languages for which support is being created.
![Page 12: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/12.jpg)
Scalable: Blocking to non-blocking
dinsdag 30 oktober 12
Blocking has the risk that the CPU is doing nothing while a thread is waiting for inputNon-blocking: can use the CPU more effectively if there is something to do, it does not fall asleep
![Page 13: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/13.jpg)
Easily Concurrent
dinsdag 30 oktober 12
- We can use the multiple cores of a machine within one JVM- Easy concurrency due to thread bound modules and verticles => No Locking- Synchronous calling of a request handler. Therefore no concurrency issues.
![Page 14: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/14.jpg)
Vert.x Components
Verticle
Verticle
Worker
Worker
Module Module Module
CoreServices
Event Loop 1
Event Loop 2
Background Pool
Event Bus
dinsdag 30 oktober 12
Go through all the different components of Vert.x
![Page 15: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/15.jpg)
Verticle
Verticle
Worker
Worker
Module Module Module
CoreServices
Event Loop 1
Event Loop 2
Background Pool
Event Bus
Vert.x Core
• Must be implemented by all languages
• Core services must be called direct
• Example Services
• TCP/SSL, HTTP/HTTPS, WebSockets, Logging, SockJS and more
dinsdag 30 oktober 12
Core services must be called directly, no need for sending messages
![Page 16: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/16.jpg)
Verticle
• Unit of deployment in Vert.x
• Can contain other scripts
• Can contain libraries
• Can start other verticles
Verticle
Verticle
Worker
Worker
Module Module Module
CoreServices
Event Loop 1
Event Loop 2
Background Pool
Event Bus
dinsdag 30 oktober 12
- Demo basic verticle
![Page 17: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/17.jpg)
Module
• Modules communicate using messages
• A public module repository
• https://github.com/vert-x/vertx-mods/tree/gh-pages/mods
Verticle
Verticle
Worker
Worker
Module Module Module
CoreServices
Event Loop 1
Event Loop 2
Background Pool
Event Bus
dinsdag 30 oktober 12
![Page 18: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/18.jpg)
Worker Verticle
• For tasks that require blocking
• For tasks that take a lot of computation
• Uses thread of the background pool
• They are never executed by more than one thread
Verticle
Verticle
Worker
Worker
Module Module Module
CoreServices
Event Loop 1
Event Loop 2
Background Pool
Event Bus
dinsdag 30 oktober 12
![Page 19: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/19.jpg)
Verticle or Module
• Verticle is easy to use
• Verticle needs to be configured with its classpath when running
• A module is a package of vert.x stuff complete with dependencies.
Verticle
Verticle
Worker
Worker
Module Module Module
CoreServices
Event Loop 1
Event Loop 2
Background Pool
Event Bus
dinsdag 30 oktober 12
![Page 20: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/20.jpg)
Communicating between modules
• Send messages over the Event bus
• Vert.x will automatically convert messages between modules
Java JsonObject
Groovy Map
Ruby Hash
JavaScript Object
Python Hash
dinsdag 30 oktober 12
Messages can contain contain raw types, but JSON is recommended to be used for information sending using messages.
![Page 21: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/21.jpg)
Threads
• Amount equals number of cores
• Verticles/modules are assigned to an event loop
Event loop
• A thread pool for worker verticles
• Actions can block or take longer CPU time
Background Pool
dinsdag 30 oktober 12
![Page 22: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/22.jpg)
Demo: Office events
Event Bus
Invitations Notifications MongoPersistor
App
Back
up
CoreServices
Background PoolEvent Loop 1
Event Loop 2
Website
Event Loop 1
https://github.com/jettro/vertx-samples/tree/master/office-eventsdinsdag 30 oktober 12
The office events demo is available on github. It is used to show modules, verticles and worker verticles in different languages.
![Page 23: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/23.jpg)
Module layout
• Module naming: prefix.<name>-v<version>
• mod.json
• scripts or classes
• lib/ - libraries required by the module
dinsdag 30 oktober 12
mod.json is the configuration for the module containing the main item, worker or not and some other options.
![Page 24: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/24.jpg)
Configuration
• Pass configuration when deploying a verticle or module
• Use a json object
• json is used according the language as discussed before
dinsdag 30 oktober 12
![Page 25: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/25.jpg)
Events
• Publish/Subscribe
• Peer-to-Peer
• Replying to messages
• Distributed event-bus
dinsdag 30 oktober 12
More info about event usage in Vert.x
![Page 26: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/26.jpg)
Logging
• Default uses java utils logging
• Use other logging framework: log4j for example
• <home>/bin/vertx
• DEFAULT_JVM_OPTS="-Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.Log4jLogDelegateFactory"
• Add the library to the vertx lib folder
• Create a log4j.properties file
dinsdag 30 oktober 12
![Page 27: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/27.jpg)
There is more
• Shared data
• Embedded mode
• Clustered mode
dinsdag 30 oktober 12
![Page 28: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/28.jpg)
More info
JettroCoenradie
@jettroCoenradie@gridshorehttp://www.linkedin.com/in/jettrohttp://www.gridshore.nlhttp://www.trifork.nl
Vert.x
http://vertx.io Downloads and documentation
http://groups.google.com/group/vertx
@timfoxTim Fox
https://github.com/jettro/vertx-samples/ office-events
https://github.com/jettro/
dinsdag 30 oktober 12
![Page 29: Creating polyglot and scalable applications on the jvm using Vert.x](https://reader030.fdocuments.net/reader030/viewer/2022013111/554f6cf8b4c905c8088b52f3/html5/thumbnails/29.jpg)
Rock ?? Concert by Rod Stewart with 3.500.000 visitors
Questions ??
dinsdag 30 oktober 12
Now we can scale our rock concert to around 3.5 million users.