Take the 2-minute tour ×

Ive been trying to figure out if multithreading in an io-bound application will actually improve performance or reduce it. Many sources I have read are conflicting.

Take this one for example.

Why multithreading with io-bound is bad

The accepted answer is that if your application is io-bound multithreading will cause contention and slow down your application.

Where as is this example the answer with the highest votes states that it can improve throughput.

Why multithreading with io-bound is good

Am I misunderstanding something here?

In my situation I need to read from n disk locations n times a second. I'm finding it difficult to decide if I should be using threads at all.

For example, if I had 20 files on disk and 20 seperate threads reading from disk in a state of waiting and waking, is this going to completely slow down my system? If a pthread is executing code that reads from disk, would all the other 19 threads doing the same thing on different file be blocked?

share|improve this question
We are also considering a multithreaded disk I/O approach on Android. Currently we have over 20,000 files that each take ~12ms to read (which equates to 4 minutes - which is painful). The idea is to spawn N threads and share the files amoung them to try and reduce the overall read time. Did you conclude anything definitive in the end? I'd be interested to hear anything you have to share. P –  protectedmember Aug 5 '12 at 21:09
add comment

3 Answers

up vote 1 down vote accepted

Why do you need multithreading for this? If you work with single disk, multithreading will provide the same performance in the best case or a bit slower otherwise.

share|improve this answer
Im beginning to think now that I dont need it. I'm an inexperienced programmer and was naievly trying to improve my application –  dubbeat Oct 25 '11 at 21:31
Think how to reduce data amount that is stored on disk, consider binary format or some fast compression. –  Andy T Oct 25 '11 at 21:40
add comment

In this question:

Does it make sense to spawn more than one thread per processor?

That you labeled "why multithreading with io-bound is good", the top answer has 16 upvotes and he states that "If your software makes frequent use of disk or network IO". Take particular note of the last part, "network IO". This is a distinguishing factor from your first linked question, which is only about threads and disk IO.

share|improve this answer
the difference between disk io and network io being that network io as @ObscureRobot states may be able to "handle multiple disk requests in parallel" ? –  dubbeat Oct 25 '11 at 22:05
It's not just that. Disks are typically much faster than networks and so can serve up several network links at once. Network connections typically have a much higher latency - unlike disks, it may take seconds just to set up a connection before a single byte gets transferred. Multiple threads mitigate this latency since some threads can be transferring data while others are waiting for DNS lookups and 4/3-way TCP handshakes to complete. –  Martin James Oct 26 '11 at 8:52
add comment

The only way that additional threads will help in an io-bound situation is if your storage system can handle multiple requests in parallel. This can be the case on high end storage arrays, but is unlikely to be the case on a consumer device like the ipad.

share|improve this answer
add comment

Your Answer


