Scalable JavaScript applications 
with Project Nashorn
Speakers 
Leonardo Zanivan 
Software Architect, Trier Sistemas 
github.com/panga 
@leonardopanga 
Michel Graciano 
Software Architect, Betha Sistemas 
github.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 
○ Domain models already implemented 
○ Java EE 
○ 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 
○ JDK-8032068: sourceURL directives 
○ JDK-8021350: Share script classes between 
threads/globals 
● JDK 8u40 
○ JEP 196: Nashorn Optimistic Typing 
○ JEP 202: Nashorn Class Filter 
○ 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 
○ Polyglot 
○ Event bus (async & worker verticles) 
○ Create reactive applications 
○ Microservices ready 
○ Strong community involvement
Vert.x Architecture
Vert.x 
● Key benefits 
○ Easy deployment 
■ CLI, API, mods, runtime deps resolution 
○ Good build tools support (fat jar, auto-redeploy) 
○ Native Cluster & HA with Hazelcast 
○ Tons of extensions available
Vert.x 
● Challenges 
○ Updated documentation 
○ Verticle monitoring 
○ Limited transactions support 
○ Doesn’t have distributed maps yet (2.x) 
○ Nashorn debugging support (PR to be merged)
Vert.x 
● Vert.x 3 highlights 
○ JDK 8+ with Nashorn & Lambda 
○ No more module system* 
○ Clustered shared data 
○ Event bus proxies & codecs 
○ 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 
○ Supports REST, WebSocket and Server-Sent 
Events 
● Built on Avatar.js
Avatar Architecture
Avatar EE Architecture
Avatar 
● Deploying an application on Glassfish 4 
○ asadmin deploy ~/projects/<app-folder-name> 
● Running the application 
○ http://localhost:8080/<app-folder-name>
Avatar/Avatar.js 
● Key benefits 
○ Avatar Services use an Actor-like concurrency 
model 
○ NPM modules support 
○ Strong Java EE integration 
○ Debugging
Avatar/Avatar.js 
● Challenges 
○ Weak community involvement 
○ Low activity and no stable release 
○ Glassfish / Weblogic only 
○ Model Store API supports only Oracle NoSQL for 
schemaless database
Benchmark 
● Some simple and naive scenarios 
○ Posting and querying from database 
○ Returning a simple JSON response 
○ String concatenation 
○ 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 
○ Slideshare presentation http://bit.ly/1qz6KUb 
● Microservice architecture 
○ http://martinfowler.com/articles/microservices.html 
● Avatar.js architecture 
○ Project Avatar.js website 
● Avatar and Avatar EE architectures 
○ Project Avatar website
Thank you! 
@leonardopanga 
@mgraciano 
● Sources 
○ github.com/mgraciano/javaone-2014 
○ github.com/panga/javaone2014-benchmarks

CON6423: Scalable JavaScript applications with Project Nashorn

  • 1.
    Scalable JavaScript applications with Project Nashorn
  • 2.
    Speakers Leonardo Zanivan Software Architect, Trier Sistemas github.com/panga @leonardopanga Michel Graciano Software Architect, Betha Sistemas github.com/mgraciano @mgraciano
  • 3.
    Agenda ● WhyJS in the server ● Why the JVM ● Nashorn ecosystem ● Vert.x and Avatar/Avatar.js ● Q&A
  • 4.
    Why JS inthe server ● Asynchronous by nature ● Native JSON support ● Language reuse ● Easier developer transition
  • 5.
    Why the JVM ● Multilanguage ● APM Tools ● Access to the Java ecosystem ○ Domain models already implemented ○ Java EE ○ Core and third parties Java libraries
  • 6.
    Nashorn ● JDK8 Compact 1 Profile with extension ● Restrictions (browsers API, DOM) ● No native CommonJS implementation ● ECMA 5.1 + Rhino compatibility ● jjs interactive command line tool
  • 14.
    Nashorn ● JDK8u20 ○ JDK-8032068: sourceURL directives ○ JDK-8021350: Share script classes between threads/globals ● JDK 8u40 ○ JEP 196: Nashorn Optimistic Typing ○ JEP 202: Nashorn Class Filter ○ JEP 203: Initial ES6 implementation (const & let) ● JEP 194: Nashorn Code Persistence (lazy compilation)
  • 15.
    But how toscale it?
  • 16.
    But how toscale it? Architectures and Technologies
  • 17.
    Event-driven architecture ●Event-loops ● Async non-blocking IO ● Reactive system ● Event bus
  • 18.
  • 19.
    Microservice architecture ●Focused on specific business ● Well defined & distributed ● Loosely coupled ● Testable ● Scalable
  • 20.
  • 21.
    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
  • 22.
    Vert.x ● Keybenefits ○ Polyglot ○ Event bus (async & worker verticles) ○ Create reactive applications ○ Microservices ready ○ Strong community involvement
  • 23.
  • 24.
    Vert.x ● Keybenefits ○ Easy deployment ■ CLI, API, mods, runtime deps resolution ○ Good build tools support (fat jar, auto-redeploy) ○ Native Cluster & HA with Hazelcast ○ Tons of extensions available
  • 25.
    Vert.x ● Challenges ○ Updated documentation ○ Verticle monitoring ○ Limited transactions support ○ Doesn’t have distributed maps yet (2.x) ○ Nashorn debugging support (PR to be merged)
  • 26.
    Vert.x ● Vert.x3 highlights ○ JDK 8+ with Nashorn & Lambda ○ No more module system* ○ Clustered shared data ○ Event bus proxies & codecs ○ Ext stack (MongoDB, SockJS, Route, Rx)
  • 27.
    Demo ● Real-timenotification service using websockets over nashorn integrating with a legacy Java EE app
  • 28.
    Avatar.js ● https://avatar-js.java.net ● Oracle sponsored ● Focus on bringing the node programming model, APIs and module ecosystem to the Java platform
  • 29.
  • 30.
    Avatar ● https://avatar.java.net ● Oracle sponsored ● Focus on Thin Server Architecture ○ Supports REST, WebSocket and Server-Sent Events ● Built on Avatar.js
  • 31.
  • 32.
  • 35.
    Avatar ● Deployingan application on Glassfish 4 ○ asadmin deploy ~/projects/<app-folder-name> ● Running the application ○ http://localhost:8080/<app-folder-name>
  • 36.
    Avatar/Avatar.js ● Keybenefits ○ Avatar Services use an Actor-like concurrency model ○ NPM modules support ○ Strong Java EE integration ○ Debugging
  • 37.
    Avatar/Avatar.js ● Challenges ○ Weak community involvement ○ Low activity and no stable release ○ Glassfish / Weblogic only ○ Model Store API supports only Oracle NoSQL for schemaless database
  • 38.
    Benchmark ● Somesimple and naive scenarios ○ Posting and querying from database ○ Returning a simple JSON response ○ String concatenation ○ Fibonacci calculation
  • 39.
    Benchmark ● Node.js0.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
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
    Credits ● Event-loop& Vert.X architecture ○ Slideshare presentation http://bit.ly/1qz6KUb ● Microservice architecture ○ http://martinfowler.com/articles/microservices.html ● Avatar.js architecture ○ Project Avatar.js website ● Avatar and Avatar EE architectures ○ Project Avatar website
  • 45.
    Thank you! @leonardopanga @mgraciano ● Sources ○ github.com/mgraciano/javaone-2014 ○ github.com/panga/javaone2014-benchmarks