1

I recently ported a very simple project built in [python 2.7 / webapp2] to [python 3.7 / Flask] and in the last month I've seen the cost raising from $0 to $20!

The project is very simple (90 lines of code): just a couple of request handlers that return different json based on the value passed in the query string. There's virtually no difference in the code other than a sligtly different syntax. Traffic and request also didn't change much and decreased if anything.

In the billing I can see how the frontend hours have increased significantly and how GAE spins up more instances more often than before.

Has anyone experienced the same behaviour? Are python 3.7 and Flask "heavier" than webapp2 on 2.7?

For completeness both versions have been deployed with a standard vanilla gcloud app deploy with no other options. It's using the standard environment on F1 instances and no background workers or tasks. The app.yaml is pretty much identical in the parts that relate to the instances setup:

env: standard
instance_class: F1
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: automatic
  max_pending_latency: automatic

versions with no traffic, don't have any instance running (they can't be stopped, so they are serving, but with 0 instances).

For sake of clarity I can attach the graphs of the new version, and the old one that I temporarily re-enabled. From the graphs is clear how the new setup spins up instances for no apparent reason while the old one keep a cool flat 1 instance active.

New configuration

Old configuration

Andrea
  • 638
  • 9
  • 20
  • After further investigation I can confirm that the Python 3.7 runtime with Flask have definitely an heavier footprint compared to Python 2.7 with webapp2. The execution latency for the same script jumped from an average of 5ms/50ms/90ms to 15ms/90ms/120ms at 50th/90th/95th percentile. This on average is a 2x increase that is definitely very likely to trigger the Google App Engine scheduler into spinning up additional instances. – Andrea May 15 '20 at 16:52

1 Answers1

1

As you may be familiar, App Engine pricing is based on primarily on the number of hours an instance runs. https://cloud.google.com/appengine/pricing

There is nothing particularly special about Flask or the python37 runtime that would cause it to run "heavier" than a python27 webapp2 app. However, patterns of use might cause billing behavior like this. For example:

  • If the old version (the python27 app in your case) is disabled and the type of scaling allows for instances to continue to run on the old version, you will pay for compute time on both versions.
  • Triggering background work (e.g. data processing, media compression, etc.) with the incoming HTTP request and returning before the work is finished causes high compute time, leading to a high bill.

Other possibilities are explored here: https://stackoverflow.com/a/47245172/11957811. In order to say for sure what was causing the exact charges in your specific case, we would need to know how you deployed your old and new app (e.g. which gcloud commands and flags you ran) and what are the app.yaml configurations for both.

Joshua Koh
  • 90
  • 5
  • Thanks Joshua! I updated my original question to provide more detailed informations about the setup. I also checked the other discussion that you mentioned but it refers to the Flex environment which behaves different from the standard env that I'm using. What do you think of the graphs above? – Andrea May 14 '20 at 03:33