阅读背景:

将Cloudfront与动态图像大小和S3存储集成在一起

来源:互联网 

I've been reading a lot about dynamic image manipulation, storage and content delivery, the company I'm working for already uses AWS for some of their services.

我读过很多关于动态图像处理、存储和内容交付的文章,我为之工作的公司已经在使用AWS的一些服务。

The application I'm working on, store document images to a S3 bucket (not limited to), and i need to display them on demand.

我正在处理的应用程序将文档图像存储到S3桶中(不限于),我需要按需显示它们。

The first version of this application, stored the images locally and performs the image manipulation on-demand on the same server.

该应用程序的第一个版本,在本地存储图像,并在同一服务器上按需执行图像操作。

Now, the documents storage has increased and a lot of images are being stored, all this via web application, this means that one user may upload say 100+ images and the server needs to process them as fast as it can.

现在,文档存储增加了,许多图像被存储,所有这些都通过web应用程序,这意味着一个用户可能上传100多个图像,服务器需要尽可能快地处理它们。

That's why the images are uploaded to an EC2 instance and they are streamed to a S3 bucket internally, that's how we save the original image in the first place, no thumbnails here to speed up the uploading process.

这就是为什么图像被上载到EC2实例,并在内部流到S3桶中,这就是我们首先保存原始图像的方式,这里没有缩略图来加速上传过程。

Then a different user may want to preview this images or see them in original size, this is why i need to dynamically re-size them, i will implement Cloudfront for the image caching after they are re-sized, and here comes the issue.

然后,另一个用户可能想要预览这些图像或查看它们的原始大小,这就是为什么我需要动态地重新调整它们的大小,我将在它们被重新调整大小后实现Cloudfront以进行图像缓存,这里有一个问题。

The workflow is like this:

工作流程如下:

1. User Request CDN image
 2.a Cloudfront Serves the cached image
 2.b Cloudfront request the image to a custom origin if its not cached
  3. The origin server query S3 for the image
    4.a If the image size exists on S3
     5. Return the image to Cloudfront, Cache and return to user
    4.b If the image size does not exists on S3
     5. Generate a image size from the original S3 image
     6. Save the new size to S3
     7. Return the new size to Cloudfront, Cache and return to user

The custom origin is responsible of creating the missing image size and save it to S3, the Cloudfront can use the cached image or request this new image size to S3 as it now exists.

自定义起源负责创建丢失的图像大小并将其保存到S3中,Cloudfront可以使用缓存的图像或请求新的图像大小到S3中,因为它现在存在。

I think this is possible, as i already read a lot of documentation about it, but i still haven't found documentation of someone who has made this before.

我认为这是可能的,因为我已经读了很多关于它的文档,但是我仍然没有找到以前做过这个的人的文档。

Does this looks like a good way of handle the image manipulation, has anyone saw any documentation about how to do this.

这看起来像一个很好的处理图像操作的方法吗?有人看过关于如何操作的文档吗?

I'm a PHP developer but i might be able to implement a non-PHP solution in favor of performance on the image server.

我是一名PHP开发人员,但我可能能够实现非PHP解决方案,以提高映像服务器的性能。

1 个解决方案

#1


2  

If you are open to non-PHP based solutions https://github.com/bcoe/thumbd is a good option since it already integrates S3, etc. However you will need to know the sizes you need ahead of time. I would recommend such an approach rather than generating sizes on the fly since it means faster response times for your user. Your user will not have to wait while the new size is being generated. Storage on S3 is incredibly cheap and so you will not be wasting any $$ by creating multiple sizes either.

如果您对基于非php的解决方案开放,那么https://github.com/bcoe/thumbd是一个不错的选择,因为它已经集成了S3等等。我建议采用这种方法,而不是动态生成大小,因为这意味着用户的响应时间更快。在生成新大小时,用户不必等待。S3上的存储非常便宜,因此创建多个大小也不会浪费任何金钱。


分享到: