2

I'm deploying a new version of my Flask application to Google App Engine (GAE) and am receiving a 500 server error before the home page even loads. The only difference in this new version is that I am loading an additional 26MB file into memory using the @app.before_first_request decorator. In the previous, working version, I was loading in files in the same manner that amounted to 20MB at most.

Before loading in this file, my app was working well in production.

I have tried to update my app.yaml file to increase the size of the machine by adding in the following lines:

resources:
  cpu: 2
  memory_gb: 2.3

This is my app.yaml file:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static
  static_dir: static
- url: /.*
  script: main.app

libraries:
- name: ssl
  version: latest
- name: numpy
  version: "1.6.1"

resources:
  cpu: 2
  memory_gb: 2.3

This is how I am loading the files into memory in main.py:

def get_gcloud_data(fname):
    """Retrieve file from GCS.
    """
    base_link = 'http://fake_base_link/'
    return pickle.loads(requests.get(base_link+fname).content)

@app.before_first_request
def startup():
    global fake_var_name

    fake_var_name = np.array(get_gcloud_data('pickled_file.p'))

I did not expect this additional file to cause such problems. Am I loading files into memory incorrectly (should I be doing this at all?)? How come I am getting this new 500 error?

1 Answers1

2

You're mixing up flexible environment configurations (resources in particular) into your standard environment app.yaml file - they are ignored. Possibly of interest: How to tell if a Google App Engine documentation page applies to the 1st/2nd generation standard or the flexible environment

To bump the available memory (and CPU power) in the standard environment you need to choose a different instance_class (see it in the Runtime and app elements):

instance_class

Optional. The instance class for this service.

The following values are available depending on your service's scaling:

Automatic scaling

F1, F2, F4, F4_1G

Default: F1 is assigned if you do not specify an instance class along with the automatic_scaling element.

Basic and manual scaling

B1, B2, B4, B4_1G, B8

Default: B2 is assigned if you do not specify an instance class along with the basic_scaling element or the manual_scaling element.

Note: If instance_class is set to F2 or higher, you can optimize your instances by setting max_concurrent_requests to a value higher than 10, which is the default. To find the optimal value, gradually increase it and monitor the performance of your application.

I see you're seeking for 2.3G or RAM, but the max supported by standard environment instance classes is only 1G. If youreally need more than 1G you'll have to switch to the flexible environment. But I suspect you might not actually need that much since the app was working fine before the change with what should have been the default instance class (i.e. F1 with 128M).

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • 2
    thanks so much! You are right. It seems I was mixing up the environment types. After setting the `instance_class: F2` in my yaml file, it is working in production. – David Albrecht Apr 19 '19 at 22:05