Java app using abnormal amount of ram
Attached you see the RAM usage graph of my project. I am running a discord bot with a Java Spring Boot application, and on my local device, the app eventually uses <200 mb of RAM, but on railway, the ram usage continues to increase. I found a StackOverflow post that tackles a similar issue, but updating my Dockerfile with the runtime flags did not deliver noticeable changes (see the last deployed commit, compared to the rest). Ideally, I don't have to manually call the GC, although it is an option available to me.
Does anyone have any recommendations for getting my Java app to release unused RAM memory?
Stack Overflow
Java 17 app shows very high RAM usage in docker
I have a application that during idle times usually only needs 1GB of RAM however when I launch it inside in docker, then it shows much higher RAM usage (5GB) from the outside.
The JVM metric show ...
Solution:Jump to solution
It looks like shenandoahGC has given my app a healthier ram graph. Thank you all for your help!
17 Replies
Project ID:
1a73e8f4-a61d-4a67-9bd7-3539b677698b
1a73e8f4-a61d-4a67-9bd7-3539b677698b
that's more so looking like a memory leak to me
If it was, then i'd be able to reproduce that locally, no?
do you build from the dockerfile file and run the resulting image ?
Yes
well it's not like railway is making up metrics
According to stack it's because java isnt by default configured for containers, which is why i asked here if people had knowhow of how i should configure the dockerfile
My apologies if I gave you the wrong answer to this question. I mean that Railway is running from the Dockerfile, and my local machine is the bare Java app. Local machine has less ram usage then the deployment on railway.
The attached stackoverflow post claims that java won't unclaim heap space the same way if it's running in a container. There were runtime flags i could add to the dockerfile that'd supposedly fix this, but this did not have the desired effect
what effect did it have, if any
Practically none if it didnt make it worse
Are you sure the flags were taken into account when deploying?
How can I verify that?
Logs
A quick search doesn't give me any hits for the flags, so i guess they're not being considered
I'll play with those when i get back home and see if i can get it working. Probably misusing them
I am the most smoothbrained ape on this planet
Flags go before the -jar flag 🤦
Did it help your heap usage?
Going to redeploy now and see if it helps
I've had her run for a bit and it definitely looks like it helped. RAM usage continues to grow but does so much slower
I'm trying if ShenandoahGC helps more. It looks promising so far
Solution
It looks like shenandoahGC has given my app a healthier ram graph. Thank you all for your help!