1

I am reading conflicting opinions here. Am I right that although an asynchronous method call also gets handled by a thread pool invisible to the user, this is likely to save resources because the underlying operating system is able to suspend these threads whilst IO calls are pending ?

3
  • 1
    Lots of threads require constant context switching. Commented Mar 2, 2012 at 4:27
  • Please don't prefix your titles with ".net" and such. That's what the tags are for. Commented Mar 2, 2012 at 4:42
  • Lots of ready threads require constant context switching. Commented Mar 2, 2012 at 8:34

3 Answers 3

1

You are exactly right. The IO threads are not only suspended, they are retired when they become unneeded. But async IO is not a general solution for all problems and here is why:

  • Async algorithms are hard to code. The async code is more complicated and error-prone than synchronous variant
  • IO completion callbacks work in special IO threads and programmer has to keep those threads as free as much it is possible; otherwise the system will slow down significantly. So if you go to async IO be ready to implement Producer-Consumer pattern for actual data handling
  • If you have a demand in less than 150 parallel connections and the application runs on a PC machine then synchronous implementation will be a low-hanging fruit delivering ease of programming and satisfactory performance at the same time
Sign up to request clarification or add additional context in comments.

1 Comment

While async programming should be done cautiously as stated above. The new 5.0 features will make async extremely easy and expressive in coding. I suggest reading Eric Lippert's article to understand what is coming up: blogs.msdn.com/b/ericlippert/archive/2010/10/29/… He also states some good points around async. I know this is the future, but based on this Q&A, it seemed like it could be helpful :)
0

Ideally, if possible, you would use .net 4.0 System.Threading.Tasks.Parallel class. It will take advantage of multi-core processors.

And it's simple.

Comments

0

'an asynchronous method call also gets handled by a thread pool invisible to the user' - yes, something must do the I/O!

'this is likely to save resources because the underlying operating system is able to suspend these threads whilst IO calls are pending' - the OS is able to suspend user threads while I/O is pending as well.

In high-performance apps, asynchronous wins because more work is pushed into the kernel where better thread management is possible. This does reduce context switches and also avoids a lot of data copying.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.