Automating Distributed Partial Aggregation Chang Liu1, Jiaxing Zhang2, Hucheng Zhou2, Sean McDirmid2, Zhenyu Guo2, Thomas Moscibroda2 1University of Maryland, College Park 2Microsoft Research MapReduce Framework Mapper Mapper Mapper Mapper emits key-value pairs Key-value pairs will be shuffled over the network, and the pairs with the same key are transmitted to the same reducer Reducer Reducer Reducer Reducer takes all pairs with the same key as input, and compute the output Network IO is one of the bottlenecks dominating the overall latency MapReduce – Partial Aggregation Some traditional reducer to apply partial aggregation Mapper By aggregating partial results produced by an initial reducer, with a combiner, network IO can be reduced significantly Initial Reducer Mapper Initial Reducer Mapper Initial Reducer SUM MAX COUNT AVERAGE Combiner Final Reducer In distributed computation scenario, most reducers are provided as user defined functions Partial Aggregation – state-of-the-art • Most MapReduce systems support Partial Aggregation • Hadoop – Combiner • SCOPE – Recursive reducer • Etc. • Partial Aggregation is effective • Our study shows a up to 99.98% shuffling IO reduction, and up to 62% overall latency reduction • But most require programmers to manually rewrite the reducer • Programmers may write bugs when programs become sophisticated • We study 183 real SCOPE programs, and found 28 of them (15.3%) are problematic An example of User Defined Reducer Row reduce(RowSet inputs) { int sum = 0, count = 0; bool isFirst = true; Row output; for(row in inputs.Rows) { if(isFirst) { output[0] = row[0]; sum = 10 + row[1]; count = 2; isFirst = false; } else sum+=row[1], count++; } output[1] = sum/count; return output; } Inputs Reducer Key Value 1 2 1 5 1 3 … … output[0]=Key output[1]= 10+Σπ≥1 Inputs[i].Value 1+ Inputs How to apply partial aggregation to such a reducer? Automating Partial Aggregation • Reduce the partial aggregation application problem to the combiner synthesis problem Automating Partial Aggregation • Reduce the partial aggregation application problem to the combiner synthesis problem • A necessary and sufficient condition as the mathematical foundation Automating Partial Aggregation • Reduce the partial aggregation application problem to the combiner synthesis problem • A necessary and sufficient condition as the mathematical foundation • Programming language techniques to solve the following problems: • Decomposable verification • Combiner synthesis How to apply partial aggregation? Row reduce(RowSet inputs) { int sum = 0, count = 0; bool isFirst = true; Mapper Mapper Initial Reducer Initial Reducer Row output; for(row in inputs.Rows) { if(isFirst) { output[0] = row[0]; sum = 10 + row[1]; count = 2; Combiner isFirst = false; } else sum+=row[1], count++; } output[1] = sum/count; return output; } Final Reducer How to apply partial aggregation? It depends on the count =aggregator 0; in the main InitialReduce(inputs) loop = true; int sum = 0, count body! Row reduce(RowSet inputs) { int sum = 0, bool isFirst Row output; for(row in inputs.Rows) { if(isFirst) { = 0; … // the same as the original reducer foreach (row in inputs.Rows) { … } emit(output[0], sum, count, isFirst); output[0] = row[0]; sum = 10 + row[1]; count = 2; isFirst = false; What is the Combiner? } else sum+=row[1], count++; } output[1] = sum/count; return output; } FinalReduce(partialResults) emit(partialResults[0], sum/count) What reducers have a combiner? A mathematical foundation • πΉ is decomposable if and only if there exists a combiner πΆ such that: • • • • (commutativity of π) πΉ π 0 , π ⊕ π = πΉ π 0 , π ⊕ π 1 (correctness of πͺ) πΉ π 0 , π ⊕ π = πΆ πΉ π 0 , π , πΉ π 0 , π (commutativity of πͺ) πΆ π 1 , π 2 = πΆ π 2 , π 1 (associativity of πͺ) πΆ(πΆ(π 1 , π 2 ), π 3 ) = πΆ(π 1 , πΆ(π 2 , π 3 )) • Yu et al. Distributed aggregation for data-parallel computing: interfaces and implementations. In SOSP 2009. Notation: π 0 is the initial results πΉ(π , π) is the aggregator πΆ(π , π ) is the combiner 1⊕ is the operation concatenating two sequenses Main theorem What is this? • Theorem: πΉ is decomposable if and only if πΉ π , π₯π¦ = πΉ(π , π¦π₯) holds for all π , π₯, π¦. The combiner πΆ is uniquely determined by πΉ, and takes the form πΆ π 1 , π 2 = πΉ(π 1 , π» π 2 ) where π» is any general inverse function of πΉ Commutativity of πΉ Existence of πΆ Correctness of πΆ Commutativity of πΆ Associativity of πΆ General Inverse Function Initial Reducer π • π»(π ) is a general inverse function of πΉ if and only if πΉ π 0 , π» π = π . π H(s) π • πΉ may have many general inverse functions π π = π»(π 2 ) π»(π 1 ) • Question: will different general inverse functions result in different combiners? • We prove that for any two different general inverse functions π», π»′, πΆπ» ≡ πΆπ» ′ Initial Reducer Initial Reducer π 1 π 2 π»(π 2 ) π = π» π 1 Initial Reducer Combiner πΆπ» π π Decomposability Verification and Combiner Synthesis Programming Language Techniques • Theorem: πΉ is decomposable if and only if πΉ π , π₯π¦ = πΉ(π , π¦π₯) holds for all π , π₯, π¦. The combiner πΆ is uniquely determined by πΉ, and takes the form πΆ π 1 , π 2 = πΉ(π 1 , π» π 2 ) where π» is any general inverse function of πΉ Decomposability Verification and Combiner Synthesis Programming Language Techniques • Theorem: πΉ is decomposable if and only if π π, ππ = π(π, ππ) holds for all π, π, π. The combiner πΆ is uniquely determined by πΉ, and takes the form πΆ π 1 , π 2 = πΉ(π 1 , π» π 2 ) where π» is any general inverse function of πΉ • Decomposability verification: checking πΉ π , π₯π¦ = πΉ(π , π¦π₯) holds true for all π , π₯, π¦ Decomposability Verification and Combiner Synthesis Programming Language Techniques • Theorem: πΉ is decomposable if and only if πΉ π , π₯π¦ = πΉ(π , π¦π₯) holds for all π , π₯, π¦. The combiner πͺ is uniquely determined by πΉ, and takes the form πͺ ππ , ππ = π(ππ , π― ππ ) where π» is any general inverse function of πΉ • Decomposability verification: checking πΉ π , π₯π¦ = πΉ(π , π¦π₯) holds true for all π , π₯, π¦ • Combiner Synthesis: given πΉ, find an arbitrary general inverse function. Decomposability Verification SMT solver-based method Accumulator πΉ if(isFirst) { key = x[0]; sum = 10 + x[1]; count = 2; isFirst = false; Symbolic Execution Path formula for πΉ (isFirst i = 1 ∧ keyo = x 0 ∧ sumo = 10 + x 1 ∧ count o = 2 ∧ isFirst o = 0) ∨ (isFirst i = 0 ∧ keyo = keyi ∧ sumo = sumi + x 1 ∧ count o = count i + 1 ∧ isFirst o = isFirst i } else sum+=x[1], count++; Formula for πΉ π 0 , π₯π¦ ≠ πΉ(π 0 , π¦π₯) Combiner Synthesis • Hard – Finding π» is a nondeterministic program inversion problem • We find that many eligible reducers belong to the following categories: • Counting • Single Input • State Machine Combiner Synthesis – COUNTING Example Accumulator πΉ if(isFirst) { Observation: the results only depends on the size of the input sequence, instead of their values. key = x[0]; sum = 10 + x[1]; count = 2; isFirst = false; } else { sum+=x[1]; count++; } Strategy: Mimic the input size to get one partial result, then aggregate these input over the other partial result. Heuristics to accelerate: if the aggregator is a linear function of COUNT, then compute the function. Combiner Synthesis – Single Input Example Accumulator πΉ if(isFirst) { key = x[0]; sum = 10 + x[1]; count = 2; isFirst = false; } else { sum+=x[1]; count++; } Observation: there exists a general inverse function whose output is a sequence of length one. Strategy: Given the partial results, find one input value to compute this result, and apply that value over the other partial result. Illustrating Example: given sum, then sum = 10 + x 1 ⇒ x 1 = sum − 10 So Combine sumx , sumy = sumx + (sumy − 10) More details can be found in our paper. Evaluation • We study 4,429 SCOPE jobs • 183 have already used partial aggregation • 28 of them (15.3%) are buggy • Xiao et al. Nondeterminism in MapReduce Considered Harmful? An Empirical Study on Non-commutative Aggregators in MapReduce Programs, ICSE 2014 • We identify 261 more jobs that are eligible for partial aggregation • 22 unique reducers (reducers are heavily reused in different jobs) Evaluation – decomposability verification • We verify πΉ π , π¦π₯ = πΉ(π , π₯π¦) over the 22 identified reducers with two quantifier: (1) ∀π , π₯, π¦ and (2) ∀π₯, π¦. π = π 0 1. 1The reasons why to use two quantifiers can be found in Section 6.1 Evaluation – combiner synthesis • We apply our techniques to synthesize the combiner for these 22 identified reducers. • C for COUNTING, SM for State Machine, SI for Single Input • We failed on synthesizing the combiner for reducer 21 and 22. Evaluation – Performance Gain • Real job with tens of TBs input data • End-to-end latency reduction from 165 seconds to 64 seconds (61.6%) • Data volume over network decreases from 7.99 GB to 1.22 MB (99.98%) • Synthesized jobs (SUM, COUNT, and MAX) • An average of 62.4% reduction in latency • An average of 76% reduction in network I/O Conclusion and Future Directions • A necessary and sufficient condition for decomposability • SMT solver-based methods for the decomposability verification problem • Several techniques to solve the combiner synthesis problem • Evaluation on real dataset shows our techniques are effective • Future directions • More techniques handling the combiner synthesis problem Thank you!