SlideShare une entreprise Scribd logo
Introduction aux algorithmes
MapReduce
Mathieu Dumoulin (GRAAL), 14 Février 2014
Plan
 Introduction de la
problématique
 Tutoriel MapReduce
 Design d’algorithmes
MapReduce
 Tri, somme et calcul de
moyenne
 PageRank en MapReduce
 Conclusion
mathieu.dumoulin@gmail.com 2014-02-14
« Big Data »
Building new analytic applications based on new types of data, in
order to better serve your customers and drive a better competitive
advantage
- David McJannet, Hortonworks
Big data is high volume, high velocity, and/or high variety
information assets that require new forms of processing to enable
enhanced decision making, insight discovery and process optimization
- Gartner, updated definition of big data (2012)
mathieu.dumoulin@gmail.com 2014-02-14
Un outil spécialisé
Problèmes où Hadoop est envisageable:
 Trop de données (GB,TB,PB)
 Améliorer des résultats existants
 Obtenir de nouveaux résultats
 Combiner des données hétérogènes
 Croissance rapide (et constante) des données
 Temps de traitement lent (minutes, heures)
 Budgets limités
 Plusieurs ordinateurs déjà disponibles
mathieu.dumoulin@gmail.com 2014-02-14
Hadoop au cœur du big data
mathieu.dumoulin@gmail.com 2014-02-14
MapReduce au cœur de Hadoop
Hadoop MapReduce is a software framework for easily writing
applications which process vast amounts of data (multi-terabyte
data-sets) in-parallel on large clusters (thousands of nodes) of
commodity hardware in a reliable, fault-tolerant manner.
- Hadoop Tutorial, hadoop.apache.org
mathieu.dumoulin@gmail.com 2014-02-14
Gain d’utiliser Hadoop?
 Tout le travail de distribution, balancement de charge,
synchronisation et de gestion d’erreur est géré
automatiquement
 Il suffit de programmer Map et Reduce (Java, C++,
Python, bash, etc.)
 Une grappe Hadoop peut évoluer facilement en ajoutant
des nœuds en tout temps
 Hadoop offre un rapport performance-prix très
compétitif (Amazon EMS, réutilisation de PC existants,
aucun coûts de licences ni de matériel spécialisé HPC)
mathieu.dumoulin@gmail.com 2014-02-14
L’exemple WordCount
On veut trouver les k mots les plus fréquents dans une
collection de textes.
def word_count(text, k):
counts = defaultdict(int)
for word in text.split():
counts[word.lower()] += 1
return sorted(counts, key=counts.get, reverse=True)[:k]
Mais cette solution est-elle la bonne si le texte est très
grand?
Et s’il est très, très, …, très grand?
mathieu.dumoulin@gmail.com 2014-02-14
La taille en soit peut être un problème
Problème SolutionTaille
• 100M mots
• 1000M mots
• 100MM mots
• 1000MM mots
• Plus encore!
• Pas de problèmes
• Mémoire insuffisante
• Processeur insuffisant
• 1 ordinateur insuffisant
• Réseau insuffisant,
contrôleur surchargé
• Naïve avec 1 seul
ordinateur
• Utiliser le disque,
Fenêtre glissante
• Multithreading,
éliminer < N
• Distribuer le calcul
• MapReduce (ou
solution du même
ordre comme MPI,
etc.)
mathieu.dumoulin@gmail.com 2014-02-14
Tutoriel MapReduce
Map Reduce
mathieu.dumoulin@gmail.com 2014-02-14
Map et Reduce: la paire Clef-Valeur
Mapper:
(K,V) → (K’, V’)
Reducer:
(K’, [V’, V’,…]) → (K’’, V’’)
Données
(HDFS)
Données’
(HDFS)
mathieu.dumoulin@gmail.com 2014-02-14
MapReduce en action: WordCount illustré
mathieu.dumoulin@gmail.com 2014-02-14
Map et Reduce: Shuffle and Sort
Source: Data Intensive Text Processing with MapReduce, Jimmy Lin and Chris Dyer, 2010
mathieu.dumoulin@gmail.com 2014-02-14
Map et Reduce (moins simplifié)
 Les vrai opérateurs:
 Mapper
 Combiner
 Partitioner
 Reducer
mathieu.dumoulin@gmail.com 2014-02-14
Design d’algorithmes pour MapReduce
1- Il faut reformuler les algorithmes en fonctionnel:
2- La bande passante du
réseau est une ressource
limitée à optimiser:
mathieu.dumoulin@gmail.com 2014-02-14
Exemples choisis
 Exemples simples:
 Tri
 Somme
 Moyenne
 Un exemple complet:
PageRank
 Bonus:
K-Means (Lloyd’s algorithm)
mathieu.dumoulin@gmail.com 2014-02-14
Trier en MapReduce
 Propriété du réducteur: les paires sont traitée dans
l’ordre (selon la clef), les réducteurs sont aussi dans
l’ordre
Mapper:
Émettre l’élément à trier comme nouvelle clef
Reducer:
Aucun (i.e. fonction identité)
mathieu.dumoulin@gmail.com 2014-02-14
Calcul d’une somme (WordCount)
mathieu.dumoulin@gmail.com 2014-02-14
Amélioration: le combiner
mathieu.dumoulin@gmail.com 2014-02-14
Calcul de moyenne
Utiliser un combiner est il approprié? Si on reprend le reducer comme combiner,
l’algorithme est-il encore correct?mathieu.dumoulin@gmail.com 2014-02-14
Comment améliorer ce calcul?
mathieu.dumoulin@gmail.com 2014-02-14
Design d’une solution MapReduce pour
l’algorithme PageRank
mathieu.dumoulin@gmail.com 2014-02-14
Qu’est-ce que PageRank?
Distribution de probabilité sur les pages web qui
représente la chance qu’un utilisateur naviguant au
hasard arrive à une page web particulière.
Notes:
 Le web est un graphe orienté, une page est un nœud
et les hyperliens sont des arcs.
 L’algorithme recalcule la probabilité de toutes les
pages itérativement jusqu’à convergence
mathieu.dumoulin@gmail.com 2014-02-14
Comment calculer PageRank (simplifié)
𝑃𝑅 𝑝𝑖 =
𝑝 𝑖∈𝑀(𝑝 𝑖)
𝑃𝑅(𝑝𝑗)
𝐿(𝑝𝑗)
• p1,p2,…,pN sont les pages web (les nœuds du
graphe)
• M(pi) est l’ensemble des pages ayant un lien vers pi
• L(pj) est le nombre de liens sortant de la page pj
• N est le nombre total de pages web
Note: Pour simplifier, on élimine le facteur d’atténuation, paramétrisé par
la probabilité que l’utilisateur arrête de naviguer.
Page, Lawrence and Brin, Sergey and Motwani, Rajeev and Winograd, Terry (1999) The
PageRank Citation Ranking: Bringing Order to theWeb. Technical Report. Stanford InfoLab.
mathieu.dumoulin@gmail.com 2014-02-14
PageRank par un exemple
Le web a trois pages web:A, B et C
Initialisation: PR(A) = PR(B) = PR(C) = 0.33
Jusqu’à convergence:
𝑃𝑅 𝐴 =
𝑃𝑅(𝐵)
2
𝑃𝑅 𝐵 =
𝑃𝑅(𝐴)
2
𝑃𝑅 𝐶 =
𝑃𝑅(𝐴)
2
+
𝑃𝑅(𝐵)
2
mathieu.dumoulin@gmail.com 2014-02-14
PageRank en MapReduce
Donnés de départ:
collection de pages web (URL, [URLlien])
1. Bâtir et initialiser le graphe
2. Jusqu’à convergence, recalculer PageRank pour chaque
page web
3. Retourner les K premières valeurs de PageRank (pas
présenté)
mathieu.dumoulin@gmail.com 2014-02-14
Étape 1: Bâtir le graphe
Mapper:
Entrée: une page web
Pour chaque lien de la page, émettre:
clef: URLpage
valeur: URLlien
Reducer:
Entrée:
clef: URLpage
valeurs: [URLlien, …]
Sortie:
clef: URLpage
valeur: «PR;[URLlien]»
mathieu.dumoulin@gmail.com 2014-02-14
Étape 2: calculer PageRank - Map
Mapper:
Entrée:
clef: URLpage
valeur: «PR;[URLlien,…]»
Sortie:
Pour chaque URLlien, émettre:
clef: URLlien
valeur: «URLpage;PR, nb_urllien»
Où: nb_urllien est le compte de URLlien
mathieu.dumoulin@gmail.com 2014-02-14
Étape 2: calculer PageRank - Reduce
Reducer:
Entrée:
clef: URLpage
valeurs: [«URLinverse;PR, nb_urlpage_inverse», …]
Traitement: calculer le PR
Sortie:
clef: URLpage
valeurs: « PR;[URLlien]»
mathieu.dumoulin@gmail.com 2014-02-14
PageRank en MapReduce: Résultats
Notes:
Source: PageRank Calculation using Map Reduce - The Cornell Web Lab (2008)
Résultats obtenus sur une grappe Hadoop de 50 nœuds (Intel Xeon 2.66GHz 16GB ram)
Mon implémentation: https://bitbucket.org/mathieu_dumoulin/pagerank-mr
mathieu.dumoulin@gmail.com 2014-02-14
MapReduce PageRank: Résultats
(8 fois plus de pages que Cornell)
mathieu.dumoulin@gmail.com 2014-02-14
MapReduce PageRank: Résultats
mathieu.dumoulin@gmail.com 2014-02-14
Conclusion (malheureuse)
 MapReduce est une solution puissante au problème de
programmation distribuée
 La plate-forme fait toute la distribution et la gestion des
erreurs
 Le travail de programmation commence par la
formulation d’un algorithme MapReduce
 Ce n’est pas toujours facile
 Trouver et formuler un algorithme performant est relativement
difficile
 Le travail réel de programmation demande une maîtrise (très)
avancée de Java
mathieu.dumoulin@gmail.com 2014-02-14
Conclusion
mathieu.dumoulin@gmail.com 2014-02-14
Conclusion
On n’est pas prisonnier de MapReduce pour utiliser une
grappe Hadoop!
Apache Pig: optimiser les tâches de ETL
Apache Hive: analyser ses données façon SQL
Cascading et Apache Crunch: librairies Java qui simplifient
les opérations difficiles en MapReduce
Apache Mahout: librarie de machine learning qui peut
utiliser une grappe Hadoop « automatiquement »
mathieu.dumoulin@gmail.com 2014-02-14
Questions et commentaires
2014-02-14mathieu.dumoulin@gmail.com
Hadoop est de plus en plus une composante
d’infrastructure « standard » pour le traitement de
donnée à grande échelle et est promis à un bel avenir!
Partie Bonus
2014-02-14mathieu.dumoulin@gmail.com
 MapReduce et Machine Learning
 Exemple
 Algorithme K-Means
Map et Reduce et le machine learning?
Problématique exemple: recherche de paramètres optimaux
Yasser Ganjisaffar,Thomas Debeauvais, Sara Javanmardi, Rich Caruana, and CristinaVideira Lopes. 2011. Distributed tuning of
machine learning algorithms using MapReduce Clusters. In Proceedings of theThirdWorkshop on Large Scale Data Mining:Theory and
Applications(LDMTA '11).ACM, NewYork, NY, USA, ,Article 2 , 8 pages. DOI=10.1145/2002945.2002947
http://doi.acm.org/10.1145/2002945.2002947
mathieu.dumoulin@gmail.com 2014-02-14
Bonus:
Algorithme K-means clustering
 Problème: regrouper des données en K groupes
mathieu.dumoulin@gmail.com 2014-02-14
Algorithme K-means
(Lloyd’s Algorithm)
Initialiser les K centroïdes (d’une certaine façon)
Pour chacune de plusieurs d’itérations:
Pour chaque point:
Assigner au centroïde le plus proche
Selon une mesure de distance (ex: distance Euclidienne)
Pour chaque centroïde:
Recalculer sa position en faisant la moyenne
des membres de son groupe
mathieu.dumoulin@gmail.com 2014-02-14
K-means en MapReduce
 Driver: lancer les itérations
 Combien d’étapes map-reduce?
Une seule!
mathieu.dumoulin@gmail.com 2014-02-14
K-means MapReduce
 Driver: le “main” qui lance les tâches (Job) MapReduce et qui
itère jusqu’à convergence
 Mapper:Assigner chaque point au cluster le plus proche (en
parallèle!)
 Entrée: Key: Null value: vecteur
 Sortie: Key: index du centroïde le plus proche, value: vecteur
 Reducer: Calculer la moyenne des points membre du cluster
(en parallèle!)
 Key:
 Information partagée: les vecteurs des centroïdes
mathieu.dumoulin@gmail.com 2014-02-14
K-Means et MapReduce: État de l’art
Bahman Bahmani, Benjamin Moseley,AndreaVattani, Ravi
Kumar, and SergeiVassilvitskii. 2012. Scalable k-
means++. Proc.VLDB Endow. 5, 7 (March 2012), 622-633.
http://theory.stanford.edu/~sergei/papers/vldb12-kmpar.pdf
Implémenté dans la librairie Apache Mahout
mathieu.dumoulin@gmail.com 2014-02-14

Contenu connexe

PPTX
MapReduce: Traitement de données distribué à grande échelle simplifié
PPTX
Introduction à Hadoop
PDF
Hadoop Introduction in Paris
PDF
Hadoop MapReduce - OSDC FR 2009
PPTX
Hadoop et son écosystème
PDF
Big Data : Une Introduction
PPTX
Petit-déjeuner MapReduce-La révolution dans l’analyse des BigData
PPTX
Presentation Hadoop Québec
MapReduce: Traitement de données distribué à grande échelle simplifié
Introduction à Hadoop
Hadoop Introduction in Paris
Hadoop MapReduce - OSDC FR 2009
Hadoop et son écosystème
Big Data : Une Introduction
Petit-déjeuner MapReduce-La révolution dans l’analyse des BigData
Presentation Hadoop Québec

Tendances (20)

PPTX
Présentation Map reduce altnetfr
PPTX
Casablanca Hadoop & Big Data Meetup - Introduction à Hadoop
PDF
HADOOP + R
PPTX
Big Data: Hadoop Map / Reduce sur Windows et Windows Azure
PDF
Cartographie du big data
PPTX
Stats web avec Hive chez Scoop.it
PPTX
Présentation Big Data et REX Hadoop
PDF
Softshake 2013 - Yarn dans la vraie vie, retour d'expérience et bonnes pratiq...
PDF
BigData_Chp2: Hadoop & Map-Reduce
PDF
Plateforme bigdata orientée BI avec Hortoworks Data Platform et Apache Spark
PDF
Hadoop and friends : introduction
PDF
Tech day hadoop, Spark
PDF
BigData_Chp5: Putting it all together
PPTX
USI 2013 : 7 changements nécessaires pour sauver vos SI décisionnels
PPTX
HUG France - 20160114 industrialisation_process_big_data CanalPlus
PDF
Big Data, Hadoop & Spark
PDF
Hadoop Hbase - Introduction
PDF
BigData_TP1: Initiation à Hadoop et Map-Reduce
PPTX
Les technologies big data avec speech commentaries
Présentation Map reduce altnetfr
Casablanca Hadoop & Big Data Meetup - Introduction à Hadoop
HADOOP + R
Big Data: Hadoop Map / Reduce sur Windows et Windows Azure
Cartographie du big data
Stats web avec Hive chez Scoop.it
Présentation Big Data et REX Hadoop
Softshake 2013 - Yarn dans la vraie vie, retour d'expérience et bonnes pratiq...
BigData_Chp2: Hadoop & Map-Reduce
Plateforme bigdata orientée BI avec Hortoworks Data Platform et Apache Spark
Hadoop and friends : introduction
Tech day hadoop, Spark
BigData_Chp5: Putting it all together
USI 2013 : 7 changements nécessaires pour sauver vos SI décisionnels
HUG France - 20160114 industrialisation_process_big_data CanalPlus
Big Data, Hadoop & Spark
Hadoop Hbase - Introduction
BigData_TP1: Initiation à Hadoop et Map-Reduce
Les technologies big data avec speech commentaries
Publicité

En vedette (20)

PPTX
MapReduce au Niveau RP*
KEY
Flexible In-Situ Indexing for Hadoop via Elephant Twin
PDF
Integrating Hadoop Into the Enterprise – Hadoop Summit 2012
PDF
IBM Big Data Analytics Concepts and Use Cases
PDF
BigData_TP2: Design Patterns dans Hadoop
PPTX
Intro to Apache Mahout
PDF
BigData_TP3 : Spark
PDF
BigData_Chp3: Data Processing
PDF
Big Data: Introducing BigInsights, IBM's Hadoop- and Spark-based analytical p...
PDF
BigData_Chp1: Introduction à la Big Data
PDF
Overview - IBM Big Data Platform
PDF
Big Data & Analytics Architecture
PDF
IBM Watson Analytics Presentation
PDF
Big Data: SQL on Hadoop from IBM
PPTX
Fr les lunnettesgema
PPTX
Frengjisht pr i gatimit
PPTX
Cm6.08 part3 protection_innovation_benoit_tech
PDF
Frances ufpe 2013
PDF
Decret pétards
PDF
Offre Eventeam Tournoi des 6 nations 2013 : France - Ecosse
MapReduce au Niveau RP*
Flexible In-Situ Indexing for Hadoop via Elephant Twin
Integrating Hadoop Into the Enterprise – Hadoop Summit 2012
IBM Big Data Analytics Concepts and Use Cases
BigData_TP2: Design Patterns dans Hadoop
Intro to Apache Mahout
BigData_TP3 : Spark
BigData_Chp3: Data Processing
Big Data: Introducing BigInsights, IBM's Hadoop- and Spark-based analytical p...
BigData_Chp1: Introduction à la Big Data
Overview - IBM Big Data Platform
Big Data & Analytics Architecture
IBM Watson Analytics Presentation
Big Data: SQL on Hadoop from IBM
Fr les lunnettesgema
Frengjisht pr i gatimit
Cm6.08 part3 protection_innovation_benoit_tech
Frances ufpe 2013
Decret pétards
Offre Eventeam Tournoi des 6 nations 2013 : France - Ecosse
Publicité

Similaire à Introduction aux algorithmes map reduce (20)

PDF
Presentation Map Reduce
PPTX
Spad big data - sfds - 2016
PDF
598262625-Presentation-D-HADOooooooOP.pdf
PPT
Parallélisation d'algorithmes de graphes avec MapReduce sur un cluster d'ordi...
PDF
Bluestone - Panorama des solutions analytiques existantes
PDF
Prometheus & Grafana - Probing and Alerting
PDF
Looker Studio - trucs et astuces pour améliorer ses dashboards
PPTX
PDF
D’un modèle d'IA dans un notebook à un service temps réel : architecturons !
PDF
Techday Arrow Group: Hadoop & le Big Data
PDF
OWF12/BIG DATA OWF OpenSearchServer light
PPTX
Quel hadoop (#quelhadoop)
PPTX
La classification des Emails utilisant le modèle MapReduce
PDF
Construire un data lake managé - GDG Paris - Juin 2019
PDF
P8 03 presentation
DOC
PDF
Offrir de l'analytique en temps réel en un clic
PPTX
2014 03-26-appdevseries-session3-interactingwiththedatabase-fr-phpapp01
PDF
Stratégies d’optimisation de requêtes SQL dans un écosystème Hadoop
PDF
Bases de Données non relationnelles, NoSQL (Introduction) 1er cours
Presentation Map Reduce
Spad big data - sfds - 2016
598262625-Presentation-D-HADOooooooOP.pdf
Parallélisation d'algorithmes de graphes avec MapReduce sur un cluster d'ordi...
Bluestone - Panorama des solutions analytiques existantes
Prometheus & Grafana - Probing and Alerting
Looker Studio - trucs et astuces pour améliorer ses dashboards
D’un modèle d'IA dans un notebook à un service temps réel : architecturons !
Techday Arrow Group: Hadoop & le Big Data
OWF12/BIG DATA OWF OpenSearchServer light
Quel hadoop (#quelhadoop)
La classification des Emails utilisant le modèle MapReduce
Construire un data lake managé - GDG Paris - Juin 2019
P8 03 presentation
Offrir de l'analytique en temps réel en un clic
2014 03-26-appdevseries-session3-interactingwiththedatabase-fr-phpapp01
Stratégies d’optimisation de requêtes SQL dans un écosystème Hadoop
Bases de Données non relationnelles, NoSQL (Introduction) 1er cours

Plus de Mathieu Dumoulin (8)

PPTX
Converged and Containerized Distributed Deep Learning With TensorFlow and Kub...
PPTX
State of the Art Robot Predictive Maintenance with Real-time Sensor Data
PPTX
MapR and Machine Learning Primer
PPTX
CEP - simplified streaming architecture - Strata Singapore 2016
PDF
Streaming Architecture to Connect Everything (Including Hybrid Cloud) - Strat...
PDF
Real-World Machine Learning - Leverage the Features of MapR Converged Data Pl...
PDF
Distributed Deep Learning on Spark
PDF
Real world machine learning with Java for Fumankaitori.com
Converged and Containerized Distributed Deep Learning With TensorFlow and Kub...
State of the Art Robot Predictive Maintenance with Real-time Sensor Data
MapR and Machine Learning Primer
CEP - simplified streaming architecture - Strata Singapore 2016
Streaming Architecture to Connect Everything (Including Hybrid Cloud) - Strat...
Real-World Machine Learning - Leverage the Features of MapR Converged Data Pl...
Distributed Deep Learning on Spark
Real world machine learning with Java for Fumankaitori.com

Introduction aux algorithmes map reduce

  • 1. Introduction aux algorithmes MapReduce Mathieu Dumoulin (GRAAL), 14 Février 2014
  • 2. Plan  Introduction de la problématique  Tutoriel MapReduce  Design d’algorithmes MapReduce  Tri, somme et calcul de moyenne  PageRank en MapReduce  Conclusion mathieu.dumoulin@gmail.com 2014-02-14
  • 3. « Big Data » Building new analytic applications based on new types of data, in order to better serve your customers and drive a better competitive advantage - David McJannet, Hortonworks Big data is high volume, high velocity, and/or high variety information assets that require new forms of processing to enable enhanced decision making, insight discovery and process optimization - Gartner, updated definition of big data (2012) mathieu.dumoulin@gmail.com 2014-02-14
  • 4. Un outil spécialisé Problèmes où Hadoop est envisageable:  Trop de données (GB,TB,PB)  Améliorer des résultats existants  Obtenir de nouveaux résultats  Combiner des données hétérogènes  Croissance rapide (et constante) des données  Temps de traitement lent (minutes, heures)  Budgets limités  Plusieurs ordinateurs déjà disponibles mathieu.dumoulin@gmail.com 2014-02-14
  • 5. Hadoop au cœur du big data mathieu.dumoulin@gmail.com 2014-02-14
  • 6. MapReduce au cœur de Hadoop Hadoop MapReduce is a software framework for easily writing applications which process vast amounts of data (multi-terabyte data-sets) in-parallel on large clusters (thousands of nodes) of commodity hardware in a reliable, fault-tolerant manner. - Hadoop Tutorial, hadoop.apache.org mathieu.dumoulin@gmail.com 2014-02-14
  • 7. Gain d’utiliser Hadoop?  Tout le travail de distribution, balancement de charge, synchronisation et de gestion d’erreur est géré automatiquement  Il suffit de programmer Map et Reduce (Java, C++, Python, bash, etc.)  Une grappe Hadoop peut évoluer facilement en ajoutant des nœuds en tout temps  Hadoop offre un rapport performance-prix très compétitif (Amazon EMS, réutilisation de PC existants, aucun coûts de licences ni de matériel spécialisé HPC) mathieu.dumoulin@gmail.com 2014-02-14
  • 8. L’exemple WordCount On veut trouver les k mots les plus fréquents dans une collection de textes. def word_count(text, k): counts = defaultdict(int) for word in text.split(): counts[word.lower()] += 1 return sorted(counts, key=counts.get, reverse=True)[:k] Mais cette solution est-elle la bonne si le texte est très grand? Et s’il est très, très, …, très grand? mathieu.dumoulin@gmail.com 2014-02-14
  • 9. La taille en soit peut être un problème Problème SolutionTaille • 100M mots • 1000M mots • 100MM mots • 1000MM mots • Plus encore! • Pas de problèmes • Mémoire insuffisante • Processeur insuffisant • 1 ordinateur insuffisant • Réseau insuffisant, contrôleur surchargé • Naïve avec 1 seul ordinateur • Utiliser le disque, Fenêtre glissante • Multithreading, éliminer < N • Distribuer le calcul • MapReduce (ou solution du même ordre comme MPI, etc.) mathieu.dumoulin@gmail.com 2014-02-14
  • 11. Map et Reduce: la paire Clef-Valeur Mapper: (K,V) → (K’, V’) Reducer: (K’, [V’, V’,…]) → (K’’, V’’) Données (HDFS) Données’ (HDFS) mathieu.dumoulin@gmail.com 2014-02-14
  • 12. MapReduce en action: WordCount illustré mathieu.dumoulin@gmail.com 2014-02-14
  • 13. Map et Reduce: Shuffle and Sort Source: Data Intensive Text Processing with MapReduce, Jimmy Lin and Chris Dyer, 2010 mathieu.dumoulin@gmail.com 2014-02-14
  • 14. Map et Reduce (moins simplifié)  Les vrai opérateurs:  Mapper  Combiner  Partitioner  Reducer mathieu.dumoulin@gmail.com 2014-02-14
  • 15. Design d’algorithmes pour MapReduce 1- Il faut reformuler les algorithmes en fonctionnel: 2- La bande passante du réseau est une ressource limitée à optimiser: mathieu.dumoulin@gmail.com 2014-02-14
  • 16. Exemples choisis  Exemples simples:  Tri  Somme  Moyenne  Un exemple complet: PageRank  Bonus: K-Means (Lloyd’s algorithm) mathieu.dumoulin@gmail.com 2014-02-14
  • 17. Trier en MapReduce  Propriété du réducteur: les paires sont traitée dans l’ordre (selon la clef), les réducteurs sont aussi dans l’ordre Mapper: Émettre l’élément à trier comme nouvelle clef Reducer: Aucun (i.e. fonction identité) mathieu.dumoulin@gmail.com 2014-02-14
  • 18. Calcul d’une somme (WordCount) mathieu.dumoulin@gmail.com 2014-02-14
  • 20. Calcul de moyenne Utiliser un combiner est il approprié? Si on reprend le reducer comme combiner, l’algorithme est-il encore correct?mathieu.dumoulin@gmail.com 2014-02-14
  • 21. Comment améliorer ce calcul? mathieu.dumoulin@gmail.com 2014-02-14
  • 22. Design d’une solution MapReduce pour l’algorithme PageRank mathieu.dumoulin@gmail.com 2014-02-14
  • 23. Qu’est-ce que PageRank? Distribution de probabilité sur les pages web qui représente la chance qu’un utilisateur naviguant au hasard arrive à une page web particulière. Notes:  Le web est un graphe orienté, une page est un nœud et les hyperliens sont des arcs.  L’algorithme recalcule la probabilité de toutes les pages itérativement jusqu’à convergence mathieu.dumoulin@gmail.com 2014-02-14
  • 24. Comment calculer PageRank (simplifié) 𝑃𝑅 𝑝𝑖 = 𝑝 𝑖∈𝑀(𝑝 𝑖) 𝑃𝑅(𝑝𝑗) 𝐿(𝑝𝑗) • p1,p2,…,pN sont les pages web (les nœuds du graphe) • M(pi) est l’ensemble des pages ayant un lien vers pi • L(pj) est le nombre de liens sortant de la page pj • N est le nombre total de pages web Note: Pour simplifier, on élimine le facteur d’atténuation, paramétrisé par la probabilité que l’utilisateur arrête de naviguer. Page, Lawrence and Brin, Sergey and Motwani, Rajeev and Winograd, Terry (1999) The PageRank Citation Ranking: Bringing Order to theWeb. Technical Report. Stanford InfoLab. mathieu.dumoulin@gmail.com 2014-02-14
  • 25. PageRank par un exemple Le web a trois pages web:A, B et C Initialisation: PR(A) = PR(B) = PR(C) = 0.33 Jusqu’à convergence: 𝑃𝑅 𝐴 = 𝑃𝑅(𝐵) 2 𝑃𝑅 𝐵 = 𝑃𝑅(𝐴) 2 𝑃𝑅 𝐶 = 𝑃𝑅(𝐴) 2 + 𝑃𝑅(𝐵) 2 mathieu.dumoulin@gmail.com 2014-02-14
  • 26. PageRank en MapReduce Donnés de départ: collection de pages web (URL, [URLlien]) 1. Bâtir et initialiser le graphe 2. Jusqu’à convergence, recalculer PageRank pour chaque page web 3. Retourner les K premières valeurs de PageRank (pas présenté) mathieu.dumoulin@gmail.com 2014-02-14
  • 27. Étape 1: Bâtir le graphe Mapper: Entrée: une page web Pour chaque lien de la page, émettre: clef: URLpage valeur: URLlien Reducer: Entrée: clef: URLpage valeurs: [URLlien, …] Sortie: clef: URLpage valeur: «PR;[URLlien]» mathieu.dumoulin@gmail.com 2014-02-14
  • 28. Étape 2: calculer PageRank - Map Mapper: Entrée: clef: URLpage valeur: «PR;[URLlien,…]» Sortie: Pour chaque URLlien, émettre: clef: URLlien valeur: «URLpage;PR, nb_urllien» Où: nb_urllien est le compte de URLlien mathieu.dumoulin@gmail.com 2014-02-14
  • 29. Étape 2: calculer PageRank - Reduce Reducer: Entrée: clef: URLpage valeurs: [«URLinverse;PR, nb_urlpage_inverse», …] Traitement: calculer le PR Sortie: clef: URLpage valeurs: « PR;[URLlien]» mathieu.dumoulin@gmail.com 2014-02-14
  • 30. PageRank en MapReduce: Résultats Notes: Source: PageRank Calculation using Map Reduce - The Cornell Web Lab (2008) Résultats obtenus sur une grappe Hadoop de 50 nœuds (Intel Xeon 2.66GHz 16GB ram) Mon implémentation: https://bitbucket.org/mathieu_dumoulin/pagerank-mr mathieu.dumoulin@gmail.com 2014-02-14
  • 31. MapReduce PageRank: Résultats (8 fois plus de pages que Cornell) mathieu.dumoulin@gmail.com 2014-02-14
  • 33. Conclusion (malheureuse)  MapReduce est une solution puissante au problème de programmation distribuée  La plate-forme fait toute la distribution et la gestion des erreurs  Le travail de programmation commence par la formulation d’un algorithme MapReduce  Ce n’est pas toujours facile  Trouver et formuler un algorithme performant est relativement difficile  Le travail réel de programmation demande une maîtrise (très) avancée de Java mathieu.dumoulin@gmail.com 2014-02-14
  • 35. Conclusion On n’est pas prisonnier de MapReduce pour utiliser une grappe Hadoop! Apache Pig: optimiser les tâches de ETL Apache Hive: analyser ses données façon SQL Cascading et Apache Crunch: librairies Java qui simplifient les opérations difficiles en MapReduce Apache Mahout: librarie de machine learning qui peut utiliser une grappe Hadoop « automatiquement » mathieu.dumoulin@gmail.com 2014-02-14
  • 36. Questions et commentaires 2014-02-14mathieu.dumoulin@gmail.com Hadoop est de plus en plus une composante d’infrastructure « standard » pour le traitement de donnée à grande échelle et est promis à un bel avenir!
  • 37. Partie Bonus 2014-02-14mathieu.dumoulin@gmail.com  MapReduce et Machine Learning  Exemple  Algorithme K-Means
  • 38. Map et Reduce et le machine learning? Problématique exemple: recherche de paramètres optimaux Yasser Ganjisaffar,Thomas Debeauvais, Sara Javanmardi, Rich Caruana, and CristinaVideira Lopes. 2011. Distributed tuning of machine learning algorithms using MapReduce Clusters. In Proceedings of theThirdWorkshop on Large Scale Data Mining:Theory and Applications(LDMTA '11).ACM, NewYork, NY, USA, ,Article 2 , 8 pages. DOI=10.1145/2002945.2002947 http://doi.acm.org/10.1145/2002945.2002947 mathieu.dumoulin@gmail.com 2014-02-14
  • 39. Bonus: Algorithme K-means clustering  Problème: regrouper des données en K groupes mathieu.dumoulin@gmail.com 2014-02-14
  • 40. Algorithme K-means (Lloyd’s Algorithm) Initialiser les K centroïdes (d’une certaine façon) Pour chacune de plusieurs d’itérations: Pour chaque point: Assigner au centroïde le plus proche Selon une mesure de distance (ex: distance Euclidienne) Pour chaque centroïde: Recalculer sa position en faisant la moyenne des membres de son groupe mathieu.dumoulin@gmail.com 2014-02-14
  • 41. K-means en MapReduce  Driver: lancer les itérations  Combien d’étapes map-reduce? Une seule! mathieu.dumoulin@gmail.com 2014-02-14
  • 42. K-means MapReduce  Driver: le “main” qui lance les tâches (Job) MapReduce et qui itère jusqu’à convergence  Mapper:Assigner chaque point au cluster le plus proche (en parallèle!)  Entrée: Key: Null value: vecteur  Sortie: Key: index du centroïde le plus proche, value: vecteur  Reducer: Calculer la moyenne des points membre du cluster (en parallèle!)  Key:  Information partagée: les vecteurs des centroïdes mathieu.dumoulin@gmail.com 2014-02-14
  • 43. K-Means et MapReduce: État de l’art Bahman Bahmani, Benjamin Moseley,AndreaVattani, Ravi Kumar, and SergeiVassilvitskii. 2012. Scalable k- means++. Proc.VLDB Endow. 5, 7 (March 2012), 622-633. http://theory.stanford.edu/~sergei/papers/vldb12-kmpar.pdf Implémenté dans la librairie Apache Mahout mathieu.dumoulin@gmail.com 2014-02-14