I would like to ask some questions about building directories and storing files in them (pictures, for example).
Before addressing, I read quite a few different articles and I had some questions.
It is not a secret for anyone that for large projects it is not advisable to throw user-uploaded files into one folder and therefore you need to scatter them in directories, but how to do it correctly?
Many advise doing this mark. way: I will briefly describe, generate the file name using md5
hash. Then, take the first 2 characters from the name and create a folder and put all the files that start with the same characters, in this way we can create 256 folders in which, for example, we can place 1000 files. Of course, you can make nested levels of 3 and 4 characters of 5 and 6, and so on.
But I can not understand what will happen if one of the folders clogs much earlier than the others? How, then, to be?
My version that came to mind (I think I am not the first): Create a folder with the current year number, for example, then the current month and create a folder with the day of the month in the folder with the month number and create a folder with the name 1 in it and hammer it until there are 1000 files in it, then we create a folder with the number 2 and we hammer in it, well and in the same spirit and further.
It turns out that if we store up to a thousand folders in a folder and there are up to a thousand files in these folders, then we can store up to 30,000,000 files in one folder that is called the date of the month. After the month is over we move to another, the year is over, goes to another ... The file system in this case will not have to rake tons of files, the maximum number of files with which it will have to work is 1000
For clarity: 2015/04/15/1
Scoring a folder with the name 1 to 1000 files, then creating a folder with the name 2, after 3, and so on until 1000
The day is over, then we create a folder 16 in folder 04 and then work on the described principle. Of course, folders are created only when files are loaded into them.
What are your thoughts on this? What file storage structure do you use? And how is she good? Is the structure that I described acceptable from your point of view? What do you think about performance?