Higher ram usage with spring boot
william
HOBBYOP

a year ago

I noticed that now that we have migrated to Metal, Java Spring Boot projects are consuming almost twice as much RAM. Is this correct?

The project is the same.

Solved$10 Bounty

Pinned Solution

root101
HOBBY

a year ago

I have a couple of problems with this one, couple of things to notice:

  • When Railway automatically migrated my services to Metal, my RAM usage spiked to nearly 900MB per service. Solution: manually redeploy the services.
  • Be very careful with the Java image you're using. For example, a simple project, with DB connection, security, all the basics the, using OpenJDK image consumes about 500 MB, the Eclipse-Temurin image consumes about 350 MB, and if you compile natively (GraalVM), it consumes about 120 MB. I don't know which image is used if you're compiling with Railpack. Solution: Use Dockerfile to deploy with a better image to run the project. Feel free to let me know if you need help configuring Docker

3 Replies

melivoracapensis
FREE

a year ago

No, this is not expected - if your project, code, and workload are the same, a move to a new infrastructure (like Railway’s Metal vs. previous cloud hosts) should not double your Java Spring Boot app's memory usage in theory.

Always explicitly set JVM limits in your launch config or Dockerfile. For example:

Always explicitly set JVM limits in your launch config or Dockerfile. For example:

java -Xms512m -Xmx1024m -XX:MaxMetaspaceSize=256m -jar app.jar

Set your JVM memory flags explicitly to get consistent behavior across hosts.


asgard
FREE

a year ago

Hey william!

This is likely due to Railway's migration to Metal infrastructure having different JVM defaults. Java applications often consume more memory when the JVM detects more available system resources. Try adding these JVM flags to limit memory usage:

JAVA_OPTS=-Xmx512m -Xms256m -XX:MaxMetaspaceSize=128m

Or in your Railway service variables:

_JAVA_OPTIONS=-Xmx512m -Xms256m


root101
HOBBY

a year ago

I have a couple of problems with this one, couple of things to notice:

  • When Railway automatically migrated my services to Metal, my RAM usage spiked to nearly 900MB per service. Solution: manually redeploy the services.
  • Be very careful with the Java image you're using. For example, a simple project, with DB connection, security, all the basics the, using OpenJDK image consumes about 500 MB, the Eclipse-Temurin image consumes about 350 MB, and if you compile natively (GraalVM), it consumes about 120 MB. I don't know which image is used if you're compiling with Railpack. Solution: Use Dockerfile to deploy with a better image to run the project. Feel free to let me know if you need help configuring Docker

Status changed to Solved chandrika 11 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...