We all know Visual Studio 2010 and .NET Framework had been released during the last week..
I’ve compiled WCF Contrib v2.1 in .NET 4.0 to be available for download if you need -
wcfcontrib.mar07.binaries.4.0.zip
Read about the test details in the previous post.
After a few more various tests, the initialization time overhead is changing from time to time, and sometimes there isn’t an overhead whatsoever.
However, the fact remains the same, the asynchronous invocation pattern shows most constant results in this specific case.
My good friend Aelij Arbel pointed out another pattern of invocation using the Parallel Extensions TPL – the asynchronous API.
I added it to the test as follows:
static void CallServicesTasksAsync(IMyService client)
{
Task[] tasks = _serviceCalls
.Select(c => Task.Factory.FromAsync(client.BeginDo, client.EndDo, null))
.ToArray();
Task.WaitAll(tasks);
}
This yielded results pretty much just as the standard asynchronous invocation! Hooray!
Why is that?
Parallelizing and waiting on the synchronous “Do” operation schedules it on different threads and blocks on them (using the default scheduler).
Threads should be allocated and blocked where there’s actual CPU-bound work, this issue becomes crucial when resources are tight in your application.
This is why using the asynchronous pattern within the TPL has better results altogether. (where a thread is opened for the I/O only, not for the entire operation)