performance - Grails 中从服务返回到 Controller 的时间

标签 performance spring grails spring-mvc

我们正在研究 grails 应用程序的性能,看来 grails 需要很多时间(7-13 毫秒)才能退出服务返回到 Controller 。返回的数据是对域对象的引用(带有 2 个引用的 Map),不是很复杂。有什么办法可以缩短这个时间吗?

我们在服务中的 return 语句之前有 log.debug() ,在离开服务后,在 Controller 中还有另一个 log.debug() 。

2012-02-01 15:16:07,048 [http-8080-1] DEBUG api.TestService test before service return
2012-02-01 15:16:07,063 [http-8080-1] DEBUG api.TestController test after service return

编辑:Grails 版本 1.3.7

编辑:打开休眠 SQL 日志记录后:

2012-02-02 09:20:04,504 [http-localhost%2F127.0.0.1-8080-1] DEBUG api.TestService before return
2012-02-02 09:20:04,505 [http-localhost%2F127.0.0.1-8080-1] DEBUG hibernate.SQL select nextval ('hibernate_sequence')
2012-02-02 09:20:04,516 [http-localhost%2F127.0.0.1-8080-1] DEBUG hibernate.SQL insert into test ...
2012-02-02 09:20:04,520 [http-localhost%2F127.0.0.1-8080-1] DEBUG hibernate.SQL update test1 ...
2012-02-02 09:20:04,522 [http-localhost%2F127.0.0.1-8080-1] DEBUG hibernate.SQL insert into test_test1 ...
2012-02-02 09:20:04,524 [http-localhost%2F127.0.0.1-8080-1] DEBUG api.TestController after service

最佳答案

开销可能是由 Spring 围绕服务调用构建事务上下文引起的(Grails 默认值,请参阅 http://grails.org/doc/2.0.x/guide/services.html#declarativeTransactions )。 如果您的服务不需要(数据库)事务,请确保添加

static transactional = false 

在服务中。

如果您确实需要事务并且正在从 Controller 进行大量服务调用,则值得将它们转移到服务,以便您可以处理最少的事务量。 (如果您绝对想将它们保留在 Controller 中,则可以使用 withTransaction block 在单个事务中执行多个服务调用。)

关于performance - Grails 中从服务返回到 Controller 的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9097542/

相关文章:

Grails 2.3.1 没有运行

performance - ColdFusion 查询的查询速度比数据库调用本身慢 100 倍(记录数相对较低)

java - 优化 Tomcat/垃圾收集

java - 从 datasource.getConnection() 获取 OracleConnection

java - Spring MVC 自定义异常映射不起作用

grails - 在 Controller 中处理grails异常以进行捕获和转发

grails - grails View 中未显示“dateCreated”字段

performance - Scala - 调用 'first class functions' 的开销

C# 在使用循环访问内存时比 Java 慢一半?

java - 线程池为 7 的 Spring 调度程序无法正常工作