gagafunctor commented on a change in pull request #23983: [SPARK-26881][mllib]
Heuristic for tree aggregate depth
URL: https://github.com/apache/spark/pull/23983#discussion_r270669086
##########
File path:
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/RowMatrix.scala
##########
@@ -775,6 +778,35 @@ class RowMatrix @Since("1.0.0") (
s"The number of rows $m is different from what specified or previously
computed: ${nRows}.")
}
}
+
+ /**
+ * Computing desired tree aggregate depth necessary to avoid exceeding
+ * driver.MaxResultSize during aggregation.
+ * Based on the formulae: (numPartitions)^(1/depth) * objectSize <=
DriverMaxResultSize
+ * @param aggregatedObjectSizeInBytes the size, in megabytes, of the object
being tree aggregated
+ */
+ private[spark] def getTreeAggregateIdealDepth(aggregatedObjectSizeInBytes:
Long) = {
+ require(aggregatedObjectSizeInBytes > 0,
+ "Cannot compute aggregate depth heuristic based on a zero-size object to
aggregate")
+
+ val maxDriverResultSizeInBytes = rows.conf.get[Long](MAX_RESULT_SIZE)
+
+ require(maxDriverResultSizeInBytes > aggregatedObjectSizeInBytes,
+ s"Cannot aggregate object of size $aggregatedObjectSizeInBytes Bytes, "
+ + s"as it's bigger than maxResultSize ($maxDriverResultSizeInBytes
Bytes)")
+
+ val numerator = math.log(rows.getNumPartitions)
+ val denominator = math.log(maxDriverResultSizeInBytes) -
math.log(aggregatedObjectSizeInBytes)
+ val desiredTreeDepth = math.ceil(numerator / denominator)
+
+ if (desiredTreeDepth > 4) {
+ logWarning(
+ s"Desired tree depth for treeAggregation is big ($desiredTreeDepth)."
+ + "Consider increasing driver max result size or reducing number of
partitions")
+ }
+
+ math.min(math.max(1, desiredTreeDepth.toInt), 10)
Review comment:
@srowen Sorry for the lag, I was in vacations, away from my dev station.
I should be able to push an update by tuesday, but feel free to do it before
if you want :)
----------------------------------------------------------------
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]