Fragrance
|
Recently in my project we had a performance issue, so our teams were on our toe to decrease application start-up. While analysing the code I came across a “for loop” which was creating the problem. Collection was very big and secondly it was performing some long running task. So I had two option two increase the performance:
Using Task.Factory.StartNew
So if you see the above code, I am looping the collection and scheduling a single Task per item in the collection. This particular code will introduce far more overhead especially if the collection is very large and in that case overall runtimes is very slower. Also above code will run in asynchronous manner Using Parallel.ForEach
Now if you see second block of code, it’s a simple Parallel.ForEach call. Internally it uses a Partitioner<T> to distribute your collection into work items. But it won’t create one task per item rather it will create a batch which will lower the overhead. As whole block Parallel.ForEach runs in synchronous manner i.e. block of code after Parallel.ForEach will run only after it's completed. And in case if you want to run the Parallel.ForEach in asynchronous manner then we can modify the code as shown below. By implementing as shown below you are collaborating the power of Async plus the power of Parallel.ForEach. Including both Parallel.ForEach and Task.Factory.StartNew
Comments
Azure functions is the idea of events and code, developers will provide the Azure with a function or code and you till what event should trigger that function.
Azure Cloud Services: Developer can also use web roles or Worker roles. Web roles are used for hosting websites and web APIs, and Worker roles are designed for your background tasks, like processing queues and other batch work. So in cloud services all the environment related work is taken care by Microsoft and this model looks perfect for developers Why do we need Azure Functions?
Server less doesn’t means there are no server involved, of course servers are involved but it’s abstract from the users/developers. But we delegate all the management of the server to Azure instead of us doing it. So we can purely focus on business requirement. All the big enterprise application relies on the third party platform or backend. For example, for database we might use Azure DocumentDb and for authentication we might use some other third party platform. And with growing number of third party platform service, we might need to write our own custom backend code as per our requirement and that’s were Azure Functions comes to help us. So you can just tell the Azure function which events you need to respond to and you can write your own custom code. So with this comes a new term “Function as a Service (FaaS)”. |
Categories
All
Archives
May 2020
|