douben6670
2017-04-18 15:52
浏览 20
已采纳

在Apache下,单个目录中的许多文件会导致更长的加载时间吗?

Even if there seem to exist a few duplicate questions, I think this one is unique. I'm not asking if there are any limits, it's only about performance drawbacks in context of Apache. Or unix file system in general.

Lets say if I request a file from an Apache server

http://example.com/media/example.jpg

does it matter how many files there are in the same directory "media"?

The reason I'm asking is that my PHP application generates images on the fly.

Once created, it places it at the same location the PHP script would trigger due to ModRewrite. If the file exists, Apache will skip the whole PHP execution and directly serve the static image instead. Some kind of gateway cache if you want to call it that way.

Apache has basically two things to do:

  1. Check if the file exists
  2. Serve the file or forward the request to PHP

Till now, I have about 25.000 files with about 8 GB in this single directory. I expect it to grow at least 10 times in the next years.

While I don't face any issues managing these files, I have the slight feeling that it keeps getting slower when requesting them via HTTP. So I wondered if this is really what happens or if it's just my subjective impression.

图片转代码服务由CSDN问答提供 功能建议

即使似乎存在一些重复的问题,我认为这个问题也是独一无二的。 我不是在问是否有任何限制,只是关于Apache的上下文中的性能缺陷。 或者通常是unix文件系统。

假设我从Apache服务器请求文件

  http://example.com  /media/example.jpg

请问同一目录“media”中有多少个文件?

我问的原因是我的PHP应用程序动态生成图像。

创建后,它会将它放在PHP脚本因ModRewrite而触发的相同位置。 如果该文件存在,Apache将跳过整个PHP执行并直接提供静态图像。 如果你想以这种方式调用某种网关缓存。

Apache基本上有两件事要做:

  1. 检查 如果文件存在
  2. 提供文件或将请求转发给PHP

    直到现在,我有大约25.000个文件,大约8个 GB在这个单一目录中。 我希望它在未来几年至少增长10倍。

    虽然我没有遇到任何管理这些文件的问题,但我有一种轻微的感觉,即通过HTTP请求时它会变慢。 所以我想知道这是真的发生了什么,还是只是我的主观印象。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyun8891 2017-04-19 18:34
    已采纳

    Most file systems based on the Berkeley FFS will degrade in performance with large numbers of files in one directory due to multiple levels of indirection.

    I don't know about other file systems like HFS or NTFS, but my suspicion is that they may well suffer from the same issue.

    I once had to deal with a similar issue and ended up using a map for the files.

    I think it was something like md5 myfilename-00001 yielding (for example): e5948ba174d28e80886a48336dcdf4a4 which I then put into a file named e5/94/8ba174d28e80886a48336dcdf4a4. Then a map file mapped 'myfilename-00001' to 'e5/94/8ba174d28e80886a48336dcdf4a4'. This not-quite-elegant solution worked for my purposes and it only took a little bit of code.

    点赞 评论

相关推荐 更多相似问题