本文介绍了目录中的文件太多(在Windows和Linux上)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,在目录中放置太多文件可能会在Linux和Windows中导致性能问题.这是真的?如果是这样,避免这种情况的最佳方法是什么?

I was told that putting too many files in a directory can cause performance problems in Linux, and Windows. Is this true? And if so, what's the best way to avoid this?

推荐答案

根据这篇Microsoft文章,目录的查找时间与条目数的平方成正比. (尽管那是针对NT 3.5的错误.)

According to this Microsoft article, the lookup time of a directory increases proportional to the square of the number of entries. (Although that was a bug against NT 3.5.)

软件论坛上的老乔尔上也提出了类似的问题.一个答案是,性能似乎下降了1000到3000个文件,而一张海报则达到了18000个文件的硬限制.还有一篇文章声称可以存储300,000个文件,但是随着8.3个文件名全部用完,搜索时间迅速减少.

A similar question was asked on the Old Joel on Software Forum. One answer was that performance seems to drop between 1000 and 3000 files, and one poster hit a hard limit at 18000 files. Still another post claims that 300,000 files are possible but search times decrease rapidly as all the 8.3 filenames are used up.

为避免目录过大,请创建一个,两个或多个级别的子目录,然后将文件哈希到其中.最简单的哈希使用文件名的字母.因此,假设您选择了3个嵌套级别,则将以abc0001.txt开头的文件放置为a \ b \ c \ abc0001.txt. 3可能会过大-在每个目录中使用两个字符会减少嵌套级别的数量.例如ab\abc0001.txt.如果您预期任何目录都远远超过ca,则只需要转到两个嵌套级别即可. 3000个文件.

To avoid large directories, create one, two or more levels of subdirectories and hash the files into those. The simplest kind of hash uses the letters of the filename. So a file starting abc0001.txt would be placed as a\b\c\abc0001.txt, assuming you chose 3 levels of nesting. 3 is probably overkill - using two characters per directory reduces the number of nesting levels. e.g. ab\abc0001.txt. You will only need to go to two levels of nesting if you anticipate that any directory will have vastly more than ca. 3000 files.

这篇关于目录中的文件太多(在Windows和Linux上)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 23:19