sql - 在Grails中执行SQL的速度是在工作台中执行相同SQL的速度的两倍,为什么?

标签 sql performance grails

我有一个用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/

    相关文章:

    sql - 不明确的表更新查询

    android - 异步调用期间的 TouchableOpacity block #Performance React-native

    jquery - "Reverse Search"Grails App中的搜索功能

    ruby-on-rails - 如何使用 ruby​​-prof 和 JMeter 分析 Rails

    unit-testing - Grails Spock 单元测试需要模拟事务管理器

    eclipse : Errors occurred during the build Groovy/Grail Project

    mysql - SQLSTATE[42000] 语法错误或访问冲突 行大小太大

    sql - Oracle:什么时候检查约束?

    php - 在 JOIN MySQL 中选择除元素之外的所有元素

    mysql:即使表没有改变,同样的选择也很慢