You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Marco Gaido (JIRA)" <ji...@apache.org> on 2018/04/02 09:44:00 UTC

[jira] [Commented] (SPARK-23791) Sub-optimal generated code for sum aggregating

    [ https://issues.apache.org/jira/browse/SPARK-23791?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16422064#comment-16422064 ] 

Marco Gaido commented on SPARK-23791:
-------------------------------------

Thanks, [~rednikotin]. The error you noticed in the range 84-99 has already been solved in SPARK-23628 (it is fixed in 2.3.1, 2.4.0). I think I know the reason of the performance issue: I will try and work on it in the next days. Thanks.

> Sub-optimal generated code for sum aggregating
> ----------------------------------------------
>
>                 Key: SPARK-23791
>                 URL: https://issues.apache.org/jira/browse/SPARK-23791
>             Project: Spark
>          Issue Type: Bug
>          Components: Optimizer
>    Affects Versions: 2.2.0, 2.3.0
>            Reporter: Valentin Nikotin
>            Priority: Major
>              Labels: performance
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> It appears to be that with wholeStage codegen enabled simple spark job performing sum aggregation of 50 columns runs ~4 timer slower than without wholeStage codegen.
> Please check test case code. Please note that udf is only to prevent elimination optimizations that could be applied to literals. 
> {code:scala}
> import org.apache.spark.sql.functions._
> import org.apache.spark.sql.{Column, DataFrame, SparkSession}
> import org.apache.spark.sql.internal.SQLConf.WHOLESTAGE_CODEGEN_ENABLED
> object SPARK_23791 {
>   def main(args: Array[String]): Unit = {
>     val spark = SparkSession
>       .builder()
>       .master("local[4]")
>       .appName("test")
>       .getOrCreate()
>     def addConstColumns(prefix: String, cnt: Int, value: Column)(inputDF: DataFrame) =
>       (0 until cnt).foldLeft(inputDF)((df, idx) => df.withColumn(s"$prefix$idx", value))
>     val dummy = udf(() => Option.empty[Int])
>     def test(cnt: Int = 50, rows: Int = 5000000, grps: Int = 1000): Double = {
>       val t0 = System.nanoTime()
>       spark.range(rows).toDF()
>         .withColumn("grp", col("id").mod(grps))
>         .transform(addConstColumns("null_", cnt, dummy()))
>         .groupBy("grp")
>         .agg(sum("null_0"), (1 until cnt).map(idx => sum(s"null_$idx")): _*)
>         .collect()
>       val t1 = System.nanoTime()
>       (t1 - t0) / 1e9
>     }
>     val timings = for (i <- 1 to 3) yield {
>       spark.sessionState.conf.setConf(WHOLESTAGE_CODEGEN_ENABLED, true)
>       val with_wholestage = test()
>       spark.sessionState.conf.setConf(WHOLESTAGE_CODEGEN_ENABLED, false)
>       val without_wholestage = test()
>       (with_wholestage, without_wholestage)
>     }
>     timings.foreach(println)
>     println("Press enter ...")
>     System.in.read()
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org