问题
We have a web application in App Engine. I was wondering whether it is a good idea to move my static resources (i.e Images, CSS files, and JS files) out from App Engine and serve them from Google Cloud Storage.
My thinking here is two-fold:
1) We can get the advantages of a CDN with Google Cloud Storage. We can even configure metadata for each file to set expiration headers, gzip compression, etc. Also, by serving files from different domains we can have browsers download more content in parallel.
2) By off-loading some of the files from App Engine, the instance consumption is going to decrease (less requests to App Engine), so the costs will go down.
Am I right? Is this a wise move?
Thanks,
回答1:
Neither of these make sense.
1) App Engine has a CDN-like functionality with it's edge cache. Unfortunately, it's not well documented. There's a few Google I/O talks on it. Here's a start: http://eng.pulse.me/backend-tips-the-free-cdn/ There's another talk in Google I/O 2012 that you can find as well. Your static files will be served with the edge cache if they're accessed enough, so no need to move to GCS for this.
2) It's well documented that static files don't take instances. You've already read this, so you 'paranoia' is simply paranoia, and doesn't make sense. It's also very easy to test by uploading a new version onto app engine, accessing a static file, and checking for a new instance in the Admin.
回答2:
You are right, and the answer you accepted is wrong. The answer to your question from the official docs:
https://cloud.google.com/storage/docs/website-configuration
Hosting static assets for a dynamic website
You can use a Google Cloud Storage to host static assets for a dynamic website hosted, for example, in Google App Engine or in Google Compute Engine. Some benefits of hosting your static assets, like images or Javascript files, in a bucket include:
- Google Cloud Storage behaves essentially like a Content Delivery Network (CDN) with no work on your part because publicly readable objects are, by default, cached in the Google Cloud Storage network.
- Bandwidth charges for accessing content will typically cost less with Google Cloud Storage.
- The load on your web servers is lessened when serving the static content from Google Cloud Storage.
回答3:
Your intuition is right, here's the confirmation from Google docs:
The benefits of using Cloud Storage instead of serving directly from your app include:
Cloud Storage essentially works as a content delivery network. This does not require any special configuration because by default any publicly readable object is cached in the global Cloud Storage network.
Your app's load will be reduced by offloading serving static assets to Cloud Storage. Depending on how many static assets you have and the frequency of access, this can reduce the cost of running your app by a significant amount.
Bandwidth charges for accessing content can often be less with Cloud Storage.
Know that static files are definitely served using instance resources. It's true that edge cache comes into effect, but this does not simply remove the whole problem. Moving statics to GCS is the right way of doing this.
Note, however, that if you plan to serve your static files from GCS, you won't be able to properly map a (sub)domain to it over HTTPS (SSL) and you'll have to use a load-balancer or 3rd party CDN. In some cases this may prove to be more of a hassle. See here for details.
来源:https://stackoverflow.com/questions/19073038/should-i-move-my-static-resources-from-app-engine-to-google-cloud-storage