How can I lower my billing in gcp app engine deployment?

1/5/2020

I have hosted multiple applications in GCP App Engine. We are currently in development and testing environment, and the user requests are almost nil. In my understanding, the billing should have been low when the traffic is low. But the billing of past two months is way more than what we had initially expected. Our target is to host over hundred application in near future, but if the current billing trend continues, the potential situation after we scale is scary.

Until October we had hosted 5 applications and the billing was around 250 USD per month, but since November we've added two more applications-practically of same size and requirements as that of our previous five applications, and the billing has crossed 700 USD per month. Is there any possibility that we could have been doing something wrong? or is it better if we shift to Kubernetes or VM instance?

-- Prateik Pokharel
cloud
google-app-engine
google-cloud-platform
google-kubernetes-engine

3 Answers

1/5/2020

The bill suggests something is not truly idle.

Could you provide more details like a screenshot of the App Engine->Instances summary page? Or the billing summary? ( I can't add comments yet, hence my answer is a question for now .. )

-- Ronan Hughes
Source: StackOverflow

1/6/2020
#standard app.yaml
# service name or project name
service: default
# python runtime version 
runtime: python37
entrypoint: #django 
# type of app engine standard or flex
env: standard
# environment varible required for the project
env_variables:
  # GCP cloud database envs 
  # Bucket storage envs
handlers:
- url: /static
  static_dir: static


#flex app.yaml
service: #service name
runtime: custom
entrypoint: #django
env: flex
env_variables:
  #GCP cloud sql
  # bucket link
handlers:
- url: /static
  static_dir: static/
runtime_config:
  python_version: 3.6 # enter your Python version BASE ONLY here. Enter 2 for 2.7.9 or 3 for 3.6.4


#flex docker file
FROM gcr.io/google-appengine/python
LABEL python_version=python3.6
RUN virtualenv --no-download /env -p python3.6
# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/
RUN apt-get update
RUN apt-get install -y software-properties-common 
RUN apt-add-repository ppa:ricotz/testing
RUN apt-get update
RUN apt-get install -y libcairo2-dev
RUN apt-get install -y build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
RUN apt install -y pkg-config
RUN pip install -r requirements.txt
ADD . /app/
CMD exec gunicorn -b :$PORT name.wsgi
-- Prateik Pokharel
Source: StackOverflow

1/5/2020

App Engine is billed per instance/hour, compared to the market its prices are more than fair but you have to consider the whole picture while forecasting costs of your applications including, price of other services, traffic, etc.

First off I suggest you review the pricing of App Engine, which instance types are you using ? Can you use a more cheap instance type ? Check how many instances your application spawn, you can do it in GPC App Engine info page or with Stackdriver Monitoring. Is the behaviour the one you expect ? Are you spawning too many instances at one point because of cron jobs, etc ? Will it be possible for your application to limit the max number or instances at a time in order to contain costs?

If you are using also other services, carefully review costs for each project inside the specific page, what is costing more than expecting ? Review your total costs using the gcp pricing calculator, understand what you didn't expect and adjust your application to cover spikes in costs.

-- Pievis
Source: StackOverflow