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

BigData_Chp3: Data Processing
BigData_Chp3: Data ProcessingBigData_Chp3: Data Processing
BigData_Chp3: Data ProcessingLilia Sfaxi
 
BigData_Chp5: Putting it all together
BigData_Chp5: Putting it all togetherBigData_Chp5: Putting it all together
BigData_Chp5: Putting it all togetherLilia Sfaxi
 
BigData_Chp4: NOSQL
BigData_Chp4: NOSQLBigData_Chp4: NOSQL
BigData_Chp4: NOSQLLilia Sfaxi
 
PySpark dataframe
PySpark dataframePySpark dataframe
PySpark dataframeJaemun Jung
 
BigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-ReduceBigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-ReduceLilia Sfaxi
 
Productizing Structured Streaming Jobs
Productizing Structured Streaming JobsProductizing Structured Streaming Jobs
Productizing Structured Streaming JobsDatabricks
 
Optimizing Delta/Parquet Data Lakes for Apache Spark
Optimizing Delta/Parquet Data Lakes for Apache SparkOptimizing Delta/Parquet Data Lakes for Apache Spark
Optimizing Delta/Parquet Data Lakes for Apache SparkDatabricks
 
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)Spark Summit
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...Databricks
 
Programming in Spark using PySpark
Programming in Spark using PySpark      Programming in Spark using PySpark
Programming in Spark using PySpark Mostafa
 
PySpark in practice slides
PySpark in practice slidesPySpark in practice slides
PySpark in practice slidesDat Tran
 
Cours Big Data Chap6
Cours Big Data Chap6Cours Big Data Chap6
Cours Big Data Chap6Amal Abid
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 

Tendances (20)

spark_intro_1208
spark_intro_1208spark_intro_1208
spark_intro_1208
 
BigData_Chp3: Data Processing
BigData_Chp3: Data ProcessingBigData_Chp3: Data Processing
BigData_Chp3: Data Processing
 
BigData_Chp5: Putting it all together
BigData_Chp5: Putting it all togetherBigData_Chp5: Putting it all together
BigData_Chp5: Putting it all together
 
BigData_Chp4: NOSQL
BigData_Chp4: NOSQLBigData_Chp4: NOSQL
BigData_Chp4: NOSQL
 
PySpark dataframe
PySpark dataframePySpark dataframe
PySpark dataframe
 
BigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-ReduceBigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-Reduce
 
Productizing Structured Streaming Jobs
Productizing Structured Streaming JobsProductizing Structured Streaming Jobs
Productizing Structured Streaming Jobs
 
Apache Spark Overview
Apache Spark OverviewApache Spark Overview
Apache Spark Overview
 
Optimizing Delta/Parquet Data Lakes for Apache Spark
Optimizing Delta/Parquet Data Lakes for Apache SparkOptimizing Delta/Parquet Data Lakes for Apache Spark
Optimizing Delta/Parquet Data Lakes for Apache Spark
 
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Hadoop Tutorial For Beginners
Hadoop Tutorial For BeginnersHadoop Tutorial For Beginners
Hadoop Tutorial For Beginners
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
 
Programming in Spark using PySpark
Programming in Spark using PySpark      Programming in Spark using PySpark
Programming in Spark using PySpark
 
PySpark in practice slides
PySpark in practice slidesPySpark in practice slides
PySpark in practice slides
 
Cours Big Data Chap6
Cours Big Data Chap6Cours Big Data Chap6
Cours Big Data Chap6
 
Chapitre 3 spark
Chapitre 3 sparkChapitre 3 spark
Chapitre 3 spark
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Chapitre 2 hadoop
Chapitre 2 hadoopChapitre 2 hadoop
Chapitre 2 hadoop
 
introduction à MongoDB
introduction à MongoDBintroduction à MongoDB
introduction à MongoDB
 

En vedette

Spark, ou comment traiter des données à la vitesse de l'éclair
Spark, ou comment traiter des données à la vitesse de l'éclairSpark, ou comment traiter des données à la vitesse de l'éclair
Spark, ou comment traiter des données à la vitesse de l'éclairAlexis Seigneurin
 
Spark - Alexis Seigneurin (English)
Spark - Alexis Seigneurin (English)Spark - Alexis Seigneurin (English)
Spark - Alexis Seigneurin (English)Alexis Seigneurin
 
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 MICHRAFY MUSTAFA
 
Lessons Learned: Using Spark and Microservices
Lessons Learned: Using Spark and MicroservicesLessons Learned: Using Spark and Microservices
Lessons Learned: Using Spark and MicroservicesAlexis Seigneurin
 
Spark SQL principes et fonctions
Spark SQL principes et fonctionsSpark SQL principes et fonctions
Spark SQL principes et fonctionsMICHRAFY MUSTAFA
 
Lambda architecture et Spark
Lambda architecture et SparkLambda architecture et Spark
Lambda architecture et SparkFabien COMTE
 
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...MICHRAFY MUSTAFA
 
Introduction à ElasticSearch
Introduction à ElasticSearchIntroduction à ElasticSearch
Introduction à ElasticSearchFadel Chafai
 
Scala: Pattern matching, Concepts and Implementations
Scala: Pattern matching, Concepts and ImplementationsScala: Pattern matching, Concepts and Implementations
Scala: Pattern matching, Concepts and ImplementationsMICHRAFY MUSTAFA
 
"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
 
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 StreamingGuozhang Wang
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample applicationAntoine Rey
 
Scala : programmation fonctionnelle
Scala : programmation fonctionnelleScala : programmation fonctionnelle
Scala : programmation fonctionnelleMICHRAFY MUSTAFA
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring bootAntoine Rey
 
Spark RDD : Transformations & Actions
Spark RDD : Transformations & ActionsSpark RDD : Transformations & Actions
Spark RDD : Transformations & ActionsMICHRAFY MUSTAFA
 
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 KafkaJay Kreps
 
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-timeAmazon Web Services
 

En vedette (20)

Spark, ou comment traiter des données à la vitesse de l'éclair
Spark, ou comment traiter des données à la vitesse de l'éclairSpark, ou comment traiter des données à la vitesse de l'éclair
Spark, ou comment traiter des données à la vitesse de l'éclair
 
0712_Seigneurin
0712_Seigneurin0712_Seigneurin
0712_Seigneurin
 
Introduction spark
Introduction sparkIntroduction spark
Introduction spark
 
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
 
Spark RDD : Transformations & Actions
Spark RDD : Transformations & ActionsSpark RDD : Transformations & Actions
Spark RDD : Transformations & Actions
 
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 -introOlivier Mallassi
 
P8 03 presentation
P8 03 presentationP8 03 presentation
P8 03 presentationrajiasellami
 
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 DataArrow Group
 
10 big data hadoop
10 big data hadoop10 big data hadoop
10 big data hadoopPatrick Bury
 
10 big data hadoop
10 big data hadoop10 big data hadoop
10 big data hadoopPatrick Bury
 
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) univalence
 
Presentation des outils traitements distribues
Presentation des outils traitements distribuesPresentation des outils traitements distribues
Presentation des outils traitements distribuesLê Anh
 
Hadoop Introduction in Paris
Hadoop Introduction in ParisHadoop Introduction in Paris
Hadoop Introduction in ParisTed Drake
 
Distributed computing with Spark 2.x
Distributed computing with Spark 2.xDistributed computing with Spark 2.x
Distributed computing with Spark 2.xDr Hajji Hicham
 
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).pdfYounesOuladSayad1
 
Hands on lab Elasticsearch
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab ElasticsearchDavid Pilato
 
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 usagesOpen Source Experience
 
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.KJulien Anguenot
 
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 DataDavid Joubert
 

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