gpt4 book ai didi

grails - 需要帮助提高 grails 中大型数据集的性能

转载 作者:行者123 更新时间:2023-12-02 03:19:21 24 4
gpt4 key购买 nike

此解决方案有效,但性能低于预期。返回 200K 行的查询需要几分钟的时间,并将 CPU 固定在我的开发盒上。在查询分析器中运行相同的*查询将在 < 1 分钟内返回所有结果。

Class MyController { 

def index = {...}
...
def csv = {
...
def rs = DomainClass.createCritera().scroll {}

while(rs.next()){
response.getOutputStream().print(rs.getString(1)\n)
}
...
}

DB = SQL Server 2005 服务器位于与我的开发计算机分开的专用机箱上。

我还通过 SQL Server Profiler 注意到 gorm/hibernate 使用 sp_cursorprepexec 和 sp_cursorfetch 一次读取 128 行结果。如果可以的话,我想尝试不使用光标。

不确定这是否是问题所在,但只能提供帮助。在休眠状态下,可以将滚动设置为仅向前滚动,但我很难找到类似的 grails 设置。

原始休眠issue

解决方案:绕过休眠。从 10 分钟到 15 秒。

Class MyController { 
def DataSource

def index = {...}
...
def csv = {
...
def out = response.getOutoutStream()
Sql sql = new Sql(dataSource)

sql.eachRow("select c1, c2 from t1",{
out.println( it.c1 + "," + it.c2 )
})
...
}

*same = 从 SQL Server Profiler 剪切并粘贴,但不包括包装 sp_cursorprepexec 存储过程。

最佳答案

如果 GORM 不支持某些功能,可以直接切换到 Hibernate:

import org.hibernate.ScrollMode

class MyController {

def index = {...}

def csv = {
DomainClass.withSession { session ->
def rs = session.createCriteria(DomainClass).scroll(ScrollMode.FORWARD_ONLY)
while (rs.next()) {
response.outputStream.print rs.getString(1)
}
}
}
}

您可以使用 session.createQuery(...) 对 HQL 查询执行相同的操作。

关于grails - 需要帮助提高 grails 中大型数据集的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3730113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com