提供大量图像的软件/系统?

发布于 2024-08-12 08:54:30 字数 614 浏览 9 评论 0原文

在高峰时段,我们需要提供大约 250/rps 的服务。我们正在做的是接受图像的 url,从内存缓存中提取图像,然后通过 Apache 返回它。

我们当前的系统是双核机器,内存为4GB:2GB用于memcache中的图像,2GB用于Apache;但我们在高峰时段看到了非常高的负载 (20-30)。据 Apache 报告,平均响应时间为每个请求 30-80 毫秒,这对于从内存提供的简单 Apache 请求来说似乎有点慢。

有更好的工具吗?从磁盘提供服务不是一个选择,因为 IO 等待阻碍了它,因此我们将其移至内存。 CDN 是如何做到的?

编辑:嗯,系统是这样工作的。一个请求进来,我们检查一个“队列”,看看我们之前是否见过这个请求,以及我们是否提供了图像(从磁盘......或内存)。如果没有,我们会在 memcached 队列中增加该请求的计数器,并且有工作机器实际生成图像,然后将其存储回主服务器上。因此,目前,当收到请求时,我们将检查 memcached 数据库是否存在,然后我们将连接到另一个数据库以获取实际的图像数据库。当图像位于磁盘上时,我们发现仅 file_exist 函数就需要 30 多毫秒才能完成,因此我们将其移动到内存中。如果我们将图像移动到 ramdisk,这会加快 file_exist 的速度,还是我们仍然需要首先检查是否应该寻找图像?

At our peak hour we need to serve around 250/rps. What we're doing is accepting a url for an image, pulling the image out of memcache, and returning it via Apache.

Our currently system is a dual-core machine with 4GB of memory: 2GB for the images in memcache and 2GB for Apache; but we're seeing a very high load (20-30) during our peak time. The average response time, as reported by Apache, is 30-80ms per request, which seems kind of slow for a simple Apache request served from memory.

Are there better tools for this? Serving from disk is not an option since the IO wait was holding it back, so we moved it to memory. How do CDN's do it?

EDIT: Well, the system works like this. A request comes in, we check a "queue" to see if we've seen this request before and if we have we serve the image(from disk...or memory). If not we increment the counter for that request in a memcached queue and there are worker machines that actually generate the image and then store it back on the main server. So, currently when a request comes in we're checking the memcached db if it exists then we'll connecting to another db for the actual image database. When the images were on disk we found that just the file_exist function would take 30+ ms to completed so we moved it to memory. If we moved the images to a ramdisk would this speed up the file_exist or would we still want a first check to see if we should even seek the image out?

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

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

发布评论

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

评论(2

芸娘子的小脾气 2024-08-19 08:54:30

你看过 nginx 吗?

根据 Netcraft 2009 年 5 月的数据,nginx 提供或代理了 3.25% 最繁忙的站点。它也可以从 memcached 提供服务

Have you looked at nginx?

According to Netcraft in May 2009 nginx served or proxied 3.25% busiest sites. It can serve from memcached too.

独夜无伴 2024-08-19 08:54:30

根据图像的大小,Apache 应该可以毫无问题地处理这个问题。我们有一个 Apache,每秒处理 2000 个请求,平均响应大小为 12K。该机器有 32GB 内存,因此我们所有的内容都会被缓存。

这里有一些调整技巧,

  1. 像worker一样使用线程MPM,打开很多线程(我们有256个)。
  2. 使用 mod_cache,以便所有图像都在内存中 为
  3. Apache 进程分配尽可能多的内存

当您说 memcache 时,您是指 memcached 服务器吗?运行 memcached 会更慢,因为 TCP 连接(即使是环回)的延迟比直接内存访问要大得多。

如果您可以将所有图像放入内存中,那么 RAM 磁盘也会有很大帮助。

Depending on size of your image, Apache should handle this with no problem at all. We have an Apache serving 2000 request/seconds, the average size of response is 12K. The machine has 32GB memory so all our content is cached.

Here are some tuning tips,

  1. Use threaded MPM like worker, with lots of threads open (We have 256).
  2. Use mod_cache so all the images will be in memory
  3. Allocate as much memory as possible to the Apache process

When you say memcache, do you mean the memcached server? Running memcached will be slower because the latency on TCP connection (even though it's loopback) is much larger than direct memory access.

If you can fit all your images in memory, a RAM disk will also help a lot.

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