当 运行 使用 Gradle 进行单元测试时,最大堆大小在哪里设置?
Where does the maximum heap size get set when running a unit test with Gradle?
我有一个失败的 OOM 单元测试,想知道为什么我需要像这样手动允许更大的 maxHeapSize
:
test {
maxHeapSize = '4G'
}
我假设最大堆没有上限并且在 gradle api 来源中找不到任何东西来证明我错了。但是,运行 gradle 和 --info
清楚地表明并非如此:
Starting process 'Gradle Test Executor 427'. Working directory: [project-dir] Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dorg.gradle.native=false -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.6.jar_a26f6511a7813217be4cd6439d66563b/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea -cp /Users/[user]/.gradle/caches/6.4/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 427'
我的问题是上面的-Xmx512m
是从哪里来的?
接下来,有没有办法允许无限的最大堆,这会是一件完全不合理的事情吗?
可能与 Default maximum heap size for JavaExec Gradle task
重复
512m
默认设置在DefaultWorkerProcessBuilder
. 512m
is a tradeoff, working for small to medium sized projects and given that multiple workers can be running simultaneously. According to the commit message:
Limit memory for worker processes by default
Our workers for compilation, testing etc. had no default
memory settings until now, which mean that we would use
the default given by the JVM, which is 1/4th of system memory
in most cases. This is way too much when running with a high
number of workers. Limiting this to 256m should be enough for
small to medium sized projects. Larger projects will have to
tweak this value.
Next to that, is there a way to allow for unlimited max heap and would that be a totally unreasonable thing to do?
在撰写本文时,我不知道有任何 JVM 实现允许无限内存,老实说,我不认为这是可取的,因为它会大大降低系统速度。
我有一个失败的 OOM 单元测试,想知道为什么我需要像这样手动允许更大的 maxHeapSize
:
test {
maxHeapSize = '4G'
}
我假设最大堆没有上限并且在 gradle api 来源中找不到任何东西来证明我错了。但是,运行 gradle 和 --info
清楚地表明并非如此:
Starting process 'Gradle Test Executor 427'. Working directory: [project-dir] Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dorg.gradle.native=false -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.6.jar_a26f6511a7813217be4cd6439d66563b/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea -cp /Users/[user]/.gradle/caches/6.4/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 427'
我的问题是上面的-Xmx512m
是从哪里来的?
接下来,有没有办法允许无限的最大堆,这会是一件完全不合理的事情吗?
可能与 Default maximum heap size for JavaExec Gradle task
重复512m
默认设置在DefaultWorkerProcessBuilder
. 512m
is a tradeoff, working for small to medium sized projects and given that multiple workers can be running simultaneously. According to the commit message:
Limit memory for worker processes by default
Our workers for compilation, testing etc. had no default memory settings until now, which mean that we would use the default given by the JVM, which is 1/4th of system memory in most cases. This is way too much when running with a high number of workers. Limiting this to 256m should be enough for small to medium sized projects. Larger projects will have to tweak this value.
Next to that, is there a way to allow for unlimited max heap and would that be a totally unreasonable thing to do?
在撰写本文时,我不知道有任何 JVM 实现允许无限内存,老实说,我不认为这是可取的,因为它会大大降低系统速度。