2

Disk benchmarks typically have a chart that shows the I/O throughput increasing as the queue depth increases. I'm assuming that what's going on at the hardware level is that the disk controller is reordering the requests to coincide with where the magnetic head happens to be. But how can I increase the queue depth in my own I/O-heavy application? I'll be using C#, but language-agnostic answers will probably also be helpful.

One (untested) method that occurred to me was to split my disk access into many files and issue the I/Os in many threads. But surely there is a way to do it without using a thread per parallel I/O. And I'm also assuming that splitting to many files is not needed since a DB is generally one file.

Fantius
  • 3,806
  • 5
  • 32
  • 49
  • Is it as simple as opening a FileStream and making many BeginRead() calls? Or would they just get lined-up in a FrameWork queue before getting to the disk queue? – Fantius Oct 29 '10 at 20:45
  • Yep, the text near the top here seems to indicate that it is that simple: http://msdn.microsoft.com/en-us/library/kztecsys(VS.80).aspx – Fantius Oct 29 '10 at 20:46
  • Not sure what you are reading on that page which supports the theory. – Andrew Barber Oct 29 '10 at 20:56
  • "Asynchronous I/O can offer better performance when many I/O requests are pending simultaneously" – Fantius Oct 30 '10 at 21:32

1 Answers1

2

You don't need to use a thread per I/O operation, but you do need to parallelize your I/O. Servers that perform large-scale I/O (like databases) typically use I/O completion ports (IOCP). Completion ports allow multiple I/O requests to be pending in parallel - and can maximize the underlying hardware's ability to reorder queued requests. IOCP use callbacks to a thread-pool to notify an application when pending I/O operations have completed.

Unfortunately, C# has limited (built-in) support for completion ports - however, there are some open-source libraries that attempt to bridge this gap.

Beware, IOCP is not for the weak of heart - and the performance benefit only accrues if you are truly performing a massive amount of I/O.

LBushkin
  • 129,300
  • 32
  • 216
  • 265
  • Thanks. But from the comments at your second link: "The primary goal of Managed IOCP is to provide .Net developers with a waitable event queue with concurrency control on the threads waiting on the queue. Managed IOCP do not deal with I/O asychrony in any manner." – Fantius Nov 06 '10 at 00:49
  • According to Aaronaught at http://stackoverflow.com/questions/2785194/typesafe-fire-and-forget-asynchronous-delegate-invocation-in-c, Stream.BeginRead uses I/O completion ports. – Fantius Nov 06 '10 at 01:45