Home > Mobile >  Is setting JVM Xmx option in Google App Engine Standard useful?
Is setting JVM Xmx option in Google App Engine Standard useful?

Time:08-25

I've a simple Spring Boot application running on Google App Engine Standard Java 11 environment F2 instances. However, I occasionally get errors such as:

Exceeded soft memory limit of 512 MB with 592 MB after servicing 18320 requests total. Consider setting a larger instance class in app.yaml.

Instead of upgrading to a larger instance type, I'd prefer to limit memory usage, even if it degrades performance a bit.

Since an F2 instance has 512MB of available memory, would it help to set JVM's -Xmx option to a value like say, 480MB? Or will it make things worse by converting Google's "Exceeded soft memory limit" warning to a full blown OutOfMemory error?

Thanks

CodePudding user response:

You can limit the amount of memory the jvm is using, but there are no universal "recommended" arguments / settings. Settings that may be good for one application or use-case can be terrible for another one.As a general rule, no JVM settings at all is a good starting point.

When you face the Exceeded soft private memory limit error you have two alternatives to follow:

  • You can upgrade your instance to an another with more memory

  • You can reduce the chunks of data you process in each request, process the XML file in smaller pieces and keep the smaller instance doing the work.

Here is a stackoverflow post which can help.

CodePudding user response:

A Java process can consume more memory than what is specified via -Xmx. That applies only to max heap size. As such, if you want to limit it, you should specify significantly less than 512 MB. There are other flags to limit some portions of non-heap memory like -XX:MaxDirectMemorySize.

By default, 1/4th of available RAM is assigned as Xmx. You should check what are the actual settings your app is running with, perhaps via java -XX: PrintFlagsFinal.

I suggest reading this excellent post by a JVM expert explaining various types of JVM memory: Java using much more memory than heap size (or size correctly Docker memory limit)

  • Related