Google App Engine pricing can be hard to decipher since it is based on a pay-what-you-use model. But what matters is the billable amount listed at the bottom. By using the methods and techniques described here you can minimize your cost of hosting your application on Google App Engine.
1. Cache Everything
GAE does not charge you for using their general memcache service. Take advantage of this by caching data that is used frequently.
2. Resident Instances
Only use resident instances if you can’t afford the latency it takes to start up new instances. I’ve seen many customers using resident instances which sit there idle and have dynamic instances spawned up handling a majority of the incoming request.
3. Optimize your Queries
Not all queries are equal in the face of your GAE bill. Use key-only queries when your application can use the data from just the key the entity rather than the entire entity. Projection queries are also cheaper because they only require scanning the index tables and not having to fetch the entire entity.
4. Use Asynch URL Fetch
When making REST calls to remote servers or even a self-fetch, try to do it asynchronously with the following recipe:
- Do Asynch URL Fetch
- Do other stuff (DB access, taskqueue, etc)
- Block on the result from step 1
This shaves off latency from your requests which will lower your front-end costs.
5. Use NDB instead of DB
NDB has caching built into the datastore. Your datastore operations will be much faster and will cost less because repeated access with gets and queries will use the free memcache service rather than the datastore.
6. Trade latency for Cost
In your GAE application console you can set the latency a user sees before a new process is started. Fiddle with this and find out what amount of latency you can handle without affecting your users. The more latency you can handle, the less your front-end bill will be.
7. Don’t Index Properties you Don’t Query on
Each property in your datastore models are indexed when you do a put, yet your application may not ever be using them. If you’re not doing queries on certain fields set “indexed=False” on those fields. Your puts may become faster, and you won’t get billed for these extraneous indexes.
8. Delete old data
Data is nice to have around, but over time it’ll start costing you to store it. Occasionally run a background job (mapreduce or pipeline API) to remove data that has no value.
9. Fast User Facing Request
Look at the latency reported by the dashboard in the GAE application console. See which request are taking a really long time to service. Optimize these first to get the most bang for your buck.
10. Make your Application Multithreaded
If your setting “threadsafe: false” in your app.yaml, then each application server is only servicing one request at a time. Write thread safe code for the love of god and handle more requests per process.
Got other ways of saving money on GAE? We’d love to hear them.
Day 4: New Belgium – Giddy Up
Continuing our “99 Bottles of Beer” blog series, let’s try out a Giddy Up!, from New Belgium:
It’s a dark brown color, with hints of amber. It has a minimal amount of head and is mildly carbonated.
Definitely has a good coffee smell going on. Very aromatic!
A bit on the heavier side, and a bit of a thick taste. A minimal coffee aftertaste is present as well.
Neither overly carbonated nor flat. Easy to drink in moderation, and surprisingly smooth.
A delicious beer! I paired this one off with a bowl of chili macaroni, which the beer performed very well with. The coffee notes also make it nice for an after-dinner beer as well, so give it a try! – Dr. Chris Bunch