Calculate the running time for spark sql

99封情书 提交于 2021-02-04 11:39:07

问题


I'm trying to run a couple of spark SQL statements and want to calculate their running time.

One of the solution is to resort to log. I’m wondering is there any other simpler methods to do it. Something like the following:

import time

startTimeQuery = time.clock()
df = sqlContext.sql(query)
df.show()
endTimeQuery = time.clock()
runTimeQuery = endTimeQuery - startTimeQuery

回答1:


If you're using spark-shell (scala) you could try defining a timing function like this:

def show_timing[T](proc: => T): T = {
    val start=System.nanoTime()
    val res = proc // call the code
    val end = System.nanoTime()
    println("Time elapsed: " + (end-start)/1000 + " microsecs")
    res
}

Then you can try:

val df = show_timing{sqlContext.sql(query)}


来源:https://stackoverflow.com/questions/35280581/calculate-the-running-time-for-spark-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!