0

我正在将 2MB 块中的约 280MB 数据写入 FileStream。

在一台机器上,这在 8 秒内完成。在我的机器上(具有类似的规格、SSD 等)我一直在尝试调试为什么它需要超过 40 秒并且它们是进度暂停。

我在从硬件设备返回数据时写入数据,但我发现有时,在流上调用 Write 可能需要很长时间才能返回。我在所有写入之间调用flush:

    Stopwatch stopwatch = Stopwatch.StartNew();
    _stream.Write(buffer, 0, buffer.Length);        
    stopwatch.Stop(); 
    Console.WriteLine("_stream.Write() " + stopwatch.ElapsedMilliseconds + "ms");             

    _stream.Flush(); 

输出:

_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 2ms
... snip 
_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 23233ms    <- not expecting this
_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 0ms
... snip 
_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 15852ms    <- or this
_stream.Write() 2ms
_stream.Write() 2ms
_stream.Write() 2ms
... snip 
_stream.Write() 2ms
_stream.Write() 25ms
_stream.Write() 2ms
_stream.Write() 2ms

这不是我所期望的

4

2 回答 2

2

我实际上怀疑这可能是您认为应该使其快速的原因。SSD可能是罪魁祸首。

所以这就是奇怪的地方。像 .net 这样的 SSD 有一个 GC。这是因为 SSD 与 HDD 不同,无法以与写入信息相同的方式删除信息。写入的最小单位远小于删除的最小单位。

有关更多信息,请搜索写入放大。

业界知道这一点,因此他们在 SATA 中开发了一项称为 TRIM 的功能。然而,我的研究表明,由于某些奇怪的原因,有一批 Corsair Force 3 在固件中禁用了 TRIM……

于 2013-02-08T18:02:16.340 回答
1

您总是可以在异步线程上运行写入,并在写入过程完成时回调?

于 2013-02-11T11:14:48.137 回答