Linux 中单个文件夹中有 200,000 个图像,性能问题与否?

发布于 2024-09-29 05:43:10 字数 209 浏览 4 评论 0原文

我有一个 php/mysql 网站,在单个文件夹(linux 服务器) 中包含超过 200,000 图像。我认为我永远不需要在文件资源管理器中看到它们,而是可以在网站上的各个页面上查看它们。它们仅显示在网站的产品页面中。 文件系统是ext3。那么将它们保存在单个文件夹中是否明智?它会降低网站的性能吗?

I have a php/mysql website with over 200,000 images in single folder (linux server). I don't think, that I will never need to see them in file explorer, instead they will be viewed on website on their individual pages. They are just displayed in product page on website. File system is ext3. so is it wise to save them in single folder? can it slow down the site's performance?

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

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

发布评论

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

评论(6

此刻的回忆 2024-10-06 05:43:10

Ext3使用树来保存目录内容,因此它处理单个目录中大量文件的能力优于那些具有线性目录列表的文件系统。
在这里您可以阅读用于保存目录的树的描述内容。

然而,200K 文件仍然是一个巨大的数字。根据文件名的前 n 个字符将它们移动到子目录中是合理的。这种方法允许您仅保留文件名而不是目录名,并且当您需要访问该文件时,您知道在哪里(在哪个子目录中)查找它。

Ext3 uses tree to hold directory contents, so its capability to handle a large number of files in a single directory is better than that of those file systems with linear directory listings.
Here you can read the description of the tree used to keep directory contents.

However, 200K files is still a huge number. It's reasonable to move them into subdirectories based on first n characters of file names. This approach lets you keep only file names and not directory names, and when you need to access the file, you know where (in which subdirectory) to look for it.

将军与妓 2024-10-06 05:43:10

我知道选择了一个答案,出于兴趣,我想添加一个提高性能的解决方案

如果目录列表每次都返回所有结果,那么每次查询目录列表将花费最大的开销。

您可以通过将列表存储在索引数据库(例如 SQLite)中并仅从那里查询结果来提高性能。您可以选择记录的子集并通过这种方式更轻松地实现分页,并且也可以过滤结果。

I know an answer was chosen, I want to add a solution on improving the performance, for interest

Querying the directory listing each time will cost the most overhead, if the directory listing returns all results every time.

You can improve performance by storing the listing in an indexed database (say SQLite) and just query the results from there. You can select a subset of records and implement pagination much easier this way, and filter the results too.

凌乱心跳 2024-10-06 05:43:10

文件系统决定性能,200,000 个没有索引的图像会降低 ext2(或 NTFS)的性能

file systems determine performance, and 200,000 images without indexing will slow down performance in ext2 (or NTFS)

各空 2024-10-06 05:43:10

很可能在将来的某个时候,您可能想做一些将所有图像转储到一个文件夹中会对您造成伤害的事情,或者会发生一些意想不到的事情,并且您会后悔这样做。

另一方面,将文件分成几个文件夹似乎没有太多缺点,除了增加处理它们的复杂性之外。

性能会根据您的文件系统、其配置和访问模式而有所不同。我认为,如果将文件拆分到多个文件夹之间,性能会明显变差,这会很奇怪。

所以我想说,分成不同的文件夹......

It's quite probable that some time in the future you might want to do something where having all the images dumped in a single folder will hurt you, or something unexpected will happen and you will regret doing it that way.

On the other hand, having the files split into several folders doesn't seem to have many disadvantages, besides added complexity in dealing with them.

Performance will vary depending on your filesystem, its configuration and your access patterns. I believe it would be quite strange for performance to be perceptibly worse if splitting the files between multiple folders.

So I'd say, split into different folders...

巨坚强 2024-10-06 05:43:10

您可能会对这篇有关 Web 场景的 ext2 变体的论文感兴趣:hashFS:应用哈希进行优化用于小文件读取的文件系统

对于 Web 场景(论文中所述的假设),我们发现平面文件集(目录中的文件较多)比深层文件集(更深的目录树)具有更好的 ext2 性能。

诚然,回想起来,评估应该更广泛。但它可能值得一读。

This paper over an ext2 variant for web scenarios might interest you: hashFS: Applying Hashing to Optimize File Systems for Small File Reads.

We have seen a better ext2 performance with a flat file set (more files in a directory) than a deep file set (deeper directory tree) for a web scenario (assumptions stated in paper).

Granted, in retrospect the evaluation should have been more extensive. But it might be worth reading.

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