title: treeReduce vs reduceByKey in Spark
body: <p>I saw the following post a little bit back: <a href="https://stackoverflow.com/questions/32281417/understadning-treereduce-in-spark">Understanding TreeReduce in Spark</a></p>
  
  <p>I am still trying to exactly understand when to use a treeReduce vs a reduceByKey. I think we can use a universal example like a word count to help me further understand what is going on.  </p>
  
  <ul>
  <li>Does it always make sense to use reduceByKey in a word count?</li>
  <li>Or is there a particular size of data when treeReduce makes more sense?</li>
  <li>Are there particular cases or rules of thumbs when treeReduce is the better option? </li>
  <li>Also this may be answered in the above based on reduceByKey but does anything change with reduceByKeyLocally and treeReduce</li>
  <li>How do I appropriately determine depth?</li>
  </ul>
  
  <p><strong>Edit</strong>: So playing in spark-shell, I think I fundamentally don't understand the concept of treeReduce but hopefully an example and those question help.</p>
  
  <pre><code>res2: Array[(String, Int)] = Array((D,1), (18964,1), (D,1), (1,1), ("",1), ("",1), ("",1), ("",1), ("",1), (1,1))
  
  scala&gt; val reduce = input.reduceByKey(_+_)
  reduce: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[11] at reduceByKey at &lt;console&gt;:25
  
  scala&gt; val tree = input.treeReduce(_+_, 2)
  &lt;console&gt;:25: error: type mismatch;
   found   : (String, Int)
   required: String
         val tree = input.treeReduce(_+_, 2)
  </code></pre>