计算Spark SQL的运行时间 [英] Calculate the running time for spark sql
本文介绍了计算Spark SQL的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行一些Spark SQL语句,并希望计算其运行时间.
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
推荐答案
如果您使用的是spark-shell(scala),则可以尝试定义如下计时函数:
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
}
然后您可以尝试:
val df = show_timing{sqlContext.sql(query)}
这篇关于计算Spark SQL的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文