punkouter
punkouter

Reputation: 5366

What to do with long running processes on a ASP.NET MVC site?

This program is used for taking data that has been imported and exported it line by line to normalized tables. It can take hours sometimes.

How it works is

  1. Uses presses button to begin processing
  2. A call is made from jquery to a method on the MVC controller.
  3. That controller calls a DLL which then begins the long processing

Only one person uses this program at a time.

We are worried about it tying up a ASP.NET IIS thread. Would this be more efficient if instead of the web site running the code we could make a scheduled task that runs a EXE every 30 minutes to check and process the code..

EDIT 1: After talking to a coworker the work around we will do for now is simply remove the button from the web site that processes and instead refactor that processing into a scheduled task that runs every 5 minutes ... if there are any comments about this let me know.

The question is really about the differences between the web site running code vs. a completely separate EXE...IIS threads vs. processes... Does it help any ?

Upvotes: 3

Views: 4460

Answers (2)

JaredPar
JaredPar

Reputation: 755347

When the task can run for hours having it block an ASP.Net thread is definitely the wrong thing to do. A web call should complete in a reasonable amount of time (seconds ideally, minutes at worst). Tasks which take considerably longer than that can be initiated from a web request but definitely shouldn't block the entire execution.

I think there are a couple of possible paths forward

  1. If this is a task that does need to be executed on a semi-regular basis then factor it into an EXE and schedule the task to run at the correct interval
  2. If this task should run on demand then factor it out into an EXE and have the web request kick off the EXE but not wait for its completion
  3. Another possibility is to factor it out into a long running server process. Then use remoting or WCF to communicate between asp.net and the process

Upvotes: 1

Gary Walker
Gary Walker

Reputation: 9134

If the processing takes hours, it should definitely be in a separate process, not just a separate thread. You complicate thread locking and management, garbage collection and other things by dropping this into a separate process. For example, if your web server needs to be rebooted, your separate process can continue running without being affected. With a little work, you could even spin up this process on a separate server if you want (of course you would need to change the process start mechanism to do this)

Upvotes: 2

Related Questions