How can we avoid OutOfMemoryError exceptions?
The App Engine scheduler starts instances based on response times, but we need new instances started when an existing instance is exceeding its memory quota.
Our GAE instances handle multiple concurrent upload requests of varying file sizes. Whenever an instance handles too many concurrent uploads (that use heap space to copy uploaded bytes), the instance crashes with java.lang.OutOfMemoryError: Java heap space.
We’ve seen the other posts suggesting using of instance class with more memory or use of Backends.
But do we have to move to Backends to avoid this? Or is there a way the normal GAE instance scheduler can be encouraged not to send new requests to instances near memory limit?
Use blobstore upload handler instead. The upload goes first through blob upload handler that strips blob data and saves it to blobstore, then your handler is called (and passed the saved blob key and other request data).
This has two advantages:
Your front end is not involved with handling blob data, so this should not produce OOM error.
Uploads can be larger than 32Mb, which is otherwise limit for all frontend requests.