Async I/O always better than sync I/O?

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Hi,

Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than
synchronous I/O? At least as good?

When I don't concern about easy or difficult to write code, should I always
use Async I/O?



Thanks!
 
Hi,

Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than
synchronous I/O? At least as good?

When I don't concern about easy or difficult to write code, should I always
use Async I/O?

Thanks!

Well, that really depends on what you want to achieve. If you have a
CPU bound task you don't want to delay while doing I/O, async is the
way to go. On the other hand if you application is mainly doing I/O
you will most likely not see a big gain by using async I/O. Also,
synchronous I/O is a lot simpler than async I/O so even tough you say
you don't care, you'll be facing more problems if you go with async I/
O if you don't really need it but of course it's your choice.

Regards,
Brian
 
Ryan said:
Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than
synchronous I/O? At least as good?

If your code is I/O bound (so you don't have spare work to do) and
doesn't need to scale (so you'd have more parallel I/O-bound code
running), then you don't need the complexity of async.

Otherwise, assuming you write it correctly, you can scale to more
parallel I/O operations and you can fit in more compute work while I/O
is pending, if you use async.
When I don't concern about easy or difficult to write code, should I always
use Async I/O?

Don't underestimate the cost (in maintenance, debugging, design,
implementation, documentation, explanation to other coders) of async
code.

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top