一个目录中的许多文件会导致Apache下的加载时间更长吗? [英] Do many files in a single directory cause longer loading time under Apache?

查看:64
本文介绍了一个目录中的许多文件会导致Apache下的加载时间更长吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使似乎存在一些重复的问题,我也认为这是独特的.我不是问是否有任何限制,仅是关于Apache上下文中的性能缺陷.还是一般的Unix文件系统.

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.

让我们说一下我是否从Apache服务器请求文件

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"?

我问的原因是我的PHP应用程序即时生成了图像.

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

一旦创建,它将放置在PHP脚本由于ModRewrite触发的位置.如果文件存在,Apache将跳过整个PHP执行过程,而是直接提供静态映像.如果您希望以这种方式调用网关缓存,则可以使用这种方式.

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基本上有两件事要做:

Apache has basically two things to do:

  1. 检查文件是否存在
  2. 提供文件或将请求转发到PHP

到现在,我在这个目录中大约有25.000个文件,其中约8 GB.我预计未来几年它至少会增长10倍.

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.

尽管我在管理这些文件方面没有遇到任何问题,但我有一点感觉,当通过HTTP请求它们时,它会变得越来越慢.所以我想知道这是否真的发生了,或者仅仅是我的主观印象.

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.

推荐答案

基于Berkeley FFS的大多数文件系统会由于多个间接级别而在一个目录中包含大量文件的情况下降低性能.

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.

我不了解HFS或NTFS等其他文件系统,但我怀疑它们很可能会遇到相同的问题.

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.

我认为这类似于md5 myfilename-00001产生(例如):e5948ba174d28e80886a48336dcdf4a4,然后将其放入名为e5/94/8ba174d28e80886a48336dcdf4a4的文件中.然后,将"myfilename-00001"映射到"e5/94/8ba174d28e80886a48336dcdf4a4"的映射文件.这个非优雅的解决方案可以达到我的目的,并且只需要一点代码.

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.

这篇关于一个目录中的许多文件会导致Apache下的加载时间更长吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆