Recap: Map-Reduce Map Phase Reduce Phase (per record - - PowerPoint PPT Presentation

recap map reduce
SMART_READER_LITE
LIVE PREVIEW

Recap: Map-Reduce Map Phase Reduce Phase (per record - - PowerPoint PPT Presentation

Map Reduce (contd.) CompSci 590.03 Instructor: Ashwin Machanavajjhala Lecture 12 : 590.02 Spring 13 1 Recap: Map-Reduce Map Phase Reduce Phase


slide-1
SLIDE 1

Map ¡Reduce ¡(contd.) ¡

CompSci ¡590.03 ¡ Instructor: ¡Ashwin ¡Machanavajjhala ¡

1 ¡ Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡

slide-2
SLIDE 2

Recap: ¡Map-­‑Reduce ¡

¡ ¡

¡

Map ¡Phase ¡ (per ¡record ¡computaAon) ¡ Reduce ¡Phase ¡ (global ¡computaAon) ¡ Shuffle ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 2 ¡

slide-3
SLIDE 3

This ¡Class ¡

  • High ¡Level ¡Languages ¡for ¡Map ¡Reduce ¡
  • Join ¡Processing ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 3 ¡

slide-4
SLIDE 4

HIGH ¡LEVEL ¡LANGUAGES ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 4 ¡

slide-5
SLIDE 5

Word ¡Count ¡in ¡Pig ¡

Load ¡A ¡= ¡‘documents’ ¡USING ¡PigStorage(‘\t’) ¡AS ¡(id, ¡docstring) ¡

// ¡load ¡the ¡data ¡using ¡a ¡built ¡in ¡loader ¡assuming ¡data ¡is ¡(id, ¡document ¡string) ¡ delimited ¡by ¡tabs ¡

¡ B ¡= ¡FOREACH ¡A ¡GENERATE ¡FLATTEN(Tokenize(docstring)) ¡AS ¡word ¡

// ¡Mapper ¡UDF ¡Tokenize ¡generates ¡a ¡set ¡of ¡words ¡ // ¡FLATTEN: ¡flaQens ¡a ¡set ¡into ¡mulRple ¡records. ¡ ¡

C ¡= ¡GROUP ¡B ¡BY ¡word ¡

// ¡groups ¡the ¡data ¡by ¡word ¡

D ¡= ¡FOREACH ¡C ¡GENERATE ¡group, ¡COUNT(B) ¡

// ¡Built ¡in ¡reduce ¡funcRon ¡counts ¡the ¡number ¡of ¡Rmes ¡each ¡word ¡appears ¡in ¡B ¡

STORE ¡D ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 5 ¡

slide-6
SLIDE 6

GROUP ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 6 ¡

slide-7
SLIDE 7

Pig ¡UDFs ¡

  • All ¡user ¡defined ¡funcAons ¡are ¡wriben ¡in ¡java. ¡
  • See ¡hbp://wiki.apache.org/pig/UDFManual ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 7 ¡

slide-8
SLIDE 8

Algebraic ¡UDFs ¡

  • Aggregate ¡funcAons ¡take ¡a ¡bag ¡and ¡return ¡a ¡scalar ¡value ¡
  • Some ¡aggregate ¡funcAons ¡(e.g., ¡associaAve ¡and ¡commutaAve ¡
  • peraAons) ¡can ¡be ¡computed ¡incrementally ¡in ¡a ¡distributed ¡
  • fashion. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 8 ¡

slide-9
SLIDE 9

Other ¡funcAons ¡

  • COGROUP ¡ ¡// ¡group ¡mulAple ¡tables ¡on ¡the ¡same ¡value ¡
  • FILTER ¡

¡// ¡discard ¡records ¡that ¡do ¡not ¡saAsfy ¡some ¡property ¡

  • UNION

¡// ¡union ¡of ¡two ¡tables ¡

  • SAMPLE

¡// ¡randomly ¡sample ¡each ¡record ¡with ¡probability ¡p ¡

  • DISTINCT ¡ ¡// ¡remove ¡duplicates ¡
  • LIMIT

¡// ¡return ¡a ¡subset ¡of ¡n ¡(not ¡random) ¡ ¡

  • See ¡hbp://pig.apache.org/docs/r0.7.0/piglaAn_ref2.html ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 9 ¡

slide-10
SLIDE 10

COGROUP ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 10 ¡

slide-11
SLIDE 11

JOIN ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 11 ¡

slide-12
SLIDE 12

JOIN ¡PROCESSING ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 12 ¡

slide-13
SLIDE 13

JOINs ¡

  • A ¡= ¡JOIN ¡B ¡BY ¡fieldB, ¡C ¡BY ¡fieldC ¡PARALLEL ¡20 ¡

– Specify ¡the ¡number ¡of ¡reduce ¡tasks ¡

  • A ¡= ¡JOIN ¡B ¡BY ¡fieldB, ¡C ¡BY ¡fieldC ¡USING ¡‘replicated’ ¡ ¡

– Can ¡ask ¡the ¡system ¡to ¡use ¡one ¡of ¡three ¡ways ¡to ¡do ¡join. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 13 ¡

slide-14
SLIDE 14

Join ¡Types ¡

Fragment ¡Replicated ¡Join: ¡ ¡

  • When ¡one ¡of ¡the ¡tables ¡is ¡small ¡enough ¡to ¡fit ¡in ¡memory. ¡
  • Replicate ¡the ¡“small” ¡table ¡to ¡all ¡mappers ¡containing ¡the ¡other ¡

“large” ¡table. ¡ ¡ Skewed ¡Join: ¡

  • When ¡one ¡of ¡the ¡join ¡abributes ¡is ¡very ¡skewed. ¡ ¡
  • Keys ¡with ¡large ¡number ¡of ¡keys ¡are ¡split ¡into ¡mulAple ¡reducers. ¡

Merge ¡Join: ¡

  • When ¡two ¡datasets ¡are ¡already ¡sorted ¡on ¡the ¡join ¡key ¡
  • Use ¡sort ¡merge ¡join. ¡ ¡

¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 14 ¡

slide-15
SLIDE 15

Join ¡as ¡an ¡OpAmizaAon ¡Problem ¡

  • ObjecAve: ¡minimize ¡job ¡compleAon ¡Ame ¡
  • Cost ¡at ¡a ¡reducer: ¡ ¡

¡

  • Input-­‑size ¡dominated: ¡Reducer ¡input ¡processing ¡Ame ¡is ¡large ¡
  • Output-­‑size ¡dominated: ¡Reducer ¡output ¡processing ¡Ame ¡is ¡large ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 15 ¡

slide-16
SLIDE 16

Join-­‑Matrix ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 16 ¡

Mij ¡= ¡pair ¡of ¡tuples ¡that ¡have ¡S.key ¡= ¡i ¡and ¡T.key ¡= ¡j ¡ Mij ¡is ¡shaded ¡if ¡corresponding ¡tuples ¡appear ¡in ¡the ¡join ¡output. ¡ ¡ Goal: ¡find ¡a ¡mapping ¡between ¡join ¡matrix ¡cells ¡to ¡reducers ¡that ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡minimizes ¡compleQon ¡Qme. ¡ ¡

slide-17
SLIDE 17

Join ¡AlternaAves ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 17 ¡

  • Standard ¡join ¡algorithm ¡
  • Group ¡both ¡tables ¡by ¡key, ¡send ¡all ¡tuples ¡

with ¡the ¡same ¡key ¡to ¡a ¡single ¡reducer ¡

  • Skew ¡in ¡7 ¡leads ¡to ¡skewed ¡execuAon ¡

Ames ¡in ¡reducers. ¡ ¡

slide-18
SLIDE 18

Join ¡AlternaAves ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 18 ¡

  • Fine ¡grained ¡load ¡balancing ¡

– Divide ¡the ¡cells ¡in ¡the ¡join ¡matrix ¡equally ¡ amongst ¡the ¡reducers ¡

  • Leads ¡to ¡replicaAon ¡of ¡tuples ¡to ¡mulAple ¡

reducers ¡

– S2, ¡S3 ¡are ¡sent ¡to ¡all ¡reducers. ¡ ¡

slide-19
SLIDE 19

Join ¡AlternaAves ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 19 ¡

  • Best ¡of ¡both ¡worlds ¡
  • 7 ¡is ¡broken ¡down ¡into ¡two ¡reducers ¡
  • Limits ¡replicaAon ¡of ¡input ¡as ¡well ¡as ¡

reduces ¡output ¡skew. ¡ ¡

slide-20
SLIDE 20

CompuAng ¡a ¡join ¡

  • IdenAfy ¡the ¡regions ¡in ¡the ¡join ¡matrix ¡that ¡appear ¡in ¡the ¡join. ¡ ¡

– Sufficient ¡to ¡idenAfy ¡a ¡superset ¡of ¡the ¡shaded ¡cells ¡in ¡the ¡join ¡matrix ¡

  • Map ¡regions ¡of ¡the ¡join ¡matrix ¡to ¡reducers ¡such ¡that ¡each ¡shaded ¡

cell ¡is ¡covered ¡by ¡a ¡reducer. ¡ ¡

  • Develop ¡a ¡Map-­‑reduce ¡algorithm ¡to ¡assign ¡tuples ¡to ¡the ¡

corresponding ¡reducers. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 20 ¡

slide-21
SLIDE 21

Approach ¡1: ¡Cross ¡Product ¡

  • Cross ¡Product: ¡all ¡cells ¡in ¡the ¡join ¡matrix ¡are ¡shaded ¡

– Superset ¡of ¡any ¡join ¡condiAon ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 21 ¡

slide-22
SLIDE 22

Cross ¡Product ¡

How ¡to ¡cover ¡the ¡cross ¡product ¡by ¡r ¡reducers? ¡

  • Need ¡to ¡cover ¡all ¡|S| ¡|T| ¡ ¡cells ¡using ¡r ¡ ¡reducers ¡

– Max ¡reducer ¡output ¡size ¡>= ¡|S||T|/r ¡ – Therefore, ¡Max ¡reducer ¡input ¡size ¡>= ¡ ¡2 ¡sqrt(|S||T|/r ¡) ¡

  • We ¡can ¡match ¡these ¡lower ¡bounds ¡by ¡assigning ¡square ¡regions ¡

from ¡the ¡join ¡matrix ¡of ¡side ¡= ¡sqrt(|S| ¡|T| ¡/ ¡r) ¡cells. ¡ ¡

– |S| ¡and ¡|T| ¡must ¡be ¡mulAples ¡of ¡sqrt(|S| ¡|T| ¡/ ¡r) ¡ ¡

  • Algorithms ¡in ¡the ¡paper ¡for ¡opAmal ¡mapping ¡to ¡reducers ¡for ¡any ¡

given ¡|S|, ¡|T|, ¡r. ¡ ¡ ¡

– At ¡most ¡4 ¡sqrt(|S| ¡|T| ¡/ ¡r) ¡max ¡reducer ¡input ¡and ¡max ¡reducer ¡output. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 22 ¡

slide-23
SLIDE 23

Join ¡Algorithm ¡

  • Assign ¡row ¡ids ¡from ¡{1, ¡2, ¡…, ¡|S|} ¡and ¡ ¡

{1, ¡2, ¡…, ¡|T|} ¡to ¡all ¡rows ¡in ¡S ¡and ¡T, ¡resp. ¡ ¡ ¡

  • Map ¡phase: ¡ ¡

For ¡x ¡ε ¡S, ¡let ¡R ¡= ¡{r1, ¡…, ¡rk} ¡be ¡the ¡regions ¡intersecAng ¡row ¡x.id. ¡ Generate ¡tuples: ¡one ¡tuple ¡(r,x) ¡for ¡each ¡r ¡ε ¡R ¡ Similarly ¡generate ¡tuples ¡for ¡y ¡ε ¡T. ¡ ¡

  • Reduce ¡phase: ¡

Perform ¡the ¡join ¡(or ¡cross ¡product) ¡of ¡all ¡the ¡tuples ¡input ¡to ¡the ¡

  • reducer. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 23 ¡

slide-24
SLIDE 24

Join ¡Algorithm: ¡1-­‑Bucket-­‑Theta ¡

  • Problem: ¡Need ¡a ¡new ¡map ¡step ¡to ¡assign ¡ids ¡to ¡rows ¡in ¡S ¡and ¡T ¡
  • Instead, ¡on ¡seeing ¡a ¡new ¡tuple ¡in ¡S ¡or ¡T, ¡assign ¡a ¡random ¡row ¡id. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 24 ¡

slide-25
SLIDE 25

1-­‑Bucket-­‑Theta ¡

  • Since ¡every ¡cell ¡in ¡the ¡enAre ¡cross ¡product ¡is ¡sent ¡to ¡some ¡

reducer, ¡any ¡join ¡algorithm ¡can ¡be ¡implemented ¡

– By ¡applying ¡the ¡appropriate ¡join ¡condiAon. ¡ ¡ ¡

  • If ¡evaluaAng ¡a ¡join ¡requires ¡at ¡least ¡an ¡x ¡fracAon ¡of ¡all ¡cells ¡in ¡the ¡

join ¡matrix, ¡then ¡max ¡reducer ¡input ¡>= ¡2 ¡sqrt(x|S||T|/r). ¡

  • 1-­‑Bucket-­‑Theta ¡has ¡max ¡reducer ¡input ¡<= ¡4 ¡sqrt(|S| ¡|T|/r) ¡
  • Hence, ¡at ¡most ¡a ¡factor ¡of ¡2/sqrt(x) ¡off ¡

– Works ¡well ¡as ¡long ¡as ¡x ¡is ¡large ¡(at ¡least ¡50%) ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 25 ¡

slide-26
SLIDE 26

Approach ¡2: ¡Approximate ¡the ¡Join ¡Matrix ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 26 ¡

True ¡join ¡matrix ¡ Histogram ¡boundaries ¡ Candidate ¡cells ¡to ¡be ¡ covered ¡by ¡algorithm ¡

slide-27
SLIDE 27

Approach ¡2 ¡

  • Need ¡more ¡detailed ¡staAsAcs ¡about ¡|S| ¡and ¡|T| ¡
  • Need ¡to ¡know ¡something ¡about ¡the ¡join ¡predicate ¡

– Doesn’t ¡work ¡for ¡black-­‑box ¡join ¡operators ¡ – Need ¡to ¡idenAfy ¡which ¡blocks ¡contain ¡0 ¡cells ¡that ¡appear ¡in ¡the ¡join ¡ – Equijoins, ¡band-­‑joins, ¡inequality ¡joins ¡… ¡

  • Paper ¡shows ¡a ¡heurisAc ¡technique ¡to ¡divide ¡candidate ¡cells ¡into ¡
  • reducers. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 27 ¡

slide-28
SLIDE 28

Summary ¡

  • High ¡level ¡languages ¡help ¡write ¡complex ¡programs ¡without ¡

thinking ¡about ¡map ¡and ¡reduce ¡

  • Join ¡operaAons ¡can ¡be ¡opAmized ¡by ¡dividing ¡the ¡join ¡matrix ¡into ¡
  • regions. ¡ ¡

Lecture ¡12 ¡: ¡590.02 ¡Spring ¡13 ¡ 28 ¡