M
M
MrOnatsky2018-06-26 21:52:22
PHP
MrOnatsky, 2018-06-26 21:52:22

Will such a distribution of files by its id work?

Good afternoon. This is no longer a question, but so, to consult.
For some time I was thinking about the distribution of files by their id, and settled on this option:
1. Convert id from decimal to hexadecimal. The ID must be greater than or equal to 4096 for the resulting hexadecimal number to be greater than or equal to 4 in length.
2. The store consists of levels. Each level has 256 folders. As a result, 256^2 = 65536 folders. If we take a thousand files as the maximum optimal number of files in a folder, then in the end we have a storage for 65536000 files (1000 in each folder). For the name of the folder of the first level, "cut off" the last 2 digits of id, for the second level, 2 more last digits. In this way we will achieve an even distribution. Here is an example of a path definition:

$dir = substr($hex, -2, 2) . '/' . substr($hex, -4, 2);

3. For the file name, we use its id and if you need to protect it from brute force for downloading, then add an arbitrary string to it (for example, a hash sum, the crc32 algorithm will be enough) and you can’t get the file simply by id.
Example: /e5/f5/83f5e5-r45c943k.jpg
Having done tests, with 10 million files, there were 152-153 files in each folder.
How do you like the option? Are there stones? Crooked? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2018-06-26
@RidgeA

I would stage
replaced the hash from id or some other value with MD5.
That would decide
and
And so, as for me, it seems normal

I
index0h, 2018-06-27
@index0h

Norm, though for generating id I would take the usual uuid v4. Look also towards solutions like mogilefs, you may not need your bike

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question