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.
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.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
i.e. first letter / first two letters / full username
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.