https://kotlinlang.org logo
#gradle
Title
# gradle
n

Nick Kleban

04/02/2024, 2:02 PM
Greetings all! I have project with structure similar to nowinandroid Why I see 2 java processes while executing gradle commands? And is it possible to limit memory consumption of second java process? • Second stays in the limits set from root
gradle.properties
Copy code
'org.gradle.jvmargs=-Xmx3072m -XX:+UseParallelGC -Dfile.encoding=UTF-8'
• First one takes way more, usually around 4,5Gb
s

Sam

04/02/2024, 2:14 PM
I don't know how Kotlin-specific this question is, so this might not be the best place to ask. What gradle commands are you running? Maybe the second process is for running tests, or something like that.
n

Nick Kleban

04/02/2024, 2:22 PM
Sorry if this is not right place to ask, I was just thinking maybe it’s some kind of kotlin daemon running along with gradle daemon I’m running unit tests with
Copy code
./gradlew clean koverVerify --no-build-cache --no-daemon
s

Sam

04/02/2024, 2:24 PM
There will almost certainly be some extra processes. I think the Kotlin compiler often runs in a daemon. Tests will also probably fork extra processes. And Gradle itself will almost always make a separate daemon process, even if you specify
--no-daemon
.
If you can, I'd say just rely on swap and let the build do whatever it wants. I've had to try to limit builds to a fixed amount of memory in the past and it's a massive pain.
n

Nick Kleban

04/02/2024, 2:31 PM
--no-daemon
I’ve added just for testing, so I don’t need to stop gradle before my test run When I ran
assemble
result is roughly the same The reason I want to limit it because on CI (14GB RAM) my builds are failing sometimes with OOM, and I suspect this unlimited process may consume too much memory
s

Sam

04/02/2024, 2:33 PM
Yeah, I've been there. I have no idea why 1️⃣ CI servers increasingly seem to have less memory than developer machines and 2️⃣ CI servers never seem to have any kind of swap 😢
Decades ago we invented memory virtualisation so we wouldn't have to deal with this, and then along comes container orchestration with its fancy ideas about how every process needs a fixed amount of memory again
It's like we went back in time
Sorry, I guess that touched a nerve 😂
I don't have a solution for you 😞
n

Nick Kleban

04/02/2024, 2:39 PM
I appreciate it anyway! Our devops initially proposed to have 4GB servers for our builds 😂
🤦 1
c

Chrimaeon

04/02/2024, 3:20 PM
what do you set the java option for memory to? there are also other gradle options you can set on your.
On Circle CI I usually use
Copy code
JAVA_TOOL_OPTIONS: "-Xmx3G"
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.workers.max=2 -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false"
and my builds run on a large resource class with 8GB of ram.
t

tapchicoma

04/02/2024, 3:52 PM
Why I see 2 java processes while executing gradle commands? And is it possible to limit memory consumption of second java process?
Second process is Kotlin daemon. You could define jvm args for it via
kotlin.daemon.jvmargs
Gradle property
n

Nick Kleban

04/02/2024, 4:03 PM
It was indeed kotlin daemon, thank you for help! This one worked for me:
Copy code
-Dkotlin.daemon.jvm.options=-Xmx3G
I’ve noticed that settings for a Kotlin daemon like:
Copy code
kotlin.daemon.jvmargs=-Xmx4G -Xms2G
are not honored if gradle daemon was enabled and works perfectly otherwise. Does anyone have any ideas as to why?
t

tapchicoma

04/03/2024, 5:23 PM
Gradle daemon is always starting even if you pass
--no-daemon
option. Why do you think it is not honored? cc @Alexander.Likhachev
a

Alexander.Likhachev

04/03/2024, 5:37 PM
> I’ve noticed that settings for a Kotlin daemon like: >
Copy code
kotlin.daemon.jvmargs=-Xmx4G -Xms2G
> are not honored if gradle daemon was enabled and works perfectly otherwise Hm, could you explain it more or maybe even provide a reproducer project, please? In some cases, the Kotlin daemon may reuse the daemon process that was started earlier. It has special handling for the case e.g. if you request 2GB, but there’s already a daemon started for another project that requested 5GB. Then, instead of starting 2 daemons the daemon with the biggest memory limit will be reused. It’s not yet properly documented and sometimes may work not as expected, we have plans to improve this. Thus, if you’re experimenting with different memory limits, sometimes you have to kill the daemon (or use
--no-daemon
) during the experiments.
n

Nick Kleban

04/06/2024, 3:53 PM
Before tests I always do
gradle --stop
. I was probably misinterpreting output of
top -o mem
command. I’m not sure then what the column
mem
shows in this case.
a

Alexander.Likhachev

04/09/2024, 7:47 PM
mem
in the output of
top
shows the physical memory currently allocated by OS to the JVM process. Could you provide more specific details about the output you are seeing? Is it lesser than you’re setting? Bigger? You may be also interested in more specialized tools for JVM like
jcmd <pid> GC.heap_info
,
jcmd <pid> VM.flags
where you can find the required process id using the
jps
tool. Or you may even use visual tools like VisualVM or the one included into IDEA Ultmate By setting
-Xmx
, you’re limiting only the heap memory of JVM, it does not say anything about the JVM non-heap memory as well as the metaspace
3 Views