Reputation: 270
We have a piece of Javascript which is served to millions of browsers daily. In order to handle the load, we decided to go for Google App Engine.
One particular thing about this piece of Javascript is that it is (very) slightly different per company using our service.
So far we are handling this by serving everything through main.py which basically goes: - Read the JS static file and print it - Print custom code
We do this on every load, and costs are starting to really add-up.
Apart from having a static version of the file per customer, is there any other way that you could think about in order to reduce our bill? Would using memcache instead of reading a file reduce the price in any way?
Thanks a lot.
Upvotes: 2
Views: 669
Reputation: 10128
If you use Javascript by serving static files (I assume that what you do now).
Upvotes: 0
Reputation: 15143
I'm assuming you're paying a lot in instance hours. Reading from the GAE filesystem is rather slow. So the easiest way to optimize is only read from the static file once on your instance startup, keep the js file in memory (ie a global variable), and print it.
Secondly, make sure your js is being cached by the customers so when they reload your page, you don't have to serve the js to them again unnecessarily.
Next way is to serve the js file as a static file if possible. This would save you some money if the js file is big and you're consuming CPU cycles just printing it. In this case have your handler that generates the HTML insert the appropriate URL to the appropriate js file instead of regenerating the entire js each time. You'll save money because you won't get charged instance hours for files served as static files, plus they can get cached in the edge cache (GAE's CDN), and you won't get billed anything at all for them.
Upvotes: 3
Reputation: 2276
Here are some ways to more optimize it without using a cdn.
Yes do add the memcache layer to cache all the whole output and add an additional instance cache which uses the memory of the instance. This can simply be done by adding a module global dict and adding your key/vals cache there. But you can also use a LRUCaching libraries so you don't overload your instances.
Finally the cheapest would be to use a cdn and point the origin to your app engine app, if your output doesn't require modification too frequently you could cache these results for short or long time.
Here is a complete blog post about instance caching by Ben Kamens: http://bjk5.com/post/2320616424/layer-caching-in-app-engine-with-memcache-and-cachepy
Upvotes: 2