Question

I'm doing some research for a project in which I will need to create a service which can handle millions of requests per minute. Clearly I want to use an asynchronous programming model to make the best use of threads and resources. But memory usage and speed are the top priorities.

Looking at the original APM (Asynchronous Programming Model), I'm wondering if it might be more efficient or faster than the newer TAP (Task-based Asynchronous Pattern).

My thinking here is that maybe it's better to register a callback function than it is to "spin up" a ton of Task<T>. The task clearly has to have a little bit of overhead to it right?

Was it helpful?

Solution

In my research I found the two to be nearly identical. In my case I was mostly working with HttpListener and WebRequest classes and in fact most of the TAP methods (e.g. HttpListener.GetContextAsync()) are just wrappers of Task.FromAsync on the APM methods of the same name.

I did notice a very small increase in memory allocations for the Task<T> that captured the result objects, but it was very difficult for me to compare those against the memory allocations with the IAsyncResult (just because the patterns are so different it was difficult to make a comparison). But as I noted the overall process memory usage was very slightly higher under the TAP pattern.

Alternatively, the CPU usage/consumption seemed to be completely identical between the two models.

The main difference was the significantly simpler code and simpler debugging of the code that the TAP offers.

Again my research was very specific to my use case, so I don't want to propose these results as the answer to the general question, but hopefully someone finds my research useful in the future.

Licensed under: CC-BY-SA with attribution
scroll top