Skip to content Skip to sidebar Skip to footer

Gae Soft Private Memory Limit Error On Post Requests

I am working on an application where I am using the paid services of Google app engine. In the application I am parsing a large xml file and trying to extracting data to the datast

Solution 1:

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

  1. To upgrade your instance to a more powerful one, which gives you more memory.
  2. To reduce the chunks of data you process in each request. You could split the XML file to smaller pieces and keep the smaller instance doing the work.

Solution 2:

I agree with Mario's answer. Your options are indeed to either upgrade to an Instance class with more memory such as F2 or F3 or process these XML files in smaller chunks.

To help you decide what would be the best path for this task, you would need to know if these XML files to be processed will grow in size. If the XML file(s) will remain approximately this size, you can likely just upgrade the instance class for a quick fix.

If the files can grow in size, then augmenting the instance memory may only buy you more time before encountering this limit again. In this case, your ideal option would be to use a stream to parse the XML file(s) in smaller units, consuming less memory. In Python, xml.sax can be used to accomplish just that as the parse method can accept streams. You would need to implement your own ContentHandler methods.

In your case, the file is coming from the POST request but if the file were coming from Cloud Storage, you should be able to use the client library to stream the content through to the parser.

Solution 3:

I had a similar problem, almost sure it's my usage of /tmp directory was causing it, this directory is mounted in memory which was causing it. So, if you are writing any files into /tmp don't forget to remove them!

Another option is that you actully have a memory leak! It says after servicing 14 requests - this means the getting more powerful instance will only delay the error. I would recommend cleaning memory, now I don't know what your code looks like, I'm trying following with my code:

import gc

# ...@app.route('/fetch_data')deffetch_data():
    data_object = fetch_data_from_db()
    uploader = AnotherHeavyObject()

    # ...
    response = extract_data(data_object)


    del data_object
    del uploader
    gc.collect()

    return response

After trying things above, now it seems that issue was with FuturesSession - related to this https://github.com/ross/requests-futures/issues/20. So perhaps it's another library you're using - but just be warned that some of those libraries leak memory - and AppEngine preserves state - so whatever is not cleaned out - stays in memory, and affects following requests on that same instance.

Post a Comment for "Gae Soft Private Memory Limit Error On Post Requests"