平行File.Read比顺序读取速度更快? [英] Is Parallel File.Read Faster than Sequential Read?

查看:199
本文介绍了平行File.Read比顺序读取速度更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是平行 File.Read 使用PLINQ /并口可以更快?我的代码如下(.NET 4.0):

I just wonder is parallel File.Read using PLINQ/Parallel can be faster? My code is as follows ( .Net 4.0):

public static void ReadFileParallel(List<string> fileName)
{
   Parallel.Foreach(fileName, file=>File.Read(file));
}

public static void ReadFilePLINQ(List<string> fileName)
{
    fileName.AsParallel().foreach(file=>File.Read(file));
}



我之所以问这个是因为我认为这个文件读取IO约束,这样做平行无助,对吗?

The reason I ask this is because I thought that file reading is IO bound, so doing parallel won't help, am I right?

推荐答案

这要看情况。

如果您的文件是在不同的地点,不同的网络共享,或者在不同的物理硬盘驱动器,那么,并行装载可能会有所帮助。如果他们是一个旋转的硬盘驱动器,并行读取文件可能会显著伤害你的性能,因为额外的寻道时间,你可能会从这些并行读取招致

If your files were in different locations, on different network shares, or on different physical hard drives, then yes, parallel loading will probably help. If they're on a single spinning hard drive, reading the files in parallel will probably hurt your performance significantly due to the extra seek time that you will likely incur from these parallel reads.

如果你的文件是SSD上,你可能会得到略少的表现,但是这将取决于它们的大小多少你在并行读取文件,什么是。我想,在某个特定文件大小阈值和并行读取数,性能将显著下降。很难说的,一个没有一些试验。

If your files are on an SSD, you will probably get slightly less performance, but it would depend on how many files you're reading in parallel and what their sizes are. I imagine that at a certain file size threshold and number of parallel reads, performance will drop significantly. Hard to tell on that one without some experimentation.

这篇关于平行File.Read比顺序读取速度更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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