Scalability

Another area where asynchronous programming is quintessential is the construction of scalable services. When dealing with many requests, it’s common to initiate the processing for a request on the thread pool. This technique is used to reduce the thread creation and deletion churn that would occur if each request would use a dedicated thread. Because thread creation is rather expensive, it’s better to reuse threads using a pool mechanism.

When using a pool, a critical question to answer is how many threads should be allocated. The ideal number of threads is quite simply the same as the amount of CPUs available. Using fewer threads causes underutilization of the system, which may be warranted if many different services are run on the ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.