I am in the design phase of a project where the end user will submit a request from a web page that will spawn a long running asynchronous processed job. Is there a "best practice" for this problem? Are web services and service brokers a good way to go? Is Microsoft messaging queue applicable here?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
I don't know about "best practice". I do know the most common mistakes.
First Mistake: DOS Yourself
You use the webhandler to process the long running job. This can be bad or extremely bad depending on your percentage of hits that become long running jobs, how long they run and how much sustained traffic you get.
You want to make sure that you aren't getting more than 1 long running job within the period of time it takes for that long running job to complete. If you do you DOS yourself. It will also get worse the more traffic you get assuming the percentage and time stays consistent. It's one of those problems which self-imposes a limit on traffic growth.
Second Mistake: Spawning from the webhandler
Spawning a process from the web handler to handle a long running process can be tricky, and as a result also error prone.
I usually use
You can also use a polling implementation with
You can communicate to another server process that handles the processing. That communication can be done with
I suppose you are talking about more than a few minutes.
If it's few minutes, you could launch a worker thread on the background and display a some progress on the UI. Lots of web applications use that method.
If it's more than, say 5 minutes, you may want to delegate the task to a dedicated service. One example is the reports generated by Google Analytics.
Microsoft Messaging queue can be used to transmit information from a system to another, or a component to another.