SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Alexis Seigneurin
@aseigneurin @ippontech
Spark
● Traitement de larges volumes de données
● Traitement distribué (commodity hardware)
● Ecrit en Scala, bindings Java et Python
Histoire
● 2009 : AMPLab de l'Université de Berkeley
● Juin 2013 : "Top-level project" de la
fondation Apache
● Mai 2014 : version 1.0.0
● Actuellement : version 1.2.0
Use cases
● Analyse de logs
● Traitement de fichiers texte
● Analytics
● Recherche distribuée (Google, avant)
● Détection de fraude
● Recommendation (articles, produits...)
Proximité avec Hadoop
● Mêmes use cases
● Même modèle de
développement :
MapReduce
● Intégration dans
l'écosystème
Plus simple qu’Hadoop
● API plus simple à prendre en main
● Modèle MapReduce "relâché"
● Spark Shell : traitement interactif
Plus rapide qu’Hadoop
Spark officially sets a new record in large-scale
sorting (5 novembre 2014)
● Tri de 100 To de données
● Hadoop MR : 72 minutes
○ Avec 2100 noeuds (50400 cores)
● Spark : 23 minutes
○ Avec 206 noeuds (6592 cores)
Écosystème Spark
● Spark
● Spark Shell
● Spark Streaming
● Spark SQL
● Spark ML
● GraphX
Intégration
● Yarn, Zookeeper, Mesos
● HDFS
● Cassandra
● Elasticsearch
● MongoDB
Fonctionnement de Spark
● Resilient Distributed Dataset
● Abstraction, collection traitée en parallèle
● Tolérant à la panne
● Manipulation de tuples :
○ Clé - Valeur
○ Tuples indépendants les uns des autres
RDD
Sources
● Fichier sur HDFS
● Fichier local
● Collection en mémoire
● Amazon S3
● Base NoSQL
● ...
● Ou une implémentation custom de
InputFormat
Transformations
● Manipule un RDD, retourne un autre RDD
● Lazy !
● Exemples :
○ map() : une valeur → une valeur
○ mapToPair() : une valeur → un tuple
○ filter() : filtre les valeurs/tuples
○ groupByKey() : regroupe la valeurs par clés
○ reduceByKey() : aggrège les valeurs par clés
○ join(), cogroup()... : jointure entre deux RDD
Actions finales
● Ne retournent pas un RDD
● Exemples :
○ count() : compte les valeurs/tuples
○ saveAsHadoopFile() : sauve les résultats au
format Hadoop
○ foreach() : exécute une fonction sur chaque
valeur/tuple
○ collect() : récupère les valeurs dans une liste
(List<T>)
Exemple
● Arbres de Paris : fichier CSV en Open Data
● Comptage d’arbres par espèce
Spark - Exemple
geom_x_y;circonfere;adresse;hauteurenm;espece;varieteouc;dateplanta
48.8648454814, 2.3094155344;140.0;COURS ALBERT 1ER;10.0;Aesculus hippocastanum;;
48.8782668139, 2.29806967519;100.0;PLACE DES TERNES;15.0;Tilia platyphyllos;;
48.889306184, 2.30400164126;38.0;BOULEVARD MALESHERBES;0.0;Platanus x hispanica;;
48.8599934405, 2.29504883623;65.0;QUAI BRANLY;10.0;Paulownia tomentosa;;1996-02-29
...
Spark - Exemple
JavaSparkContext sc = new JavaSparkContext("local", "arbres");
sc.textFile("data/arbresalignementparis2010.csv")
.filter(line -> !line.startsWith("geom"))
.map(line -> line.split(";"))
.mapToPair(fields -> new Tuple2<String, Integer>(fields[4], 1))
.reduceByKey((x, y) -> x + y)
.sortByKey()
.foreach(t -> System.out.println(t._1 + " : " + t._2));
[... ; … ; …]
[... ; … ; …]
[... ; … ; …]
[... ; … ; …]
[... ; … ; …]
[... ; … ; …]
u
m
k
m
a
a
textFile mapToPairmap
reduceByKey
foreach
1
1
1
1
1
u
m
k
1
2
1
2a
...
...
...
...
filter
...
...
sortByKey
a
m
2
1
2
1u
...
...
...
...
...
...
geom;...
1 k
Spark - Exemple
Acacia dealbata : 2
Acer acerifolius : 39
Acer buergerianum : 14
Acer campestre : 452
...
Spark en cluster
Topologie & Terminologie
● Un master / des workers
○ (+ un master en standby)
● On soumet une application
● Exécution pilotée par un driver
Spark en cluster
Plusieurs options
● YARN
● Mesos
● Standalone
○ Workers démarrés individuellement
○ Workers démarrés par le master
MapReduce
● Spark (API)
● Traitement distribué
● Tolérant à la panne
Stockage
● HDFS, base NoSQL...
● Stockage distribué
● Tolérant à la panne
Stockage & traitements
Colocation données & traitement
● “Data locality”
● Traiter la donnée là où elle se trouve
● Eviter les network I/Os
Colocation données & traitement
Spark
Worker
HDFS
Datanode
Spark
Worker
HDFS
Datanode
Spark
Worker
HDFS
Datanode
Spark Master
HDFS
Namenode
HDFS
Namenode
(Standby)
Spark
Master
(Standby)
Démo
Spark en cluster
Démo
$ $SPARK_HOME/sbin/start-master.sh
$ $SPARK_HOME/bin/spark-class
org.apache.spark.deploy.worker.Worker
spark://MBP-de-Alexis:7077
--cores 2 --memory 2G
$ mvn clean package
$ $SPARK_HOME/bin/spark-submit
--master spark://MBP-de-Alexis:7077
--class com.seigneurin.spark.WikipediaMapReduceByKey
--deploy-mode cluster
target/pres-spark-0.0.1-SNAPSHOT.jar
Spark SQL
● Exploitation d’un RDD en SQL
● Moteur d’exécution SQL : convertit les
requêtes en instructions de base
Spark SQL
Spark SQL
Préalable :
● Disposer de données tabulaires
● Décrire le schéma → SchemaRDD
Description de schéma :
● Description programmatique des données
● Inférence de schéma par réflexion (POJO)
JavaRDD<Row> rdd = trees.map(fields -> Row.create(
Float.parseFloat(fields[3]), fields[4]));
● Création de données tabulaires (type Row)
Spark SQL - Exemple
---------------------------------------
| 10.0 | Aesculus hippocastanum |
| 15.0 | Tilia platyphyllos |
| 0.0 | Platanus x hispanica |
| 10.0 | Paulownia tomentosa |
| ... | ... |
Spark SQL - Exemple
List<StructField> fields = new ArrayList<StructField>();
fields.add(DataType.createStructField("hauteurenm", DataType.FloatType, false));
fields.add(DataType.createStructField("espece", DataType.StringType, false));
StructType schema = DataType.createStructType(fields);
JavaSchemaRDD schemaRDD = sqlContext.applySchema(rdd, schema);
schemaRDD.registerTempTable("tree");
---------------------------------------
| hauteurenm | espece |
---------------------------------------
| 10.0 | Aesculus hippocastanum |
| 15.0 | Tilia platyphyllos |
| 0.0 | Platanus x hispanica |
| 10.0 | Paulownia tomentosa |
| ... | ... |
● Description du schéma
● Comptage d’arbres par espèce
Spark SQL - Exemple
sqlContext.sql("SELECT espece, COUNT(*)
FROM tree
WHERE espece <> ''
GROUP BY espece
ORDER BY espece")
.foreach(row -> System.out.println(row.getString(0)+" : "+row.getLong(1)));
Acacia dealbata : 2
Acer acerifolius : 39
Acer buergerianum : 14
Acer campestre : 452
...
Spark Streaming
Micro-batches
● Découpe un flux continu en batches
● API identique
● ≠ Apache Storm
DStream
● Discretized Streams
● Séquence de RDDs
● Initialisé avec une Duration
Window operations
● Fenêtre glissante
● Réutilise des données d'autres fenêtres
● Initialisé avec window length et slide interval
Sources
● Socket
● Kafka
● Flume
● HDFS
● MQ (ZeroMQ...)
● Twitter
● ...
● Ou une implémentation custom de Receiver
Démo
Spark Streaming
Démo de Spark Streaming
● Consommation de Tweets #Android
○ Twitter4J
● Détection de la langue du Tweet
○ Language Detection
● Indexation dans Elasticsearch
● Analyse dans Kibana 4
$ curl -X DELETE localhost:9200
$ curl -X PUT localhost:9200/spark/_mapping/tweets '{
"tweets": {
"properties": {
"user": {"type": "string","index": "not_analyzed"},
"text": {"type": "string"},
"createdAt": {"type": "date","format": "date_time"},
"language": {"type": "string","index": "not_analyzed"}
}
}
}'
● Lancer ElasticSearch
Démo
● Lancer Kibana -> http://localhost:5601
● Lancer le traitement
@aseigneurin
aseigneurin.github.io
@ippontech
blog.ippon.fr

Contenu connexe

Tendances

Tendances (20)

Spark RDD : Transformations & Actions
Spark RDD : Transformations & ActionsSpark RDD : Transformations & Actions
Spark RDD : Transformations & Actions
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
 
BigData_Chp4: NOSQL
BigData_Chp4: NOSQLBigData_Chp4: NOSQL
BigData_Chp4: NOSQL
 
Spark introduction and architecture
Spark introduction and architectureSpark introduction and architecture
Spark introduction and architecture
 
Hudi architecture, fundamentals and capabilities
Hudi architecture, fundamentals and capabilitiesHudi architecture, fundamentals and capabilities
Hudi architecture, fundamentals and capabilities
 
PySpark dataframe
PySpark dataframePySpark dataframe
PySpark dataframe
 
What Is RDD In Spark? | Edureka
What Is RDD In Spark? | EdurekaWhat Is RDD In Spark? | Edureka
What Is RDD In Spark? | Edureka
 
Apache Spark Introduction
Apache Spark IntroductionApache Spark Introduction
Apache Spark Introduction
 
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
 
Apache Spark 101
Apache Spark 101Apache Spark 101
Apache Spark 101
 
Introduction to apache spark
Introduction to apache spark Introduction to apache spark
Introduction to apache spark
 
Apache Spark overview
Apache Spark overviewApache Spark overview
Apache Spark overview
 
Koalas: Making an Easy Transition from Pandas to Apache Spark
Koalas: Making an Easy Transition from Pandas to Apache SparkKoalas: Making an Easy Transition from Pandas to Apache Spark
Koalas: Making an Easy Transition from Pandas to Apache Spark
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & Internals
 
BigData_Chp3: Data Processing
BigData_Chp3: Data ProcessingBigData_Chp3: Data Processing
BigData_Chp3: Data Processing
 
Apache Spark Overview
Apache Spark OverviewApache Spark Overview
Apache Spark Overview
 
Le processus ETL (Extraction, Transformation, Chargement)
Le processus ETL (Extraction, Transformation, Chargement)Le processus ETL (Extraction, Transformation, Chargement)
Le processus ETL (Extraction, Transformation, Chargement)
 
Delta lake and the delta architecture
Delta lake and the delta architectureDelta lake and the delta architecture
Delta lake and the delta architecture
 
Chp2 - Les Entrepôts de Données
Chp2 - Les Entrepôts de DonnéesChp2 - Les Entrepôts de Données
Chp2 - Les Entrepôts de Données
 
Les Base de Données NOSQL -Presentation -
Les Base de Données NOSQL -Presentation -Les Base de Données NOSQL -Presentation -
Les Base de Données NOSQL -Presentation -
 

En vedette

Introduction à ElasticSearch
Introduction à ElasticSearchIntroduction à ElasticSearch
Introduction à ElasticSearch
Fadel Chafai
 
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo..."Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
Lucidworks
 

En vedette (20)

Spark (v1.3) - Présentation (Français)
Spark (v1.3) - Présentation (Français)Spark (v1.3) - Présentation (Français)
Spark (v1.3) - Présentation (Français)
 
0712_Seigneurin
0712_Seigneurin0712_Seigneurin
0712_Seigneurin
 
Introduction spark
Introduction sparkIntroduction spark
Introduction spark
 
spark_intro_1208
spark_intro_1208spark_intro_1208
spark_intro_1208
 
Spark - Alexis Seigneurin (English)
Spark - Alexis Seigneurin (English)Spark - Alexis Seigneurin (English)
Spark - Alexis Seigneurin (English)
 
Apache SPARK ML : principes, concepts et mise en œuvre
Apache SPARK  ML : principes, concepts et  mise en œuvre Apache SPARK  ML : principes, concepts et  mise en œuvre
Apache SPARK ML : principes, concepts et mise en œuvre
 
Lessons Learned: Using Spark and Microservices
Lessons Learned: Using Spark and MicroservicesLessons Learned: Using Spark and Microservices
Lessons Learned: Using Spark and Microservices
 
Spark SQL principes et fonctions
Spark SQL principes et fonctionsSpark SQL principes et fonctions
Spark SQL principes et fonctions
 
Lambda architecture et Spark
Lambda architecture et SparkLambda architecture et Spark
Lambda architecture et Spark
 
Spark - Ippevent 19-02-2015
Spark - Ippevent 19-02-2015Spark - Ippevent 19-02-2015
Spark - Ippevent 19-02-2015
 
Interface fonctionnelle, Lambda expression, méthode par défaut, référence de...
Interface fonctionnelle, Lambda expression, méthode par défaut,  référence de...Interface fonctionnelle, Lambda expression, méthode par défaut,  référence de...
Interface fonctionnelle, Lambda expression, méthode par défaut, référence de...
 
Introduction à ElasticSearch
Introduction à ElasticSearchIntroduction à ElasticSearch
Introduction à ElasticSearch
 
Scala: Pattern matching, Concepts and Implementations
Scala: Pattern matching, Concepts and ImplementationsScala: Pattern matching, Concepts and Implementations
Scala: Pattern matching, Concepts and Implementations
 
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo..."Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
"Spark Search" - In-memory, Distributed Search with Lucene, Spark, and Tachyo...
 
Building Realtim Data Pipelines with Kafka Connect and Spark Streaming
Building Realtim Data Pipelines with Kafka Connect and Spark StreamingBuilding Realtim Data Pipelines with Kafka Connect and Spark Streaming
Building Realtim Data Pipelines with Kafka Connect and Spark Streaming
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
Scala : programmation fonctionnelle
Scala : programmation fonctionnelleScala : programmation fonctionnelle
Scala : programmation fonctionnelle
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
I Heart Log: Real-time Data and Apache Kafka
I Heart Log: Real-time Data and Apache KafkaI Heart Log: Real-time Data and Apache Kafka
I Heart Log: Real-time Data and Apache Kafka
 
Build a Recommendation Engine using Amazon Machine Learning in Real-time
Build a Recommendation Engine using Amazon Machine Learning in Real-timeBuild a Recommendation Engine using Amazon Machine Learning in Real-time
Build a Recommendation Engine using Amazon Machine Learning in Real-time
 

Similaire à Spark - Alexis Seigneurin (Français)

Nosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -intro
Nosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -introNosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -intro
Nosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -intro
Olivier Mallassi
 
CHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdf
CHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdfCHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdf
CHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdf
YounesOuladSayad1
 

Similaire à Spark - Alexis Seigneurin (Français) (20)

Nosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -intro
Nosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -introNosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -intro
Nosql, hadoop, map reduce, hbase, sqoop, voldemort, cassandra -intro
 
P8 03 presentation
P8 03 presentationP8 03 presentation
P8 03 presentation
 
Tech day hadoop, Spark
Tech day hadoop, SparkTech day hadoop, Spark
Tech day hadoop, Spark
 
Techday Arrow Group: Hadoop & le Big Data
Techday Arrow Group: Hadoop & le Big DataTechday Arrow Group: Hadoop & le Big Data
Techday Arrow Group: Hadoop & le Big Data
 
10 big data hadoop
10 big data hadoop10 big data hadoop
10 big data hadoop
 
10 big data hadoop
10 big data hadoop10 big data hadoop
10 big data hadoop
 
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017) Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
Spark-adabra, Comment Construire un DATALAKE ! (Devoxx 2017)
 
Introduction Apche Spark
Introduction Apche SparkIntroduction Apche Spark
Introduction Apche Spark
 
Elastic serach
Elastic serachElastic serach
Elastic serach
 
Presentation des outils traitements distribues
Presentation des outils traitements distribuesPresentation des outils traitements distribues
Presentation des outils traitements distribues
 
Hadoop Introduction in Paris
Hadoop Introduction in ParisHadoop Introduction in Paris
Hadoop Introduction in Paris
 
Distributed computing with Spark 2.x
Distributed computing with Spark 2.xDistributed computing with Spark 2.x
Distributed computing with Spark 2.x
 
Big sql4meetup
Big sql4meetupBig sql4meetup
Big sql4meetup
 
5 sw
5 sw5 sw
5 sw
 
CHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdf
CHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdfCHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdf
CHAPITRE3_Fondements_Big_Data_MR_YARN - converted (1).pdf
 
Hands on lab Elasticsearch
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab Elasticsearch
 
PostgreSQL, plus qu'une base de données, une plateforme aux multiples usages
PostgreSQL, plus qu'une base de données, une plateforme aux multiples usagesPostgreSQL, plus qu'une base de données, une plateforme aux multiples usages
PostgreSQL, plus qu'une base de données, une plateforme aux multiples usages
 
mix-it 2011
mix-it 2011mix-it 2011
mix-it 2011
 
Architecture Big Data open source S.M.A.C.K
Architecture Big Data open source S.M.A.C.KArchitecture Big Data open source S.M.A.C.K
Architecture Big Data open source S.M.A.C.K
 
Journées SQL 2014 - Hive ou la convergence entre datawarehouse et Big Data
Journées SQL 2014 - Hive ou la convergence entre datawarehouse et Big DataJournées SQL 2014 - Hive ou la convergence entre datawarehouse et Big Data
Journées SQL 2014 - Hive ou la convergence entre datawarehouse et Big Data
 

Spark - Alexis Seigneurin (Français)

  • 2. Spark ● Traitement de larges volumes de données ● Traitement distribué (commodity hardware) ● Ecrit en Scala, bindings Java et Python
  • 3. Histoire ● 2009 : AMPLab de l'Université de Berkeley ● Juin 2013 : "Top-level project" de la fondation Apache ● Mai 2014 : version 1.0.0 ● Actuellement : version 1.2.0
  • 4. Use cases ● Analyse de logs ● Traitement de fichiers texte ● Analytics ● Recherche distribuée (Google, avant) ● Détection de fraude ● Recommendation (articles, produits...)
  • 5. Proximité avec Hadoop ● Mêmes use cases ● Même modèle de développement : MapReduce ● Intégration dans l'écosystème
  • 6. Plus simple qu’Hadoop ● API plus simple à prendre en main ● Modèle MapReduce "relâché" ● Spark Shell : traitement interactif
  • 7. Plus rapide qu’Hadoop Spark officially sets a new record in large-scale sorting (5 novembre 2014) ● Tri de 100 To de données ● Hadoop MR : 72 minutes ○ Avec 2100 noeuds (50400 cores) ● Spark : 23 minutes ○ Avec 206 noeuds (6592 cores)
  • 8. Écosystème Spark ● Spark ● Spark Shell ● Spark Streaming ● Spark SQL ● Spark ML ● GraphX
  • 9. Intégration ● Yarn, Zookeeper, Mesos ● HDFS ● Cassandra ● Elasticsearch ● MongoDB
  • 11. ● Resilient Distributed Dataset ● Abstraction, collection traitée en parallèle ● Tolérant à la panne ● Manipulation de tuples : ○ Clé - Valeur ○ Tuples indépendants les uns des autres RDD
  • 12. Sources ● Fichier sur HDFS ● Fichier local ● Collection en mémoire ● Amazon S3 ● Base NoSQL ● ... ● Ou une implémentation custom de InputFormat
  • 13. Transformations ● Manipule un RDD, retourne un autre RDD ● Lazy ! ● Exemples : ○ map() : une valeur → une valeur ○ mapToPair() : une valeur → un tuple ○ filter() : filtre les valeurs/tuples ○ groupByKey() : regroupe la valeurs par clés ○ reduceByKey() : aggrège les valeurs par clés ○ join(), cogroup()... : jointure entre deux RDD
  • 14. Actions finales ● Ne retournent pas un RDD ● Exemples : ○ count() : compte les valeurs/tuples ○ saveAsHadoopFile() : sauve les résultats au format Hadoop ○ foreach() : exécute une fonction sur chaque valeur/tuple ○ collect() : récupère les valeurs dans une liste (List<T>)
  • 16. ● Arbres de Paris : fichier CSV en Open Data ● Comptage d’arbres par espèce Spark - Exemple geom_x_y;circonfere;adresse;hauteurenm;espece;varieteouc;dateplanta 48.8648454814, 2.3094155344;140.0;COURS ALBERT 1ER;10.0;Aesculus hippocastanum;; 48.8782668139, 2.29806967519;100.0;PLACE DES TERNES;15.0;Tilia platyphyllos;; 48.889306184, 2.30400164126;38.0;BOULEVARD MALESHERBES;0.0;Platanus x hispanica;; 48.8599934405, 2.29504883623;65.0;QUAI BRANLY;10.0;Paulownia tomentosa;;1996-02-29 ...
  • 17. Spark - Exemple JavaSparkContext sc = new JavaSparkContext("local", "arbres"); sc.textFile("data/arbresalignementparis2010.csv") .filter(line -> !line.startsWith("geom")) .map(line -> line.split(";")) .mapToPair(fields -> new Tuple2<String, Integer>(fields[4], 1)) .reduceByKey((x, y) -> x + y) .sortByKey() .foreach(t -> System.out.println(t._1 + " : " + t._2)); [... ; … ; …] [... ; … ; …] [... ; … ; …] [... ; … ; …] [... ; … ; …] [... ; … ; …] u m k m a a textFile mapToPairmap reduceByKey foreach 1 1 1 1 1 u m k 1 2 1 2a ... ... ... ... filter ... ... sortByKey a m 2 1 2 1u ... ... ... ... ... ... geom;... 1 k
  • 18. Spark - Exemple Acacia dealbata : 2 Acer acerifolius : 39 Acer buergerianum : 14 Acer campestre : 452 ...
  • 20. Topologie & Terminologie ● Un master / des workers ○ (+ un master en standby) ● On soumet une application ● Exécution pilotée par un driver
  • 21. Spark en cluster Plusieurs options ● YARN ● Mesos ● Standalone ○ Workers démarrés individuellement ○ Workers démarrés par le master
  • 22. MapReduce ● Spark (API) ● Traitement distribué ● Tolérant à la panne Stockage ● HDFS, base NoSQL... ● Stockage distribué ● Tolérant à la panne Stockage & traitements
  • 23. Colocation données & traitement ● “Data locality” ● Traiter la donnée là où elle se trouve ● Eviter les network I/Os
  • 24. Colocation données & traitement Spark Worker HDFS Datanode Spark Worker HDFS Datanode Spark Worker HDFS Datanode Spark Master HDFS Namenode HDFS Namenode (Standby) Spark Master (Standby)
  • 26. Démo $ $SPARK_HOME/sbin/start-master.sh $ $SPARK_HOME/bin/spark-class org.apache.spark.deploy.worker.Worker spark://MBP-de-Alexis:7077 --cores 2 --memory 2G $ mvn clean package $ $SPARK_HOME/bin/spark-submit --master spark://MBP-de-Alexis:7077 --class com.seigneurin.spark.WikipediaMapReduceByKey --deploy-mode cluster target/pres-spark-0.0.1-SNAPSHOT.jar
  • 28. ● Exploitation d’un RDD en SQL ● Moteur d’exécution SQL : convertit les requêtes en instructions de base Spark SQL
  • 29. Spark SQL Préalable : ● Disposer de données tabulaires ● Décrire le schéma → SchemaRDD Description de schéma : ● Description programmatique des données ● Inférence de schéma par réflexion (POJO)
  • 30. JavaRDD<Row> rdd = trees.map(fields -> Row.create( Float.parseFloat(fields[3]), fields[4])); ● Création de données tabulaires (type Row) Spark SQL - Exemple --------------------------------------- | 10.0 | Aesculus hippocastanum | | 15.0 | Tilia platyphyllos | | 0.0 | Platanus x hispanica | | 10.0 | Paulownia tomentosa | | ... | ... |
  • 31. Spark SQL - Exemple List<StructField> fields = new ArrayList<StructField>(); fields.add(DataType.createStructField("hauteurenm", DataType.FloatType, false)); fields.add(DataType.createStructField("espece", DataType.StringType, false)); StructType schema = DataType.createStructType(fields); JavaSchemaRDD schemaRDD = sqlContext.applySchema(rdd, schema); schemaRDD.registerTempTable("tree"); --------------------------------------- | hauteurenm | espece | --------------------------------------- | 10.0 | Aesculus hippocastanum | | 15.0 | Tilia platyphyllos | | 0.0 | Platanus x hispanica | | 10.0 | Paulownia tomentosa | | ... | ... | ● Description du schéma
  • 32. ● Comptage d’arbres par espèce Spark SQL - Exemple sqlContext.sql("SELECT espece, COUNT(*) FROM tree WHERE espece <> '' GROUP BY espece ORDER BY espece") .foreach(row -> System.out.println(row.getString(0)+" : "+row.getLong(1))); Acacia dealbata : 2 Acer acerifolius : 39 Acer buergerianum : 14 Acer campestre : 452 ...
  • 34. Micro-batches ● Découpe un flux continu en batches ● API identique ● ≠ Apache Storm
  • 35. DStream ● Discretized Streams ● Séquence de RDDs ● Initialisé avec une Duration
  • 36. Window operations ● Fenêtre glissante ● Réutilise des données d'autres fenêtres ● Initialisé avec window length et slide interval
  • 37. Sources ● Socket ● Kafka ● Flume ● HDFS ● MQ (ZeroMQ...) ● Twitter ● ... ● Ou une implémentation custom de Receiver
  • 39. Démo de Spark Streaming ● Consommation de Tweets #Android ○ Twitter4J ● Détection de la langue du Tweet ○ Language Detection ● Indexation dans Elasticsearch ● Analyse dans Kibana 4
  • 40. $ curl -X DELETE localhost:9200 $ curl -X PUT localhost:9200/spark/_mapping/tweets '{ "tweets": { "properties": { "user": {"type": "string","index": "not_analyzed"}, "text": {"type": "string"}, "createdAt": {"type": "date","format": "date_time"}, "language": {"type": "string","index": "not_analyzed"} } } }' ● Lancer ElasticSearch Démo ● Lancer Kibana -> http://localhost:5601 ● Lancer le traitement