user1005448
user1005448

Reputation: 637

WCF service - async iimplementation

In a standalone windows application (Wpf/Winforms) I can see the benefits of using async implementation of long running methods to keep the UI responsive.

As I know, the IIS is will take care of the threading stuff e.g the web service will not block while its processing another request.

So my questions are:

  1. When it comes to implementing a web service using async/await, does that makes sence ?
  2. Will we gain any performance/scaling benefits for making the implementation async e.g using the async/await keywords.
  3. To make a wcf service scale and perform well, can the only tuning be done in the config file or are there other things to think of ?

I'm interested in hearing your experiences and not only links to theoretical articles.

Thanks

Upvotes: 1

Views: 302

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 456677

Web services in general can gain a benefit from async/await if they use naturally-asynchronous operations. This is because async can return the IIS thread to the thread pool while it is waiting for the operation to complete, instead of blocking that thread.

I haven't heard many numbers on WCF services, but on the MVC/WebAPI side I've heard of scalability benefits in the 10x-100x range.

"Naturally-asynchronous" usually means "I/O-based". Obviously, there's no benefit if you just use Task.Run to offload a CPU-bound (or blocking) call onto a thread pool thread - you'd just be trading one thread for another. But if your implementation is I/O-bound, then you can use async to make maximum use of the thread pool.

Another thing to keep in mind is the scalability of the system as a whole. I.e., if your WCF calls all just turn around and call a single SQL Server backend, then you probably won't get any benefit from scaling WCF because the SQL Server will be your scalability bottleneck.

But in general, I recommend using async/await on your server-side code for any naturally-asynchronous work.

Upvotes: 3

Related Questions