CPU intensive or time consuming operations? Consider the following options -
- Create a Windows service with a Queuing mechanism and let the service process your jobs one by one and update your application via a database posting. Your application should be devised to look up the updates and show it up on UI as required.
- Kick off the process in an Asynchronous task(async delegate) with a call-back method. Again call-back method would update the application database or the UI with a asynchronous refresh window.
Scenarios:
Suppose we have to process a MS-word document being uploaded and extract data and save in your application database.Or, You have some plot-point(tabular) data and you want to create a graph out of that.
Or, You want to publish a numerous number of files or strangled data into a PDF file format etc.
These are some of the examples which takes considerably longer duration and would cause sufficient delays in the response and user will have to keep waiting. In such scenarios one would want to do the intensive processing in the back-end.
Windows service:
Will have to have a queuing mechanism wherein the service will pick the jobs from and process it. It could be as simple as a simple database table with status and the job information for the input and user. When the service sees and entry in the table with a status "Pending", it would take it up and process. If the queue volume increases you would consider more sophisticated queuing system like MSMQ.Advantages:
- Job runs on a separate process and could even be on a different server. So, it will not have an impact on the webserver performance.- You could have multiple instances of the service and allow them to process multiple jobs simultaneously. This helps to a greater extent when you have voluminous requests and all of them require equal level of priority.
Disadvantages:
This will lead to additional deployment tasks.
Asynchronous Tasks:
This is a simple job delegation with a callback function. Your work is performed right within the ASP.Net process on a separate thread. You will have CPU & memory shared with this. Each one of your requests will kick off a new thread and will get processed right after they are initiated. If your jobs are memory intensive, this is no good choice.
(*)In both of these routes application will require a support for delayed response handling since they both work in a fire & forget manner. What does that mean?
In these cases, you will initiate a new job and leave it complete without waiting for it to complete. The w3wp/aspnet process will continue to process the request and send the response to the client. At that point of time there is no results available out of the job being submitted. The application will require a separate mechanism to check status of the job and update the client periodically.
No comments:
Post a Comment