Exceeded soft memory limit - how to configure app.yaml for java 11

2,760 views
Skip to first unread message

Raphael André Bauer

unread,
Mar 24, 2021, 1:31:54 PM3/24/21
to google-a...@googlegroups.com
Hi,

I am running in the issue "Exceeded soft memory limit of 256 MB with
283 MB after servicing 3 requests total.
Consider setting a larger instance class in app.yaml.".

My app.yaml looks like this:

########################################
runtime: java11
instance_class: F1

env_variables:
JAVA_TOOL_OPTIONS: "-XX:MaxRAM=200m -Xmx200m"
inbound_services:
- warmup

handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301

automatic_scaling:
min_instances: 1
max_instances: 2

# Connecting to the cloud sql instance via app engine standard needs a
vpc access connector:
# https://stackoverflow.com/questions/51328359/how-to-connect-to-cloud-sql-mysql-database-from-app-engine
vpc_access_connector:
name: "projects/xxxxlocations/europe-west3/connectors/serverless-connector"
##########################################################################

My question now is: How can I tell the java runtime to NOT use more
than the available RAM of the instance?

Strangely: Anything I set in terms of -Xmx gets discarded and my app
always has a max heap of 127.729664MB.
So it seems my JAVA_TOOL_OPTIONS do not get picked up by the JVM.

So where does the rest of the memory go?
Or is this "something else" like the serverless connector in the
container that consumes all the memory?


Thanks!


Raphael

Ludovic Champenois

unread,
Mar 25, 2021, 5:19:49 PM3/25/21
to Google App Engine

Hi,
I am not sure JAVA_TOOL_OPTIONS is supported (nor documented) for GAE Java11..
You have a few options:
1/ either move to
instance_class: F4
or
instance_class: F2

to get bigger instances.
Or manually control your entrypoint... I assume you deployed a jar, let's call it myjar.jar

the default entrypoint generated is:
java -jar myjar.jar

You can change it by adding this to your app.yaml:

entrypoint: java -XX:MaxRAM=200m -Xmx200m -jar myjar.jar


Hope this helps,
Ludo

Raphael André Bauer

unread,
Mar 27, 2021, 3:33:52 AM3/27/21
to google-a...@googlegroups.com
Thanks Ludo!
I have zero idea how this is implemented internally
- but might it be the case that the VPN connector uses a substantial
amount of memory of the instance?
> --
> You received this message because you are subscribed to the Google Groups "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/55cf6419-9a2b-4fb5-a51d-086d084ade78n%40googlegroups.com.

Andrew Cooper

unread,
Apr 7, 2021, 5:58:45 AM4/7/21
to Google App Engine

Do you know how much memory it uses when you run it locally? 

Increasing the size of the instance is not generally the best approach. For example, if you have a memory leak, then the instance size might need to grow exponentially!!

You can use Cloud Code to help you debug these types of situations. You can also use the Cloud Profiler for Java to understand better what your code is consuming.

I am more familiar with Python than Java, but I wonder how you are implementing the Java code? Looping in Python is notoriously problematic as it has a habit of leaving behind and accumulating "garbage" in memory. You can implement List Comprehensions, Generators, and Yield returns in Python to consume memory more efficiently. I have added a link that explains my thinking better and provides a helpful comparison. I believe that you can do something similar in Java, but I might be wrong. You can also try chunking your data, but you might be limited in how you can split your data, so it might not be the best fit.

Reply all
Reply to author
Forward
0 new messages