title: Google App Engine App get terminated due to memory limit (at 40MB usage)?
body: <p>My GAE backend always get terminated at 40MB memory usage and log said it used too much memory. I don't know why since I used B1/B2 which should have 128/256MB.</p>
  
  <p>Here is the details</p>
  
  <p>I create my GAE app with a frontend module and a backend (in python). The frontend gets the user requests and send to backend. Backend is a image processing app involving google cloud storage service. It needs a long time to finish and consumes some memory as expected.  The backend module run for a long time (5-10mins maybe) so I start the function as a background thread like shown in document:</p>
  
  <pre><code>t = background_thread.BackgroundThread(target=f, args=["foo", "bar"])
  t.start()
  </code></pre>
  
  <p>Everything works fine on my local development server. However, on cloud, every time the thread is about to finish, it gets terminated. Log said:</p>
  
  <blockquote>
    <p>2014-05-12 18:45:11.826 While handling this request, the process that
    handled this request was found to be using too much memory and was
    terminated. This is likely to cause a new process to be used for the
    next request to your application. If you see this message frequently,
    you may have a memory leak in your application.</p>
  </blockquote>
  
  <p>I searched a lot, people usually get this message with another message saying "reach soft memory limit" but I only got one message. I checked my memory usage report, the process is always get terminated at 40MB! but I used B1 and B2 which should have 128/256MB limit. Btw, I tried both manual and basic scaling with 1-3 instances. </p>
  
  <p>Even very short run also cause this problem. I tried processing 20 images (each one only 5-10kb) should take tens of seconds to finish at maximum, it still gets killed at 40MB. I also found when my backend idel, it already cost 30 MB. I doubt the image processing will cost hundreds of MB. On my local machine, the image processing usually only take seconds to finish...</p>
  
  <p>My guess is:</p>
  
  <p>Since my function runs as a thread and no further requests coming, google thinks the backend is idle and should not consume such large memory. So gae kills it for memory leaking.
  Or, google limit the thread to use only 40MB memory.</p>
  
  <p>By the way, I havn't enable my billing. Will it give me some limit like this?</p>
  
  <p>Can anyone help me with this issue? Thank you very much. </p>
  
  <p><img src="https://i.stack.imgur.com/aEFHR.jpg" alt="Memory usage figure"></p>