How many threads for reading and writing to the hard disk?

后端 未结 7 2261
清酒与你
清酒与你 2021-02-14 16:32

i am developing an application that gathers a list with all the files of the hard drive and also afterwards it does write files to the hard drive.

I want to ask : what i

7条回答
  •  礼貌的吻别
    2021-02-14 16:43

    Never process IO-dense operations concurrently. It's slower because the disk probe wastes a lot of time on switching between different threads/files.

    What shall I do if I have a few threads within IO operations? Produce the operations concurrently, and execute them single-threaded. We have a container, like a ConcurrentQueue(or a thread-safe queue written by yourself), and there are 10 threads, will read from these files 1.txt 2.txt ... 10.txt. You put the "reading-requests" in the queue concurrently, another thread deals with all the requests(open 1.txt, get what you want, and continue with 2.txt), the disk probe will not be busy with switching between threads/files in this case.

提交回复
热议问题