多线程对IO绑定操作有意义吗? [英] Does multithreading make sense for IO-bound operations?

查看:242
本文介绍了多线程对IO绑定操作有意义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行许多磁盘操作时,多线程是有帮助,阻碍还是没有作用?

When performing many disk operations, does multithreading help, hinder, or make no difference?

例如,将许多文件从一个文件夹复制到另一个文件夹时.

For example, when copying many files from one folder to another.

说明:我知道执行其他操作时,并发显然会有所作为.如果任务是打开图像文件,转换为另一种格式然后保存,则可以在进行图像操作的同时执行磁盘操作.我的问题是,仅执行磁盘操作时,是否同时对磁盘操作进行排队和响应会更好.

Clarification: I understand that when other operations are performed, concurrency will obviously make a difference. If the task was to open an image file, convert to another format, and then save, disk operations can be performed concurrently with the image manipulation. My question is when the only operations performed are disk operations, whether concurrently queuing and responding to disk operations is better.

推荐答案

到目前为止,大多数答案都与OS调度程序有关.但是,我认为还有一个更重要的因素会导致您的回答.您要写入单个物理磁盘还是多个物理磁盘?

Most of the answers so far have had to do with the OS scheduler. However, there is a more important factor that I think would lead to your answer. Are you writing to a single physical disk, or multiple physical disks?

即使与多个线程并行...将IO单个物理磁盘本质上也是一种串行化操作.每个线程都必须阻塞,以等待机会访问磁盘.在这种情况下,多个线程可能毫无用处……甚至可能导致争用问题.

Even if you parallelize with multiple threads...IO to a single physical disk is intrinsically a serialized operation. Each thread would have to block, waiting for its chance to get access to the disk. In this case, multiple threads are probably useless...and may even lead to contention problems.

但是,如果您要将多个流写入多个物理磁盘,则同时处理它们将使您的性能得到提升.对于托管磁盘,例如RAID阵列,SAN设备等,尤其如此.

However, if you are writing multiple streams to multiple physical disks, processing them concurrently should give you a boost in performance. This is particularly true with managed disks, like RAID arrays, SAN devices, etc.

我认为该问题与OS调度程序没有太大关系,因为它与您写入的磁盘的物理方面有更多关系.

I don't think the issue has much to do with the OS scheduler as it has more to do with the physical aspects of the disk(s) your writing to.

这篇关于多线程对IO绑定操作有意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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