如何最好地在服务器之外调整图像大小

发布于 2024-07-08 02:02:40 字数 88 浏览 7 评论 0原文

我有一个用户上传图像的网站。 这些图像被调整为不同的尺寸。 我目前在我的服务器上执行此操作,但正在考虑在 AWS 或类似的东西上处理它。 这是一个好主意吗?

I have a site that users upload images to. Those images are resized to various dimensions. I currently do that on my server, but was thinking of processing that on AWS or something similar. Is that a good idea?

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

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

发布评论

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

评论(3

终陌 2024-07-15 02:02:40

我一直在使用 EC2 和专用服务器来执行类似的任务,这里有一些提示:

  1. 使用尽可能少的 IO。 如果您打算使用 ImageMagick 之类的东西,请知道写入磁盘会浪费 io 资源(除非您无论如何都想缓存它)。PHP/GD 允许您直接在 http 响应中发送 jpeg。

  2. 尽快释放 RAM:尽可能释放源代码和调整大小的图像。 消除服务器交换内存的可能性。

  3. EC2 的上下文切换速度非常慢。 所以尽量少尝试。 像 Gimp 这样的处理器非常慢(在专用处理器上需要 0.2 秒,在 EC2 上需要 7 秒)。此外,ImageMagick 非常慢。 如果可以的话,请使用 PHP/GD 进行所有处理。

  4. 记住设置最大内存。 您将需要内存中图像的两个副本(源图像和缩小图像)。

  5. 最后但并非最不重要的一点:从实时开始。 不要从 mysql 队列和外部守护进程的过度解决方案开始。 从长远来看,这些将很难维持。 因此,在建造火箭之前请先尝试实时。

祝你好运!

I've been using EC2 and dedicated servers for similar tasks, and here are some tips:

  1. Use as little IO as possible. If you intend on using things like ImageMagick, know that writing to disk is a waste of io resources (unless you want to cache it anyway.) PHP/GD lets you send jpeg directly in http response.

  2. Free RAM as soon as possible: release source and resized images whenever you can. Eliminate the chance of your server swapping out memory.

  3. EC2 is extremely slow with context switches. So try as little as possible. Processors like Gimp are -extremely- slow (a scale down that took 0.2 seconds on dedicated, took 7 seconds on EC2.) Also, ImageMagick is extremely slow, period. If you can, use PHP/GD for all of your processing.

  4. Remember to set maximum memory. You will need two copies of the image in memory (source and scaled down.)

  5. Last but not least: start with real time. Don't start with overkill solution of mysql queues and external daemons. These will prove hard to maintain in the long run. So give real-time a try before you build a rocket.

Good luck!

安人多梦 2024-07-15 02:02:40

您需要弄清楚处理图像需要多少时间以及预计处理多少时间。

如果您的服务器可以在峰值负载下实时处理它们,那么现在不用担心。

我想说,如果你的服务器可以处理负载,但不是实时的,我会在服务器上构建一个队列,并让 cron 作业或守护进程处理请求之外的图像。 如果队列开始增长或者您的服务器开始过载,您可以将其移动到另一台计算机。

如果其他机器无法处理负载,您应该能够轻松地添加更多机器来处理队列。

那时,您可能已经相当成熟,可以开始利用 EC2 来实现按需扩展等功能。

You need to figure out how much it takes to process your images and how many you anticipate processing.

If your server can process them in real time with your peak load, don't worry about it right now.

I'd say that if your server can handle the load, but not in real time, I'd build a queue on the server and have a cron job or daemon process the images outside of the request. If the queue starts growing or your server starts getting overloaded, you can move it to another machine.

If that other machine can't handle the load, you should be able to, somewhat easily, add more machines to process the queue.

At that point, you're probably pretty sophisticated and you can start taking advantage of EC2 for things like scaling on demand.

随波逐流 2024-07-15 02:02:40

如果您预计需要大规模扩展和加载,您可以使用 EC2 服务器来调整大小并将其存储在 S3 中。
最终,这将取决于很多因素,具体取决于您的增长和预算。 您的服务器当前负载是多少?是否已接近容量极限? 调整图像大小所需的 CPU 大小和数量是多少?它们可以缓存和重用吗? 图像是如何使用的?

You could use an EC2 server to do the resizing and store them in S3 if you anticipate the need for a large scale out and load.
Ultimately, It would would depend on alot of factors depending on your growth and budget. What is the current load on your server and are you near capacity? What is the size and amount of CPU it takes to resize the images and can they be cached and reused? How are the images used?

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