views:

110

answers:

2

Hello Gurus,

There doesn't seem to be many Windows Workflow Foundation gurus out there :(

Here are couple of challenges that I face:

How many workflow runtimes should there be running for in an Asp.Net MVC application? One per application, per session or per request?

How frequently should the workflow runtime be started and stopped? Once per application instance, once per session or once per request?

What are the pros and cons of doing one or another in the above options?

Any comments or suggestions are welcome,

Thanks,

Cullen

+1  A: 

How many workflow runtimes should there be running for in an Asp.Net MVC application?
one per application, unless you need more for scalability purposes (too many requests)

How frequently should the workflow runtime be started and stopped?
typically, once per application instance

The pro's and con's are trivial, you can scale better with more session requests and instances, but it takes more overhead to manage them all.

Your best bet is to use just enough of what you need and grow later if necessary.

Robert Greiner
@Robert: Thanks for the quick reply! Have you done much WF in asp.net environment?
Cullen Tsering
No problem, I've used it a little bit, I've probably only learned enough to get myself into serious trouble. Hopefully, I'll have some opportunities to use it more later.
Robert Greiner
that's what I'm trying to prevent myself getting into, "serious trouble" I mean. The project that I'm working on has plans to use WF extensively in the stateless web environment. Hopefully, I'll find my way through WF to implement the best solutions for this project.
Cullen Tsering
yeah, unfortunately it seems you have to pass through that phase before you can get anything legitimate accomplished. Good luck and I hope your project works out.
Robert Greiner
+1  A: 

You would normally only run one workflow runtime per application. It is possible to define more than one and there may be some complex scenarios where that is desirable but its highly unlikely. I can't see any scenario where multiple runtimes for the same configuration would be run in the same process.

For a web hosted workflow you really need the SqlWorkflowPersistenceService. IIS expects to be able to recycle an application pool with minimul impact on the application. Hence you need idled workflows to be persisted so that they survive such recycles.

On a similar note you should use the ManualWorkflowSchedulerService which plays nice with ASP.NET use of threads, its also really handy in being able to perform end-to-end processing of a request to a response through workflow on a single thread. Just be sure to include the useActiveTimers="true" attribute so that delay activities work.

In line with the above you need to be sure that any active workflow does not take longer to complete or go idle than the application pool's shutdown time limit. Otherwise on recycle IIS may force the process to terminate before a workflow has persisted.

As to starting and stopping the workflow, its again difficult to see a scenario where you wouldn't just want it to start on application start and remain running. I guess if you have a workflow which never idles but just runs from beginning to end and you only run such workflows very occasionally then it might be simpler to start the runtime and the end it afterward. However even that can get messy, I wouldn't bother just start it on app start and be done with it.

AnthonyWJones
@Anthony: thanks for the reply. I've already configured to add SqlWorkflowPersistenceService and ManualWorkflowSchedulerService to the run time; The IIS recycling issue is a really important one to be aware of. Is there an event that can be intercepted when the application pool gets recycled?
Cullen Tsering
There is no specific Recycling event. The closest I can think of is that the application is started again on recycle but that would be in a different process than any workflow currently executing. I would just be sure that Shutdown timeout is well clear of a workflow's running time. If that time is excessive then perhaps some of that work doesn't belong in a web process.
AnthonyWJones