java gradle 守护进程的高内存使用率

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34314862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:44:37  来源:igfitidea点击:

High memory usage by gradle daemon

javagradlegradle-daemon

提问by

I am using Gradle 2.5 to compile a Java project which consists of 5 modules. In order to speed things up I also use the gradle-daemon. However, During compilation there are up to 18 instances of the gradle-daemon running. After compilation finishes there are still 15 instances of the daemon left. The daemons process consumes about 600 MB of RAM. Is it normal to have that many daemons running in the background or is the gradle-daemon misconfigured?

我正在使用 Gradle 2.5 编译一个包含 5 个模块的 Java 项目。为了加快速度,我还使用了 gradle-daemon。但是,在编译期间,最多有 18 个 gradle-daemon 正在运行。编译完成后,还剩下 15 个守护进程实例。守护进程消耗大约 600 MB 的 RAM。在后台运行这么多守护进程是否正常,还是 gradle-daemon 配置错误?

UPDATE: My operating system is Debian Jessie. Java version is Oracle Java 8.

更新:我的操作系统是 Debian Jessie。Java 版本是 Oracle Java 8。

采纳答案by

Following Antoniossss' advice I got in touch with a developer. As it turns out, Gradle is in fact quite resource hungry. Even for a simple "Hello World" application the daemon might use very well up to 150 MB and maybe even more. It is also alright, that multiple daemon threads are started, as long as they run within the same JVM. There is only limited control on the user's side to control/limit memory usage. One could set GRADLE_OPTS variable in order to pass Xmx options to the JVM, e.g., I managed to build my Android project with following settings:

按照 Antoniossss 的建议,我与一位开发人员取得了联系。事实证明,Gradle 实际上非常需要资源。即使对于一个简单的“Hello World”应用程序,守护程序也可能使用最多 150 MB 甚至更多。启动多个守护线程也没关系,只要它们在同一个 JVM 中运行即可。用户方面只有有限的控制来控制/限制内存使用。可以设置 GRADLE_OPTS 变量,以便将 Xmx 选项传递给 JVM,例如,我设法使用以下设置构建了我的 Android 项目:

$ export GRADLE_OPTS="-Xmx64m -Dorg.gradle.jvmargs='-Xmx256m -XX:MaxPermSize=64m'"

The first -Xmx option is set for the Gradle that you start in CLI, the second one (after -Dorg.gradle.jvmargs) is the -Xmx value for the Gradle-Daemon.

第一个 -Xmx 选项是为您在 CLI 中启动的 Gradle 设置的,第二个(在 -Dorg.gradle.jvmargs 之后)是 Gradle-Daemon 的 -Xmx 值。

The less memory you allow for your JVM the higher the risk for your build to fail - obviously. So you might have to tune those settings until they suit your purposes.

JVM 允许的内存越少,构建失败的风险就越高——显然。因此,您可能必须调整这些设置,直到它们适合您的目的。

Those settings can also be set in the gradle.properties file.

这些设置也可以在 gradle.properties 文件中设置。