我有一个用grails编写的报表应用程序。它在生产后台数据库中触发SQL,并简单地将结果行返回给用户。
执行sql的位是这样的:
class ReportService {
static transactional = false
def dataSource_target
def runReport(sql) {
def rows = null
def start
def con
start = System.currentTimeMillis()
try {
con = new Sql(dataSource_target)
rows = con.rows(sql)
} finally {
con.close()
}
def time = System.currentTimeMillis() - start
def response = [rows: rows, time:time,]
response
}
运行此命令时,需要60秒(60000毫秒)。如果我使用mysql工作台或类似版本运行完全相同的SQL,它会在30秒后返回。那是很大的不同!
通常在30左右返回行,因此网络开销不大。
有什么主意为什么要运行查询并使结果变成红色?
最佳答案
您代码中的time
变量可测量
为了更准确地测量(2),请将代码更改为
def runReport(sql) {
def rows = null
def time
def con
try {
con = new Sql(dataSource_target)
def start = System.currentTimeMillis()
rows = con.rows(sql)
time = System.currentTimeMillis() - start
} finally {
con.close()
}
def response = [rows: rows, time:time,]
response
}
关于sql - 在Grails中执行SQL的速度是在工作台中执行相同SQL的速度的两倍,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25606070/