需要调整大小和存储的大批量图像
我正在使用 PHP 和 Graphicsmagick,并且有一群用户上传批量图像。
这些批次的图像从一张图像到数百张,甚至可能是一千张。
我需要将这些原始上传存储在 Amazon S3 上,还需要将每个图像的大小调整为三种不同的大小,并将这些副本存储在 Amazon S3 上。
这需要尽可能实时。
您将如何设计它以获得最佳性能?
I'm using PHP and Graphicsmagick and I have a bunch of users uploading batches of images.
These batches run from one image to hundreds, maybe even a thousand.
I need to store these original uploads on Amazon S3 and I also need to resize each image to three different sizes and also store those copies on Amazon S3.
This needs to be as realtime as possible.
How would you architect this for best performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现起来非常简单。当用户上传图像时,将其添加到(lpush)消息队列。当您将消息添加到队列时,您不会因为工作(等待)而打扰网站用户,而是离线执行。我会选择 redis,因为它非常强大、快速、易于使用。您应该研究一下 Redis,因为您还可以使用它来满足您的缓存需求,甚至更多。这很好。接下来,您生成几个工作进程,它们除了处理(blpop)队列中的消息(逐个)。他们从队列中获取消息,执行工作(调整图像大小),完成后从队列中获取下一条消息。就是这么简单而且非常快。特别是如果您使用编译为 C 的 PHP 扩展(C 是非常快的语言),例如 phpredis。
PS:很好的解释redis的入门教程=> http://simonwillison.net/static/2010/redis-tutorial/(必须阅读;))
Pretty simple to achieve. When the user uploads an image add it to(lpush) the message queue. When you add a message to the queue you are not bothering the user of your website with the work(waiting), but instead do it offline. I would go for redis, because it is very powerful, fast, easy to use. You should look into redis because you can also use it for your caching needs and even more. It is nice. Next you spawn a couple of worker processes who do nothing else but process(blpop) the message in the queue(one by one). They get a message from the queue, do there job(image resizing) and when done get a next message from the queue. It is that simple and very fast. Especially if you use a PHP extension which compiles to C(C is very fast language) like for example phpredis.
P.S: good introductory tutorial explaining redis => http://simonwillison.net/static/2010/redis-tutorial/ (must read ;))