将照片存储在 Blobstore 中或作为 Blob 存储在数据存储中 - 哪个更好/更高效/更便宜?

将照片存储在 Blobstore 中或作为 Blob 存储在数据存储中 - 哪个更好/更高效/更便宜?

问题描述:

我有一个应用程序,其中特定类型的每个 DataStore 实体都可以有许多与之关联的照片.(想象一个汽车销售网站——一辆车有多张照片)

I have an app where each DataStore Entity of a specific kind can have a number of photos associated with it. (Imagine a car sales website - one Car has multiple photos)

最初因为所有数据都来自另一个站点,所以我只能将照片存储为 DataStore Blob,但现在可以以编程方式编写 BlobStore 项目,我想知道是否应该更改我的设计和将照片存储为 BlobStore 项目?

Originally since all the data is being sourced from another site, I was limited to having to store the photos as DataStore Blobs, but now that its possible to write BlobStore items programatically, I'm wondering if I should change my design and store the photos as BlobStore items?

那么,问题是:
将照片存储在 Blobstore 中还是作为数据存储区中的 Blob 存储更好"?两者都是可能的解决方案,但哪种方法更好/更便宜/最有效,为什么?

So, the question is:
Is it 'better' to store the photos in the Blobstore, or as Blobs in the Datastore? Both are possible solutions, but which would be the better/cheaper/most efficient approach, and why?

与 Datastore 相比,从 BlobStore 提供的图像有几个优点:

Images served from BlobStore have several advantages over Datastore:

  1. 图像直接从 BlobStore 提供,因此请求不会通过 GAE 前端实例.因此,您可以节省前端实例的时间和成本.

  1. Images are served directly from BlobStore, so request does not go through GAE frontend instance. So you are saving on frontend instances time and hence cost.

BlobStore 存储成本大约是 Datastore 存储成本的一半(0.13 美元对 0.24 美元).使用 Datastore,您需要额外支付 get() 或 query() 费用.

BlobStore storage cost is roughly half of Datastore storage cost ($0.13 vs $0.24). With Datastore you'd additionally pay for get() or query().

BlobStore 自动使用 Google 缓存服务,因此唯一的成本是带宽成本(0.12 美元/GB).您也可以通过缓存控制在前端实例上设置它,但不同的是,这是为 BlobStore 自动完成的.

BlobStore automatically uses Google cache service, so the only cost is cost of bandwidth ($0.12/GB). You can also set this on frontend instance via cache control, but the difference is that this is done automatically for BlobStore.

BlobStore 中的图像可以通过 ImageService 提供,并且可以在飞,例如创建缩略图.转换后的图像也会自动缓存.

Images in BlobStore can be served via ImageService and can be transformed on the fly, e.g. creating thumbnails. Transformed images are also automatically cached.

Datastore 中的二进制 blob 大小限制为 1Mb.

Binary blobs in Datastore are limited to 1Mb in size.

BlobStore 的一个缺点是它没有访问控制.任何有 blob 网址的人都可以下载它.如果您需要 ACL(访问控制列表),请查看 Google Cloud Storage.

One downside of BlobStore is that it has no access controls. Anybody with an URL to blob can download it. If you need ACL (Access Control List) take a look at Google Cloud Storage.

更新:

成本明智的最大节省将来自正确缓存图像:

Cost wise the biggest saving will come from properly caching the images:

  1. 每张图片都应该有一个永久的 URL.
  2. 每个图像 URL 都应该使用适当的缓存控制 HTTP 标头:

  1. Every image should have a permanent URL.
  2. Every image URL should be served with proper cache control HTTP headers:

// 32M seconds is a bit more than one year 
Cache-Control: max-age=32000000, must-revalidate

您可以通过以下方式在 Java 中执行此操作:

you can do this in java via:

httpResponse.setHeader("Cache-Control", "max-age=32000000, must-revalidate");

更新 2:

正如 Dan 在评论中正确指出的那样,BlobStore 数据是通过前端实例提供的,因此可以通过用户代码实现访问控制.

As Dan correctly points out in the comments, BlobStore data is served via a frontend instance, so access controls can be implemented by user code.