Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On my website, users have files so I create a folder for each user when they register.

for example

/userdata/USERID

If site grows and I have thousands of users I might end up having too many user folders in one folder so i decided to split them up.

for example

/userdata/1/USERID (first thousand users)

/userdata/2/USERID (second thousand users)

My questions is how much folders should I put in one subfolder? Is 1000 in each a good idea? more? less? Just want to make sure things run smoothly.

share|improve this question

migrated from stackoverflow.com May 14 '11 at 11:49

This question came from our site for professional and enthusiast programmers.

3  
The answer to that depends entirely on the operating system & filesystem that your web host is using. –  jayp May 13 '11 at 16:17

3 Answers 3

up vote 2 down vote accepted

I always work to the rule of going for a maximum of ~1000 with ext2/ext3. I suspect that the choice of filesystem might affect your choice.

The absolute limit in ext3 is ~32k. Have a look for all of the gory details on Wikipedia: http://en.wikipedia.org/wiki/Ext3

In terms of a hashing algorithm for your directories I'd recommend using the last digit of the id. If you calculate $id % 10 and use that value it'll work a treat. That way you get an even distribution out of the box.

share|improve this answer
    
@James C, Can you please explain what hashing would be used for in this case? I'm not sure I understand. –  user80666 May 13 '11 at 16:26
    
"hashing" as in which user to store in which directory. I'm recommending that it'd look like 5/1234, 5/2345, 1/102, etc –  James C May 13 '11 at 16:39

It depends mostly on the file system you are using.

You'll probably find it easier to use a pattern rather then splitting on arbitrary numbers. CPAN, for instance, uses

U/US/USERNAME

i.e. first letter / first two letters / full username

share|improve this answer
    
Thanks for advice. On my site usernames can be changed, I would prefer not to have to move folders around so CPAN's approach may not be suitable for me. –  user80666 May 13 '11 at 16:25
    
@user, I'd highly recommend using the CPAN approach, or first_letter/second_letter/[etc]/full and just accept that you'll have to move a directory now and then. –  Chris S May 14 '11 at 13:43
    
moving folders in the same file system is just shifting the folder entry; you don't actually move any data –  mpez0 May 14 '11 at 15:38

If your usernames change infrequently, the CPAN mindset might still have an advantage. It's generally better to know for 90% of users where to drill down and find their content than to have to search N file structures looking for USERID.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.