什么可以使dev和prod模式之间的性能不同?

时间:2013-04-12 19:22:00

标签: performance grails opencsv grails-2.2

示例

我正在编写一个实用程序,使用OpenCSV在CSV中转换域类,pojos和pogos。我创建的示例可用on git

我的想法是转到TestController的索引操作并点击将进行ajax调用的按钮。此ajax将以CSV格式转换在引导程序上创建的域类Test的所有实例,并将此文本返回到视图。

流程

  • Bootstrap创建5000个域类Test
  • 的记录
  • 用户转到索引页面: / csv-example / test / index
  • 用户点击按钮,发出ajax请求
  • 控制器列出所有测试记录
  • ArrayList csv格式的控制器转换String
    • DefaultCSVConverter将查找类Test
    • 的序列化程序
    • DomainClassSerializer将转换List<String[]>
    • 中的实例
    • DefaultCSVConverter将使用 OpenCSV 撰写List<String[]>

问题

如果我在production模式下运行此示例应用程序,Grails会快得多,而我正在尝试理解原因。我已经尝试在dev模式下运行,禁用了realoding agent:

grails Ddisable.auto.recompile=true -noreloading run-app

这对转换实例所花费的时间没有影响。

所以我的问题是:除了重新加载代理之外,还有什么能使这种性能在开发和生产模式之间有所不同?

Env

Grails 2.2.1

赢7 x64

JDK 1.6.0_43 64位

3 个答案:

答案 0 :(得分:1)

似乎差异是由国际化引起的。 PluginAwareResourceBundleMessageSource在开发和生产运行模式之间有不同的表现。为了找到我使用Jvisualvm,在开发和生产模式下分析CPU。

启动Grails

set GRAILS_OPTS=-Xverify:none -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8500 -Dcom.sun.management.jmxremote.authenticate=false -

grails  -Ddisable.auto.recompile=true -noreloading run-app

启动jvisualvm

jvisualvm -J-Xms1G -J-Xmx1G –cp:a path/to/app/target/classes

分析结果应如下所示

enter image description here

答案 1 :(得分:0)

我看了你的github代码,并且prod dataSource - pooled = true?这可以吗?

答案 2 :(得分:0)

我的理解是prod和dev主要区别在于grails-app / conf中关于应用程序可执行文件的定义。假设你为prod和dev提供了相同的硬件/操作系统配置和启动参数,我首先要看一下配置文件中的不同之处。

您的Config.groovy

environments {
    development {
        grails.logging.jul.usebridge = true
    }
    production {
        grails.logging.jul.usebridge = false
        // TODO: grails.serverURL = "http://www.changeme.com"
    }
}

DataSource.groovy中

development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
}
...
production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
}

有一点突出(正确的,如果我错了,因为我为H2配置数据源已经有一段时间了)是在dev中,你在内存中运行H2,而在prod中你正在写入磁盘。

相关问题