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

后端 未结 7 2259
清酒与你
清酒与你 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:52

    At first, I say one!

    It actually depends whether the data to read need complex computations for being elaborated. In this case, it could be convenient to instantiate more than one thread to elaborate different disk data; but this is convenient only if you have a multiple CPU on the same system.

    Otherwise, more than one thread make the HDD more stressed than necessary: concurrent reads from different threads will issue seek operations for reading the file blocks(*), introducing an overhead which could slow down the system, depending on the number of files read and the size of the files.

    Read the files sequentially.

    (*) The OS really tries to store the same file blocks sequentially in order to speed up the read operations. Disk fragmentation happens, so non-sequential fragments requires a seek operation which required really more time respect the read operation in the same place. Try to read multiple files in parallel, will cause a bunch of seeks because single file blocks are contiguous, while multiple files blocks could be not contiguous.

    0 讨论(0)
提交回复
热议问题