45
Scalable JavaScript applications with Project Nashorn

JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Embed Size (px)

DESCRIPTION

Speakers: Leonardo Zanivan Michel Graciano

Citation preview

Page 1: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Scalable JavaScript applications with Project Nashorn

Page 2: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

SpeakersLeonardo ZanivanSoftware Architect, Trier Sistemasgithub.com/panga@leonardopanga

Michel GracianoSoftware Architect, Betha Sistemasgithub.com/mgraciano@mgraciano

Page 3: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Agenda● Why JS in the server● Why the JVM● Nashorn ecosystem● Vert.x and Avatar/Avatar.js● Q&A

Page 4: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Why JS in the server● Asynchronous by nature● Native JSON support● Language reuse● Easier developer transition

Page 5: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Why the JVM● Multilanguage● APM Tools● Access to the Java ecosystem

o Domain models already implementedo Java EEo Core and third parties Java libraries

Page 6: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 8: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 9: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 10: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 11: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 12: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 13: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 14: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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)

Page 15: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

But how to scale it?

Page 16: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

But how to scale it?Architectures and Technologies

Page 17: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Event-driven architecture● Event-loops● Async non-blocking IO● Reactive system● Event bus

Page 18: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Event-driven architecture

Page 19: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Microservice architecture● Focused on specific business● Well defined & distributed● Loosely coupled● Testable● Scalable

Page 20: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Microservices Architecture

Page 21: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Vert.x● Key benefits

o Polygloto Event bus (async & worker verticles)o Create reactive applicationso Microservices readyo Strong community involvement

Page 23: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Vert.x Architecture

Page 24: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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

Page 25: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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)

Page 26: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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)

Page 27: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Demo● Real-time notification service using

websockets over nashorn integrating with a legacy Java EE app

Page 28: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Avatar.js

Page 30: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Avatar● https://avatar.java.net● Oracle sponsored● Focus on Thin Server Architecture

o Supports REST, WebSocket and Server-Sent Events

● Built on Avatar.js

Page 31: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Avatar Architecture

Michel Graciano
Imagens precisam de retoque quanto ao contraste. Farei isso mais pra frente, assim que fechar o assunto e confirmar que elas continuarão aqui.
Page 32: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Avatar EE Architecture

Michel Graciano
Imagens precisam de retoque quanto ao contraste. Farei isso mais pra frente, assim que fechar o assunto e confirmar que elas continuarão aqui.
Page 33: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Leonardo Loch Zanivan
Demo com Avatar.js e Avatar tem nos benchmarks, utilizando REST e um módulo NPM, bem simpleshttps://github.com/panga/javaone2014-benchmarks/tree/master/avatar-app
Michel Graciano
Sim, utilizarei ele. A pergunta é: terei tempo? :D
Michel Graciano
Fica aqui a ideia que conversamos... talvez apenas invluir slides com o código, para ganhar tempo.
Leonardo Loch Zanivan
De acordo
Michel Graciano
Esta com erro na minha máquina. Se eu não conseguir fazer rodar esta semana, e no final de semana não der, vou apenas mostrar o fonte e a gente tenta deixar o teu laptop pra mostrar. Eles fazem switch de telas de forma facil la (teoricamente). Senao, nao mostro rodando... apenas codigo.
Michel Graciano
Hoje não vou conseguir testar isso... estou apenas o pó!
Page 34: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Page 35: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

● Deploying an application on Glassfish 4o asadmin deploy ~/projects/<app-folder-

name>● Running the application

o http://localhost:8080/<app-folder-name>

Avatar

Page 36: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Avatar/Avatar.js● Key benefits

o Avatar Services use an Actor-like concurrency model

o NPM modules supporto Strong Java EE integrationo Debugging

Page 37: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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

Leonardo Loch Zanivan
O tópico dos problemas com node_modules foi um comentário que eu fiz da dificuldade que eu tive de utilizar node_modules dentro do app, só conseguir fazer com módulos globais, APESAR de ter lido em algum lugar (que não lembro) que suportava dentro da aplicação, vale verificar ou remover isso da apresentação
Page 38: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Benchmark● Some simple and naive scenarios

o Posting and querying from databaseo Returning a simple JSON responseo String concatenationo Fibonacci calculation

Page 39: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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

Michel Graciano
Aqui temos que pensar numa estratégia de mostrar os benchmarks
Michel Graciano
Como conversamos, gráficos seria uma boa estratégia.
Leonardo Loch Zanivan
Antes de ir pros gráficos seria bom explicar o objetivo dos benchmarks realizados, pode citar todos, mas pontuar apenas o fib. Só que com os novos resultados do 8u40 mudou bastante essa parte. Se quiser citar eu te mando o arquivo com os resultados novos.
Leonardo Loch Zanivan
A memória baixou muito o uso, ficou quase igual no java, o que mudou foi: Lower memory usage (Nashorn)Higher throughput (Nashorn)
Page 40: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Some Fib(30) results

Page 41: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Some Fib(30) results

Page 42: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Some Fib(30) results

Page 43: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Q&A

Page 44: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

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

Page 45: JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]

Thank you!@leonardopanga@mgraciano

● Sourceso github.com/mgraciano/javaone-2014o github.com/panga/javaone2014-benchmarks