Download - Introduction spark
![Page 1: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/1.jpg)
Introduction à!
Nantes - 08/07/2014!Ludwine Probst - @nivdul
![Page 2: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/2.jpg)
développeuse!maths lover!
machine learning & big data
Leadeuse de Duchess France
@nivdulnivdul.wordpress.com
![Page 3: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/3.jpg)
Etat des lieux
![Page 4: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/4.jpg)
Mais…
![Page 5: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/5.jpg)
![Page 6: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/6.jpg)
• analytics pour de gros datasets et données en mémoire!
• Resilient Distributed Datasets (RDD)!
• principe de lineage!
• compatible avec Hadoop / InputFormats!
• meilleures performances que Hadoop!
• plus de flexibilité d’implémentation
![Page 7: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/7.jpg)
Interrogation de Spark
shell scala/python!supporte les lambdas expressions (Java8)
compatible avec NumPy
![Page 8: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/8.jpg)
Vue globale
todo schéma
![Page 9: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/9.jpg)
SparkContext
SparkConf sparkConf = new SparkConf() .setAppName("SimpleExample") .setMaster("local"); ! //.setMaster(« spark://192.168.1.11:7077") !!JavaSparkContext sc = new JavaSparkContext(sparkConf);
![Page 10: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/10.jpg)
Resilient Distributed Datasets (RDD)
• créé au démarrage!
• traitement en parallèle possible / partitionnement sur les différents noeuds du cluster!
• opérations sur les RDDs = transformations + actions!
• contrôle sur la persistance : MEMORY, DISK…!
• resistance à la panne (principe de lineage avec le DAG)
Définition : collections distribuées fault-tolerant et ! immutable
![Page 11: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/11.jpg)
Créer un RDD
// sc est le SparkContext !// à partir d’un fichier texte JavaRDD<String[]> lines = sc.textFile("ensemble-des-equipements-sportifs-de-lile-de-france.csv"); !// à partir d’un fichier venant d’Hadoop sc.hadoopFile(path, inputFormatClass, keyClass, valueClass); !
![Page 12: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/12.jpg)
Opérations sur les RDDsJavaRDD<String[]> lines = sc.textFile("ensemble-des-equipements- sportifs-de-lile-de-france.csv") .map(line -> line.split(";")) // suppression de la 1ère ligne .filter(line -> !line[1].equals("ins_com")); !lines.count(); !// nombre par type d'équipement rangé par ordre alphabétique lines.mapToPair(line -> new Tuple2<>(line[3], 1)) .reduceByKey((x, y) -> x + y) .sortByKey() .foreach(t -> System.out.println(t._1 + " -> " + t._2)); !
![Page 13: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/13.jpg)
Persistance des RDDs
// lines est un RDD !// persistance par défaut MEMORY_ONLY lines.cache(); !// spécifié lines.persist(StorageLevel.DISK_ONLY()); lines.persist(StorageLevel.MEMORY_ONLY()); lines.persist(StorageLevel.MEMORY_AND_DISK()); !// avec réplication lines.persist(StorageLevel.apply(1, 3));
*Spark est fault-tolerant grâce au graphe d’exécution qui enregistre la suite des opérations effectuées sur un RDD
![Page 14: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/14.jpg)
Côté performances
![Page 15: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/15.jpg)
Ecosystème Spark
Streaming
![Page 16: Introduction spark](https://reader031.vdocument.in/reader031/viewer/2022021918/58ae890c1a28abdf068b4cf9/html5/thumbnails/16.jpg)