4Developers 2015: Nashorn - o co ten cały szum - Michał Gruca
CON6423: Scalable JavaScript applications with Project Nashorn
-
Upload
michel-graciano -
Category
Technology
-
view
115 -
download
1
description
Transcript of CON6423: Scalable JavaScript applications with Project Nashorn
![Page 1: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/1.jpg)
Scalable JavaScript applications with Project Nashorn
![Page 2: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/2.jpg)
SpeakersLeonardo ZanivanSoftware Architect, Trier Sistemasgithub.com/panga@leonardopanga
Michel GracianoSoftware Architect, Betha Sistemasgithub.com/mgraciano@mgraciano
![Page 3: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/3.jpg)
Agenda● Why JS in the server● Why the JVM● Nashorn ecosystem● Vert.x and Avatar/Avatar.js● Q&A
![Page 4: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/4.jpg)
Why JS in the server● Asynchronous by nature● Native JSON support● Language reuse● Easier developer transition
![Page 5: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/5.jpg)
Why the JVM● Multilanguage● APM Tools● Access to the Java ecosystem
○ Domain models already implemented○ Java EE○ Core and third parties Java libraries
![Page 6: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/6.jpg)
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
![Page 7: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/7.jpg)
![Page 8: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/8.jpg)
![Page 9: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/9.jpg)
![Page 10: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/10.jpg)
![Page 11: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/11.jpg)
![Page 12: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/12.jpg)
![Page 13: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/13.jpg)
![Page 14: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/14.jpg)
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)
![Page 15: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/15.jpg)
But how to scale it?
![Page 16: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/16.jpg)
But how to scale it?Architectures and Technologies
![Page 17: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/17.jpg)
Event-driven architecture● Event-loops● Async non-blocking IO● Reactive system● Event bus
![Page 18: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/18.jpg)
Event-driven architecture
![Page 19: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/19.jpg)
Microservice architecture● Focused on specific business● Well defined & distributed● Loosely coupled● Testable● Scalable
![Page 20: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/20.jpg)
Microservices Architecture
![Page 21: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/21.jpg)
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
![Page 22: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/22.jpg)
Vert.x● Key benefits
○ Polyglot○ Event bus (async & worker verticles)○ Create reactive applications○ Microservices ready○ Strong community involvement
![Page 23: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/23.jpg)
Vert.x Architecture
![Page 24: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/24.jpg)
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
![Page 25: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/25.jpg)
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)
![Page 26: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/26.jpg)
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)
![Page 27: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/27.jpg)
Demo● Real-time notification service using
websockets over nashorn integrating with a legacy Java EE app
![Page 28: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/28.jpg)
Avatar.js● https://avatar-js.java.net● Oracle sponsored● Focus on bringing the node programming
model, APIs and module ecosystem to the Java platform
![Page 29: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/29.jpg)
Avatar.js
![Page 30: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/30.jpg)
Avatar● https://avatar.java.net● Oracle sponsored● Focus on Thin Server Architecture
○ Supports REST, WebSocket and Server-Sent Events
● Built on Avatar.js
![Page 31: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/31.jpg)
Avatar Architecture
![Page 32: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/32.jpg)
Avatar EE Architecture
![Page 33: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/33.jpg)
![Page 34: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/34.jpg)
![Page 35: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/35.jpg)
● Deploying an application on Glassfish 4○ asadmin deploy ~/projects/<app-folder-name>
● Running the application○ http://localhost:8080/<app-folder-name>
Avatar
![Page 36: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/36.jpg)
Avatar/Avatar.js● Key benefits
○ Avatar Services use an Actor-like concurrency model
○ NPM modules support○ Strong Java EE integration○ Debugging
![Page 37: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/37.jpg)
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
![Page 38: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/38.jpg)
Benchmark● Some simple and naive scenarios
○ Posting and querying from database○ Returning a simple JSON response○ String concatenation○ Fibonacci calculation
![Page 39: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/39.jpg)
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
![Page 40: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/40.jpg)
Some Fib(30) results
![Page 41: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/41.jpg)
Some Fib(30) results
![Page 42: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/42.jpg)
Some Fib(30) results
![Page 43: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/43.jpg)
Q&A
![Page 44: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/44.jpg)
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
![Page 45: CON6423: Scalable JavaScript applications with Project Nashorn](https://reader034.fdocuments.us/reader034/viewer/2022042715/557d6036d8b42ae1438b4f9b/html5/thumbnails/45.jpg)
Thank you!@leonardopanga@mgraciano
● Sources○ github.com/mgraciano/javaone-2014○ github.com/panga/javaone2014-benchmarks