What is the maximum amount of files to put in 1 folder for performance?

1

1

I have read in the past that is it good practice/performance to limit the amount of files you put in each folder, in this case it is user uploaded photos,

My site has around 1,000,000 user photos so far and growing daily so I structure the folders that photos are saved in to something like 9/8/5 so it puts X amount of photos per folder then starts putting into a new folder.

I know it is not a huge performance issue but I believe too many files does hurt seeking time

I am wanting to know what is a good amount of files to limit a folder to?

JasonDavis

Posted 2009-08-06T14:20:12.137

Reputation: 4 852

That greatly depends on the file system. – Joey – 2009-08-06T14:23:04.813

2What filesystem? What operating system? – Rob – 2009-08-06T14:23:05.533

It would be on a LAMP setup – JasonDavis – 2009-08-06T14:27:28.583

Depends on the filesystem. On an MS-DOS system with FAT fileystem I ran into performance problems at around 500-1000 files per directory. – None – 2009-08-06T14:33:19.527

Answers

1

Similar to this question.

Max

Posted 2009-08-06T14:20:12.137

Reputation:

3

I'd personally not worry too much about it but I'd personally change the file system to be stored in a date format.

Such as 2009/08/06.

That'll cut down on your daily amount at least by keeping it organized but your annual amount wouldn't change.

I've never really bothered with the amount I put in a folder, I just keep things organized.

LiamGu

Posted 2009-08-06T14:20:12.137

Reputation: 178

1

In ext3 filesystems you can have approx 32000 subdirectories in a directory:

For ext2 and ext3 the hard limit is 31998 due to EXT[23]_LINK_MAX being 32000 and each of those subdirectories (folders) has a link back to its parent, which began life with a link count of 2.

The limit for decent performance would likely be quite a bit less.

Also, structuring your data to avoid hitting such limits has other benefits, for example it makes easier to split a large data store across multiple volumes or even servers.

Paul Dixon

Posted 2009-08-06T14:20:12.137

Reputation: 643

0

At some point, you'll want to consider looking at MogileFS to store your files. Then you don't need to worry about file system limits, you get almost automatic replication, and it's fast. I can't say for sure if you are at the point with a million pictures, but it's worth looking at. May be easier, in any case, than rolling your own solution just to deal with file system limits.

ChrisInEdmonton

Posted 2009-08-06T14:20:12.137

Reputation: 8 110

0

I usually split so there's 10000 files per folder. It's fairly easy if you have have some sort of numeric identifier for your files.

As an example, if you're using a file with identifier = 9876543, you could use the following process:

  • Formats number with 12 digits (000009876543)
  • Uses the first eight digits as a folder identifier (0000/0987)
  • Save the file as (0000/0987/myfile.jpg)

While most file systems allow you to keep more files in a single folder, this makes things more organized, it'll be easier if you eventually need to split in multiple volumes, and if you're using Windows it also makes sure Explorer won't freeze trying to read 1M files. :)

Badaro

Posted 2009-08-06T14:20:12.137

Reputation: 543