[英]OutOfMemoryError: Trying to optimise Maven multi-module unit tests using HSQLDB, DBUnit, unitils, Hibernate, Spring
I have a big multi-module Maven project with thousands of tests. 我有一个包含数千个测试的大型多模块Maven项目。 Each test loads DAOs, services, etc using the SpringApplicationContext annotation.
每个测试都使用SpringApplicationContext批注加载DAO,服务等。 My unitils configuration looks like this:
我的unitils配置如下所示:
database.driverClassName=org.hsqldb.jdbcDriver
database.url=jdbc:hsqldb:file:mytestdb
database.schemaNames=PUBLIC
database.userName=sa
database.password=
database.dialect=hsqldb
unitils.modules=database,dbunit,hibernate,inject,spring
# custom version of HsqldbDbSupport which calls "SET REFERENTIAL_INTEGRITY FALSE"
org.unitils.core.dbsupport.DbSupport.implClassName.hsqldb=my.company.unitils.HsqldbDbSupport
org.dbunit.dataset.datatype.IDataTypeFactory.implClassName.hsqldb=org.dbunit.ext.hsqldb.HsqldbDataTypeFactory
org.unitils.dbmaintainer.structure.ConstraintsDisabler.implClassName=org.unitils.dbmaintainer.structure.impl.DefaultConstraintsDisabler
# custom version of CleanInsertLoadStrategy which calls "DatabaseUnitils.disableConstraints();"
DbUnitModule.DataSet.loadStrategy.default=my.company.unitils.DataSetLoadStrategy
HibernateModule.configuration.implClassName=org.hibernate.cfg.AnnotationConfiguration
dbMaintainer.disableConstraints.enabled=true
dbMaintainer.cleanDb.enabled=true
dbMaintainer.generateDataSetStructure.enabled=false
dataSetStructureGenerator.xsd.dirName=target/xsd
dbMaintainer.autoCreateExecutedScriptsTable=true
updateDataBaseSchema.enabled=false
dbMaintainer.fromScratchEnabled=true
My Hibernate configuration looks like this: 我的Hibernate配置如下所示:
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.autocommit=false
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_structured_entries=false
hibernate.generate_statistics=false
When I run the tests, the 2GB allocated for heap eventually fills up. 当我运行测试时,分配给堆的2GB最终会填满。 Permgen reaches about 400MB.
Permgen达到约400MB。 Looking at the heap dump, char , java.lang.String and java.lang.String[] takes up about 40% of the total instances.
从堆转储来看, char , java.lang.String和java.lang.String []约占实例总数的40%。
When I spot-check a few of these instances, the GC root traces back to: 当我抽查其中一些实例时,GC根源可以追溯到:
I would like to optimise these 2 things, and I think they are respectively caused by: 我想优化这两个方面,我认为它们分别是由于:
Note, I use jdbc:hsqldb:file to offload some data off of the heap (ie instead of using jdbc:hsqldb:mem) 注意,我使用jdbc:hsqldb:file卸载堆中的某些数据(即,而不是使用jdbc:hsqldb:mem)
Versions: 版本:
hsqldb 1.8.0.7 hsqldb 1.8.0.7
Spring 3.0.4.RELEASE 春季3.0.4。发布
unitils 3.1 unitils 3.1
PS can someone with a 1500+ rating please tag this question with "unitils"? PS可以有人用1500+等级,请与标签“unitils”这个问题?
If the memory is taken by the data stored in the database, you can make the database use disk based tables to reduce memory use. 如果内存是由数据库中存储的数据占用的,则可以使数据库使用基于磁盘的表来减少内存使用。 This can be specified on the database URL:
可以在数据库URL上指定:
database.url=jdbc:hsqldb:file:mytestdb;hsqldb.default_table_type=cached database.url = jdbc:hsqldb:file:mytestdb; hsqldb.default_table_type = cached
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.