srowen commented on a change in pull request #23983: [SPARK-26881][core] 
Heuristic for tree aggregate depth
URL: https://github.com/apache/spark/pull/23983#discussion_r262974622
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/rdd/RDD.scala
 ##########
 @@ -1178,6 +1178,37 @@ abstract class RDD[T: ClassTag](
     }
   }
 
+  /**
+   * Computing desired tree aggregate depth necessary to avoid exceeding
+   * driver.MaxResultSize during aggregation.
+   * Based on the formulae: (numPartitions)^(1/depth) * objectSize <= 
DriverMaxResultSize
+   * @param aggregatedObjectSizeInMb the size, in megabytes, of the object 
being tree aggregated
+   * @param numPartitions the number of partitions for which to aggregate 
partial results
+   * @param maxDriverResultSizeInMb the value of the parameter 
spark.driver.maxResultSize in MB
+   */
+  def getTreeAggregateIdealDepth(
+      aggregatedObjectSizeInMb: Int,
+      numPartitions: Int = getNumPartitions,
+      maxDriverResultSizeInMb: Int = Utils.memoryStringToMb(
+        context.getConf.get("spark.driver.maxResultSize"))): Int = {
+    require(
+      aggregatedObjectSizeInMb < maxDriverResultSizeInMb,
+      s"object size to aggregate ($aggregatedObjectSizeInMb MB) exceeds max 
driver result size"
+        + s"($maxDriverResultSizeInMb MB)"
+    )
+    val numerator = math.log10(numPartitions) + 
math.log10(aggregatedObjectSizeInMb)
+    val denominator = math.log10(maxDriverResultSizeInMb)
+    val desiredTreeDepth = math.ceil(numerator / denominator).toInt
 
 Review comment:
   I might be doing the math wrong here, but we want partitions^(1/depth) * 
vectorSize <= maxResultSize, right? I get that this needs depth >= 
log(partitions) / (log(maxResultSize) - log(vectorSize)) ?
   
   I suppose we want some safety checks for 0 partitions or 0 aggregate size in 
MB.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to