Reputation: 4659
We are developing a small e-commerce project for which we are using GAE
as our web service backend but it's draining our financial resources. We studied our current infrastructure and how it was billed. That shows us that it's because of the instances we are using.
We have 7 services
running which is using 12 instances
as a whole.
Want to understand how to stop Google App Engine
instances when not being used as it's the key contributor to our billing.
application: ...
module: updatecategoryfeed
version: uno
runtime: python27
api_version: 1
instance_class: F1
threadsafe: true
automatic_scaling:
min_idle_instances: 6
max_idle_instances: automatic # default value
min_pending_latency: 30ms # default value
max_pending_latency: automatic
max_concurrent_requests: 50
handlers:
- url: /.*
script: FeedModule.FeedBuilder.update_category_feed
libraries:
- name: endpoints
version: 1.0
- name: webapp2
version: "latest"
- name: ssl
version: latest
All other services following the same structure. We have a total of 7 active services.
We decreased the auto scaling values as per our project requirements which min idle instances
to 0 and max idle instance
to be 1. The price dropped drastically. But we are still looking for the answer on how to stop an instance when not being used. For ex. the below graph shows an instance started on its own without any activity and is being billed.
Upvotes: 1
Views: 1041
Reputation: 31
You can start and stop GAE services, configuring to manual_scaling and use GAE API to start and stop.
const proj = '' // project id here
const serv = 'default' // or your service id
const vers = '' // version id here
const {google} = require('googleapis')
const appengine = google.appengine ({version: 'v1', auth: auth})
// To retrieve Status:
appengine.apps.services.versions.get ({
appsId: proj,
servicesId: serv,
versionsId: vers,
view: 'BASIC',
})
.then ()
.catch ()
// To Change Status:
newStatus = 'STOPPED' // or 'SERVING'
appengine.apps.services.versions.patch ({
appsId: proj,
servicesId: serv,
versionsId: vers,
updateMask: 'serving_status',
requestBody: {
serving_status: newStatus
}
})
.then ()
.catch ()
Upvotes: 1
Reputation: 39814
Drop your min_idle_instances
configuration in the automatic_scaling
section - those configs effectively represent instances running at all times - also called resident instances for that reason.
Their role is not to handle traffic regularly. They only handle overflow traffic for short periods of time when the traffic exceeds the capacity of the running dynamic instances to keep the latencies low, while GAE spins up additional dynamic instances (which are the ones actually handling the bulk of the traffic).
Just in case it's not clear - resident instances aren't going away - it is their job to remain alive even if there is no activity on the site.
Upvotes: 2