.net 4.5中最大同时进行的I / O操作数是多少? [英] What is the maximum number of simultaneous I/O operations in .net 4.5?

查看:113
本文介绍了.net 4.5中最大同时进行的I / O操作数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用静态void,我可以使用多线程场景同时写入的最大文件数是多少,即:

What is the maximum number of files I can write simultaneously using a Multithreaded scenario, using static void, ie:

public static void WriteToXmlFile<T>(string filePath, T objectToWrite, bool append = false) where T : new()
{
    TextWriter writer = null;
    try
    {
        var serializer = new XmlSerializer(typeof(T));
        writer = new StreamWriter(filePath, append);
        serializer.Serialize(writer, objectToWrite);
    }
    finally
    {
        if (writer != null)
            writer.Close();
    }
}

这个静态void将从同时运行的多个任务中访问。我可以同时写入的文件数量是否有任何默认限制,或者我可以修改任何此类属性的任何方式?

This static void will be accessed from multiple tasks running simultaneously. Is there any default limit for the number of files I can write at the same time, or any way I can modify any such property?

推荐答案

这里的瓶颈将是硬件,而不是软件。磁盘驱动器上的磁头一次只能在一个位置。如果有多个线程告诉它同时执行操作,那么它不会更快地工作(并且可能会更慢地反复寻找新的块)。

The bottleneck here is going to be in hardware, not in software. The head on your disk drive can only be in one place at any one time. It isn't going to work any faster (and it is likely to work slower to to repeatedly seeking to new blocks) if there are multiple threads telling it to do stuff at the same time.

有用的并行程度将等于您拥有的物理驱动器数量。如果你有4个磁盘驱动器,你可以一次写出4个文件。

The degree of parallelziation that would be helpful is going to be equal to the number of physical drives that you have. If you have 4 disk drives, you can benefit from writing out 4 files at once.

当然值得注意的是,这里不需要多个线程,无论你是否想要执行并行写入。如果实际上有多个物理磁盘驱动器,则可以使用 asynchrony 而不是多个线程来实现并行性。

And it's of course worth noting that there is no need for more than one thread here, ever, regardless of whether you want to perform parallel writes or not. You can use asynchrony rather than multiple threads to achieve parallelism, if you actually have multiple physical disk drives.

这篇关于.net 4.5中最大同时进行的I / O操作数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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