【问题标题】:How can I benchmark performance in Spark console?如何在 Spark 控制台中对性能进行基准测试?
【发布时间】:2015-06-04 14:54:19
【问题描述】:

我刚刚开始使用 Spark,目前我与它的交互围绕着spark-shell。我想基准测试各种命令需要多长时间,但找不到如何获取时间或运行基准测试。理想情况下,我想做一些超级简单的事情,例如:

val t = [current_time]
data.map(etc).distinct().reduceByKey(_ + _)
println([current time] - t)

编辑:想通了--

import org.joda.time._
val t_start = DateTime.now()
[[do stuff]]
val t_end = DateTime.now()
new Period(t_start, t_end).toStandardSeconds()

【问题讨论】:

    标签: scala apache-spark


    【解决方案1】:

    我建议您执行以下操作:

    def time[A](f: => A) = {
      val s = System.nanoTime
      val ret = f
      println("time: " + (System.nanoTime - s) / 1e9 + " seconds")
      ret
    }
    

    您可以将函数作为参数传递给时间函数,它会计算函数的结果,为您提供要执行的函数所花费的时间。

    让我们考虑一个以数据为参数的函数foobar,然后执行以下操作:

    val test = time(foobar(data))
    

    test 将包含foobar 的结果,您也将获得所需的时间。

    【讨论】:

    • System.nanoTime 以纳秒为单位给出时间。您的转换产生毫秒 :) 将 1e6*60*60 替换为 1e9 以在几秒钟内获得结果。
    • 我不记得我是什么时候写的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多