title: Very high latency running Python Flask app on gcloud app engine
body: <p>I have this small Python Flask app that gets a file posted as input and runs this file through a tensforflow keras model to come back with a prediction.</p>
  <p>On my old laptop, running this locally it is superfast. The app consumes around 450MB or ram.</p>
  <p>Now I have deployed this app to gcloud app engine, and I experience extremely high lantency, ranging from 1,900 to 3,500 ms. 1000x slower than on my own laptop! Not only is it slow, but it starts to much instances as well because of it.</p>
  <p>I have tried with F2 and F4 instances (F1 doesn't provide enough memory), but it doesn't make a difference.</p>
  <p><strong>app.yaml</strong></p>
  <pre><code>runtime: python37
  env: standard
  instance_class: F2
  entrypoint: gunicorn -b :$PORT main:app
  </code></pre>
  <p><strong>main.py</strong></p>
  <pre><code>from flask import Flask
  from flask_cors import CORS
  from flask_restful import Api, Resource, reqparse, abort
  from firebase import verifyToken, log
  from model_manager import predict
  import werkzeug, os
  import tempfile
  
  app = Flask(__name__)
  CORS(app)
  api = Api(app)
  
  post_args = reqparse.RequestParser()
  post_args.add_argument('file', type=werkzeug.datastructures.FileStorage, location='files', help=&quot;No file provided.&quot;, required=True)
  post_args.add_argument('Authorization', type=str, location='headers', help=&quot;No auth token provided.&quot;, required=True)
  
  class Analyze(Resource):
      def post(self):
          data = post_args.parse_args()
  
          if not verifyToken(data['Authorization']):
              abort(401, message=&quot;The user is not authorized to use this &quot;)
  
          try:
              tf = os.path.join('tmp', tempfile.NamedTemporaryFile().name)
              data['file'].save(tf)
              result = predict(tf)
          except Exception as ex:
              abort(400, message=ex)
          finally:
              if tf:
                  os.remove(tf)
  
          return result, 200
  
  api.add_resource(Analyze, &quot;/&quot;)
  
  if __name__ == &quot;__main__&quot;:
      app.run(debug=False)
  </code></pre>
  <p>Am I doing something wrong here that causes the high latency?</p>