Sunday, February 15, 2009
Two most exciting features in VS-10 to me
Modern computers have seen explosive growth in the number of processors and cores available for systems running on them. by conceive it as contemplation Microsoft’s Parallel Computing Platform (PCP) is providing tools enabling developers to leverage this power in an efficient, maintainable, and scalable manner. Parallel Extensions to the .NET Framework brings several important concepts into this toolset: imperative and task parallelism via the Task Parallel Library (TPL), and Parallel LINQ (PLINQ), which gives developers a declarative way to deal with data parallelism.
Parallelize a long running service
Consider the following conventional code which takes almost 50 sec to execute…
private static void Ex1Task2_StandardForEach()
{
foreach (Employee employee in employeeData)
{
Console.WriteLine("Starting process for employee id {0}",
employee.EmployeeID);
decimal span =
PayrollServices.GetPayrollDeduction(employee);
Console.WriteLine("Completed process for employee id {0}",
employee.EmployeeID);
Console.WriteLine();
}
}
But now with MS blessings, exerting the parallel processing technique we can significantly reduce the execution time.
private static void Ex1Task2_ParallelForEach()
{
Parallel.ForEach(employeeData, ed =>
{
Console.WriteLine("Starting process for employee id {0}",
ed.EmployeeID);
decimal span = PayrollServices.GetPayrollDeduction(ed);
Console.WriteLine("Completed process for employee id {0}",
ed.EmployeeID);
Console.WriteLine();
});
}
It takes less than half execution time compare to previous code………
Use the ParallelEnumerable class’ Extension methods to parallelize LINQ (PLINQ)
private static void Ex4Task2_Extensions()
{
var q = employeeData.
Where(x => x.EmployeeID % 2 == 0).OrderBy(x => x.EmployeeID)
.Select(x => PayrollServices.GetEmployeeInfo(x))
.ToList();
foreach (var e in q)
{
Console.WriteLine(e);
}
}
This conventional LINQ takes almost 50 secs to be executed.
To parallelize this LINQ query just add AsParallel() to the query’s data source, like so:
private static void Ex4Task2_ConvertToParallelExtensions()
{
var q = employeeData.AsParallel()
.Where(x => x.EmployeeID % 2 == 0).OrderBy(x => x.EmployeeID)
.Select(x => PayrollServices.GetEmployeeInfo(x))
.ToList();
foreach (var e in q)
{
Console.WriteLine(e);
}
}
Compare to previous, it takes less than half of execution time. Amazing!!!!!
Number 2 is….
Microsoft Distributed Caching Service
Microsoft Distributed Caching Service (code named “Velocity”) provides a means to store data in an in-memory cache for later retrieval, eliminating the need to get the data from the disc or data store. This can significantly increase the performance of your application. Additionally, Velocity supports caching on a cluster of services, which can increase your application’s scalability
Download the Velocity Community Technology Preview installation package MicrosoftDistributedCache.msi from http://www.microsoft.com/downloads/details.aspx?FamilyId=B24C3708-EEFF-4055-A867-19B5851E7CD2&displaylang=en
we have to install and used Microsoft Distributed Caching Service (“Velocity”) to cache resources and speed up access to data retrieval.
we can access the cache via its API and can configure a web site to use Velocity to store its session state.
Subscribe to:
Post Comments (Atom)
thx for letting us know such sexy features of
ReplyDeleteVS-X...