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 <https://cloud.google.com/code> to help you debug 
<https://cloud.google.com/code/docs/intellij/deploy-local> these types of 
situations. You can also use the Cloud Profiler for Java 
<https://cloud.google.com/profiler/docs/profiling-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 
<https://medium.com/analytics-vidhya/how-to-write-memory-efficient-loops-in-python-cd625001f0de>.
 
I believe that you can do something similar in Java 
<https://thecannycoder.wordpress.com/2014/07/04/generators/>, 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.
On Saturday, March 27, 2021 at 8:33:52 AM UTC+1 ra wrote:

> 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?
>
>
> On Thu, Mar 25, 2021 at 10:20 PM Ludovic Champenois
> <ludovic.c...@gmail.com> wrote:
> >
> >
> > 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
> >
> > Some more doc at 
> https://cloud.google.com/appengine/docs/standard/java11/runtime#application_startup
> >
> > Hope this helps,
> > Ludo
> >
> > On Wednesday, March 24, 2021 at 10:31:54 AM UTC-7 ra wrote:
> >>
> >> 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
> >
> > --
> > 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
> .
>

-- 
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-appengine+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/54285a1f-2ece-4841-b14d-77fa975e6c2an%40googlegroups.com.

Reply via email to