Write time to hard drive

616 views Asked by At

I realize this number will change based on many factors, but in general, when I write data to a hard-drive (e.g. copy a file), how long does it take for that data to actually be written to the platter after Windows says the copy is done?

Could anyone point me in the right direction to discover more on this topic?

2

There are 2 answers

0
Roy Longbottom On

You are right that there can be a delay between Windows indicating that data writing is finished and the last data actually written. Things to consider are:

  1. Device Manager, Disk Drive, Properties, Policies - Options for disabling Write Caching.

  2. You might be better off using Direct I/O so that Windows does not save it temporarily in File Cache.

  3. If your program writes the data, you can log what has been copied.

  4. If you are sending the data over a network, you are likely to have no control of when the remote system has finished.

  5. To see what is happening, you can set up Perfmon logging. One of my examples of monitoring:

http://www.roylongbottom.org.uk/monitor1.htm#anchor2

0
myron-semack On

If you are looking for a hard number, that is pretty much unknowable. Generally it is the order of a tens to a few hundred milliseconds for the data to start reaching the disk platters, but can be as high as several seconds in a large server disk array with RAID and de-duplication.

The flow of events goes something like this.

  1. The application calls a function like fwrite().
  2. This call is handled by the filesystem layer in your Operating System, which has to figure out what specific disk sectors are to be manipulated.
  3. The SATA/IDE driver in your OS will talk to the hard drive controller hardware. On a modern PC, it typically uses DMA to feed the data to the disk.
  4. The data sits in a write cache inside the hard disk (RAM).
  5. When the physical platters and heads have made it into position, it will begin to transfer the contents of cache onto the platters.
  6. Steps 3-6 may repeat several times depending on how much data is to be written, where on the disk it is to be written. Additionally, there is usually filesystem metadata that must be updated (e.g. free space counters), which will trigger more writes to the disk.

The time it takes from steps 1-3 can be unpredictable in a general purpose OS like Windows due to task scheduling, background threads, and your disk write is probably queued up with a few dozen other processes. I'd say it is usually on the order of 10-100msec on a typical PC. If you go to the Windows Resource Monitor and click the Disk tab, you can get an idea of the average disk queue length. You can use the Performance Monitor to produce more finely-controlled graphs.

Steps 3-4 are largely controlled by the disk controller and disk interface (SATA, SAS, etc). In the server world, you can be talking about a SAN with FC or iSCSI network switches, which impose their own latencies.

Step 5 will be controlled by they physical performance of the disk. Many consumer-grade HDD manufacturers do not post average seek times anymore, but 10-20msec is common.

Interesting detail about Step 5: Some HDDs lie about flushing their write cache to get better benchmark scores.

Step 6 will depend on your filesystem and how much data you are writing.