姜戈 + S3 (boto) + Sorl 缩略图:优化建议

发布于 2024-10-30 19:51:31 字数 420 浏览 8 评论 0原文

我在我正在开发的 Django 站点上使用 S3 存储后端,既可以减少 EC2 服务器的负载,也可以允许多个 Web 服务器(冗余、负载平衡)访问同一组上传的媒体。

我们的模板中使用了 Sorl.thumbnail (v11) 模板标签,以允许灵活的图像调整大小/裁剪。

在富媒体页面上的性能不是很好,当第一次访问包含需要生成缩略图的页面时,请求甚至会超时。

据我所知,这是由于 sorl 缩略图检查/从 S3 下载原始图像(可能很大且高分辨率),以及渲染/检查/上传缩略图所致。

您认为此设置的最佳解决方案是什么?

我看到过除了 S3 副本之外还存储文件本地副本的建议(当使用几个服务器进行负载平衡时效果不太好)。我还看到它建议存储 0 字节文件来欺骗 sorl.thumbnail。

还有其他建议或更好的方法来解决这个问题吗?

I am using S3 storage backend across a Django site I am developing, both to reduce load from the EC2 server(s), and to allow multiple webservers (redundancy, load balancing) access the same set of uploaded media.

Sorl.thumbnail (v11) template tags are being used in our templates to allow flexible image resizing/cropping.

Performance on media-rich pages is not very good, and when a page containing thumbnails needing to be generated for the first time is accessed, the requests even time out.

I understand that this is due to sorl thumbnail checking/downloading the original image from S3 (which could be quite large and high resolution), and rendering/checking/uploading the thumbnail.

What would you suggest is the best solution to this setup?

I have seen suggestions of storing a local copy of files in addition to the S3 copy (not to great when a couple of server are being used for load balancing). Also I've seen it suggested to store 0-byte files to fool sorl.thumbnail.

Are there any other suggestions or better ways of approaching this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悸初 2024-11-06 19:51:31

sorl 缩略图现在在创建时考虑了远程慢速存储。然而,缩略图的第一次创建是通过查询存储来完成的,例如首先从模板访问,但之后引用被缓存在键值存储中。您仍然需要第一次查询和创建,一个解决方案是在上传图像时使用具有相同选项的低级 api sorl.thumbnail.get_thumbnail。当图像上传时,将此缩略图创建作业添加到类似 celery 的队列中。

sorl thumbnail is now created with remote slow storages in mind. The first creation of the thumbnail is however done quering the storage, for example first accessed from template, but after that the references are cached in a key value store. Still you need the first query and creation, well one solution is to use the low level api sorl.thumbnail.get_thumbnail with the same options when the image is uploaded. When the image uploaded add this thumbnail creation job to a que like celery.

油饼 2024-11-06 19:51:31

您可以使用 Sorlery。它结合了 sorl 和 celery 通过工作人员创建缩略图。非常小心不要在工作线程之外进行任何文件系统访问。

可以通过将 THUMBNAIL_DUMMY_SOURCE 设置为适当的占位符来控制立即返回的缩略图(在工作人员有机会之前)。

第一次请求缩略图时会创建作业,后续请求将提供虚拟图像,直到工作线程完成。

You can use Sorlery. It combines sorl and celery to create thumbnails via workers. It's very careful not to do any filesystem access outside of the worker thread.

The thumbnail returned immediately (before the worker has had a chance) can be controlled by setting your THUMBNAIL_DUMMY_SOURCE to an appropriate placeholder.

The job is created the first time the thumbnail is requested, subsequent requests are served the dummy image until the worker thread completes.

紫﹏色ふ单纯 2024-11-06 19:51:31

与@Aidan 的解决方案几乎相同,我对 sorl-thumbnail 做了一些调整。我还用 celery 预先生成缩略图。我的代码在这里 sorl_thumbnail-async

但我开始知道 easy_thumbnails 正是我想要做的,所以我在当前的项目中使用它。您可能会发现有关该主题的有用的简短帖子是 这里

Almost same as @Aidan's solution, I have made some tweaks on sorl-thumbnail. I also pre-generate thumbnails with celery. My code is here sorl_thumbnail-async

But I came to know easy_thumbnails does exactly what I was trying to do, so I am using it in my current project. You might find useful, short post on the topic is here

很酷又爱笑 2024-11-06 19:51:31

到目前为止,我发现的最简单的解决方案实际上是这个第三方服务: http://cloudinary.com/

The easiest solution I've found so far is actually this third party service: http://cloudinary.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文