javaone 2014 - scalable javascript applications with project nashorn [con6423]
DESCRIPTION
Speakers: Leonardo Zanivan Michel GracianoTRANSCRIPT
Scalable JavaScript applications with Project Nashorn
SpeakersLeonardo ZanivanSoftware Architect, Trier Sistemasgithub.com/panga@leonardopanga
Michel GracianoSoftware Architect, Betha Sistemasgithub.com/mgraciano@mgraciano
Agenda● Why JS in the server● Why the JVM● Nashorn ecosystem● Vert.x and Avatar/Avatar.js● Q&A
Why JS in the server● Asynchronous by nature● Native JSON support● Language reuse● Easier developer transition
Why the JVM● Multilanguage● APM Tools● Access to the Java ecosystem
o Domain models already implementedo Java EEo Core and third parties Java libraries
Nashorn● JDK 8 Compact 1 Profile with extension● Restrictions (browsers API, DOM)● No native CommonJS implementation● ECMA 5.1 + Rhino compatibility● jjs interactive command line tool
Nashorn● JDK 8u20
o JDK-8032068: sourceURL directiveso JDK-8021350: Share script classes between
threads/globals● JDK 8u40
o JEP 196: Nashorn Optimistic Typingo JEP 202: Nashorn Class Filtero JEP 203: Initial ES6 implementation (const & let)
● JEP 194: Nashorn Code Persistence (lazy compilation)
But how to scale it?
But how to scale it?Architectures and Technologies
Event-driven architecture● Event-loops● Async non-blocking IO● Reactive system● Event bus
Event-driven architecture
Microservice architecture● Focused on specific business● Well defined & distributed● Loosely coupled● Testable● Scalable
Microservices Architecture
Vert.x● http://vertx.io/● Based on Netty● Sponsored by Red Hat● Winner of JAX Innovation Awards 2014
@timfox: Writing Highly Concurrent Polyglot Applications with Vert.x [CON7902] Thursday, Oct 2, 11:30 AM
Vert.x● Key benefits
o Polygloto Event bus (async & worker verticles)o Create reactive applicationso Microservices readyo Strong community involvement
Vert.x Architecture
Vert.x● Key benefits
o Easy deployment CLI, API, mods, runtime deps resolution
o Good build tools support (fat jar, auto-redeploy)
o Native Cluster & HA with Hazelcasto Tons of extensions available
Vert.x● Challenges
o Updated documentationo Verticle monitoringo Limited transactions supporto Doesn’t have distributed maps yet (2.x)o Nashorn debugging support (PR to be
merged)
Vert.x● Vert.x 3 highlights
o JDK 8+ with Nashorn & Lambdao No more module system*o Clustered shared datao Event bus proxies & codecso Ext stack (MongoDB, SockJS, Route, Rx)
Demo● Real-time notification service using
websockets over nashorn integrating with a legacy Java EE app
Avatar.js● https://avatar-js.java.net● Oracle sponsored● Focus on bringing the node
programming model, APIs and module ecosystem to the Java platform
Avatar.js
Avatar● https://avatar.java.net● Oracle sponsored● Focus on Thin Server Architecture
o Supports REST, WebSocket and Server-Sent Events
● Built on Avatar.js
Avatar Architecture
Avatar EE Architecture
● Deploying an application on Glassfish 4o asadmin deploy ~/projects/<app-folder-
name>● Running the application
o http://localhost:8080/<app-folder-name>
Avatar
Avatar/Avatar.js● Key benefits
o Avatar Services use an Actor-like concurrency model
o NPM modules supporto Strong Java EE integrationo Debugging
Avatar/Avatar.js● Challenges
o Weak community involvemento Low activity and no stable releaseo Glassfish / Weblogic onlyo Model Store API supports only Oracle NoSQL
for schemaless database
Benchmark● Some simple and naive scenarios
o Posting and querying from databaseo Returning a simple JSON responseo String concatenationo Fibonacci calculation
Benchmark● Node.js 0.10.29 (2014-06-16)● Avatar.js 0.10.28-SNAPSHOT (2014-07-
20)● Vert.X 2.1.1 (2014-06-18)● Avatar 1.0-ea-SNAPSHOT (2014-07-26)● JDK 8u5
Some Fib(30) results
Some Fib(30) results
Some Fib(30) results
Q&A
Credits● Event-loop & Vert.X architecture
o Slideshare presentation http://bit.ly/1qz6KUb
● Microservice architectureo http://martinfowler.com/articles/microservices.html
● Avatar.js architectureo Project Avatar.js website
● Avatar and Avatar EE architectureso Project Avatar website
Thank you!@leonardopanga@mgraciano
● Sourceso github.com/mgraciano/javaone-2014o github.com/panga/javaone2014-benchmarks