J
J
Julia2017-11-12 21:59:11
*nix-like systems
Julia, 2017-11-12 21:59:11

How does the number of files affect server performance?

I searched but did not find a clear answer, how the number of directories and files will affect the operation of the server and how noticeable the difference will be if there is, with the number of directories about 300 thousand, each with several (up to 20) files. I already understood that you can’t put them all in one directory, but what if they are divided into directories? How relevant is this question, to say think about storing files on another server.
and the second question is related. when accessing the site, they usually process the cnc-url through php and look in the database, I always had a question why not create real directories and put a php file with id in them, etc., so that later you can quickly find the data in the database.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
DevMan, 2017-11-12
@taynoeya

the number of files in itself (even in the same directory) does not affect performance in any way.
but, for example, when receiving a listing of such a directory or its backup, I will experience brakes.

S
Saboteur, 2017-11-12
@saboteur_kiev

1. The speed of working with a bunch of files is theoretically the same as with the database. But the caching of the file system and the database goes differently. And if, when accessing a table, it is cached all at once, then it is not so easy to cache 300,000 files / directories.
2.

When accessing the site, they usually process the cnc-url through php and look in the database, I always had a question why not create real directories and put a php file with id, etc. in them, so that later you can quickly find the data in the database."

Because the ID of the file is quite difficult to decompose into directories in such a way that it is even. files can be added and removed inconveniently, as a result, 100 files can end up in one directory, 100 thousand in another, and it will not work to redistribute all this on the go. Therefore, it is much easier to distribute files not depending on the ID, but depending on the contents of the folders, and the path to the file is already stored in the database in which there is an ID.

S
Sanes, 2017-11-12
@Sanes

In short, it does. No one will tell you how noticeable it will be, there are many conditions.
The database also consists of files.

A
Alexander Shapoval, 2017-11-12
@AlexanderShapoval

Julia , if the CNC field in the database is indexed, then the search for it will be fast enough.
If we are talking about small business card sites, then it doesn’t matter what to do with storing data, in files or in a database. If you make large sites (blogs, registration, comments, product catalog) - then already at the database design stage - this question disappears by itself. Read about relational databases. It is impossible to organize this on files, since there are relationships between the fields of the database, and they cannot be done between files. Complex SQL queries cannot be applied to files.
In addition, modern databases are powerful software focused on reliability and speed.
I recommend watching a series of videos with HightLoad ++. Many reports about services withstanding high loads

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question