apache spark avec nodejs ? oui, c'est possible avec eclairjs !

16
DEVFEST NANTES 16 Bruno Bonnin - @_bruno_b_ Apache Spark avec NodeJS ? Oui, c’est possible avec EclairJS !

Upload: bruno-bonnin

Post on 20-Mar-2017

288 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

DEVFEST NANTES 16

Bruno Bonnin - @_bruno_b_

Apache Spark avec NodeJS ?Oui, c’est possible avec EclairJS !

Page 2: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

2DEVFEST NANTES 16

About me

Bruno Bonnin - @_bruno_b_

Architecte / Développeur

http://webdemo.myscript.com/

Page 3: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

3DEVFEST NANTES 16

Java, Scala, Python, R

JavaScript

Page 4: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

4DEVFEST NANTES 16

EclairJS

Page 5: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

5DEVFEST NANTES 16

Spark WorkerSpark Worker

EclairJS

Cluster Manager

Spark WorkersSpark Driver

Libs SparkLibs Spark

Script EngineScript Engine

EclairJS Nashorn

EclairJS Nashorn

JVMJVM

App

NodeJS

EclairJS NodeJS

Page 6: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

6DEVFEST NANTES 16

EclairJS: implémentation des composants

Page 7: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

7DEVFEST NANTES 16

EclairJS: API Spark Core

val lines = sc.textFile("dream.txt")

val words = lines

.flatMap(

line => line.split(" "))

.filter(

word => word.trim.length > 0)

val counts = words

.mapToPair(

word => (word, 1))

.reduceByKey(_ + _)

var lines = sc.textFile("dream.txt");

var words = lines

.flatMap(function (line) {

return line.split(" "); })

.filter(function (word) {

return word.trim().length > 0; });

var counts = words

.mapToPair(function (word, Tuple2) {

return new Tuple2(word, 1); }, [Tuple2])

.reduceByKey(function (a, b) { return a + b; });

Page 8: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

8DEVFEST NANTES 16

EclairJS: API Spark SQL

val df = sqlCtx.read.json("people.json")

df.printSchema()

df.select("name", "age")

.filter(col("age").gt(30))

.show()

df.registerTempTable("people")

val sqlDF = sqlCtx

.sql("SELECT * FROM people")

sqlDF.show()

var df = sqlCtx.read().json('people.json');

df.printSchema();

df.select('name', 'age')

.filter(col('age').gt(30))

.show();

df.registerTempTable('people');

var sqlDF = sqlCtx

.sql('SELECT * FROM people');

sqlDF.show();

Page 9: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

9DEVFEST NANTES 16

app.get('/words', (req, res) => {

var lines = sc.textFile('dream.txt').cache();

var something = 0;

var words = lines

.flatMap(line => {

something += 1;

console.log('flatmap:' + line);

return line.split(' ');

})

.collect()

});

EclairJS: code dans NodeJS

Page 10: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

10DEVFEST NANTES 16

app.get('/words', (req, res) => {

var lines = sc.textFile('dream.txt').cache();

var something = 0;

var words = lines

.flatMap(line => {

something += 1;

console.log('flatmap:' + line);

return line.split(' ');

})

.collect()

});

EclairJS: code dans NodeJS

.then(results => { res.json({result: results}); })

.catch(err => { res.status(500).send(err); });

Page 11: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

11DEVFEST NANTES 16

app.get('/words', (req, res) => {

var lines = sc.textFile('dream.txt').cache();

var something = 0;

var words = lines

.flatMap(line => {

something += 1;

console.log('flatmap:' + line);

return line.split(' ');

})

.collect()

});

EclairJS: code dans NodeJS

.then(results => { res.json({result: results}); })

.catch(err => { res.status(500).send(err); });

Page 12: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

12DEVFEST NANTES 16

app.get('/words', (req, res) => {

var lines = sc.textFile('dream.txt').cache();

var something = 0;

var words = lines

.flatMap(line => { function (line) {

something += 1;

console.log('flatmap:' + line);

return line.split(' ');

})

.collect()

.then(results => { res.json({result: results}); })

.catch(err => { res.status(500).send(err); });

});

EclairJS: code dans NodeJS

Code métier interpréter dans Nashorn (pas dans NodeJS) :

● Ne connait pas console● Est compliant ES5

Page 13: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

13DEVFEST NANTES 16

EclairJS: déploiement

Spark WorkerSpark WorkersApplication

EclairJS - API Node

Cluster Manager EclairJS - API

Nashorn

Apache Toree(Spark Driver)

EclairJS - API Nashorn

Jupyter NotebookGateway

EclairJS Shell

EclairJS - API Nashorn

Page 14: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

14DEVFEST NANTES 16

Démo

Client SparkApplication

EclairJS - API Node EclairJS - API Nashorn

Spark Workers

EclairJS - API Nashorn

Page 15: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

15DEVFEST NANTES 16

Conclusion

Facile à apprendre (surtout pour ceux qui connaissent l’API Scala/Java)

Idéal pour les développeurs JS que le Scala peut rebuter :-)

Implémentation en cours : dernière version avec le support de Spark 2.0

Pour aller plus loin:

● https://eclairjs.github.io/ ● https://github.com/EclairJS/eclairjs

Page 16: Apache Spark avec NodeJS ? Oui, c'est possible avec EclairJS !

16DEVFEST NANTES 16 16DEVFEST NANTES 16

Merci ! @_bruno_b_

https://github.com/bbonnin/devfestnantes2016