2

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?

  • Depends on the work load. Only way to really find out is a POC demo since some workloads may be better for one method over the other. On another note, the TPL has worked very well for me. Real easy to implement and even easier to abuse. – RubberChickenLeader Feb 4 '16 at 19:47
  • Seems a bit broad. Probably depends on what you're doing. And you have searched around for discussion comparing the 2? – Andy Wiesendanger Feb 12 '16 at 16:26
  • @AndyWiesendanger I have searched around and haven't really found any comparisons of the two. It is of a bit broad question, but I'm looking for a 'general rule of thumb' type of answer. I've done some testing on my own with the specific scenario's I'm looking at and I don't really see any difference. But I'm not ready to call it a "tie". – Coding Gorilla Feb 12 '16 at 16:48
  • I think the age-old "profile it for your use case" might be the best approach here. – Whymarrh Feb 12 '16 at 21:50
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.