有多少个线程可以读取和写入硬盘? [英] How many threads for reading and writing to the hard disk?

查看:281
本文介绍了有多少个线程可以读取和写入硬盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个收集硬盘驱动器所有文件的列表的应用程序 然后它也会将文件写入硬盘.

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 is the optimum number of concurrent threads that will do this task ?

我的意思是我应该有多少个线程才能读取硬盘驱动器而不制作硬盘驱动器 之所以变慢,是因为有这么多线程正在同时读取它.

I mean how many threads should i have that read the hard drive without making the hard drive to get slow because so many threads are reading it concurrently.

谢谢!

推荐答案

首先,我说一个!

实际上取决于要读取的数据是否需要复杂的计算以进行详细说明.在这种情况下,实例化一个以上线程来阐述不同的磁盘数据可能会很方便;但这仅在同一系统上有多个CPU的情况下方便.

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.

否则,一个以上的线程会使HDD承受不必要的压力:从不同线程进行的并行读取将发出 seek 操作来读取文件块(*),从而增加了开销,可能会减慢HDD的运行速度.系统,具体取决于读取的文件数和文件大小.

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.

顺序读取文件.

(*)操作系统实际上试图顺序存储相同的文件块,以加快读取操作的速度.磁盘会发生碎片,因此非顺序碎片需要进行寻道操作,这实际上需要更多的时间来尊重同一位置的读取操作.尝试并行读取多个文件,由于单个文件块是连续的,而多个文件块可能不是连续的,因此会引起一堆查找.

(*) 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.

这篇关于有多少个线程可以读取和写入硬盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆