locked
WF ASP.NET on Load Balancing Server. RRS feed

  • Question

  • Hi,

    We are using WF in our ASP.Net Application. Till now we were using single server to host webapp. now as we are moving to new load balancing environment with sqlserver sesssion, we are having some issues with putting workflowruntime object into session, so can you please suggest me the solution for this. code is as below.

    void Session_Start(object sender, EventArgs e)
        {
           
            WorkflowRuntime runtime = new WorkflowRuntime();
            ManualWorkflowSchedulerService scheduler = new ManualWorkflowSchedulerService();

        
            SqlWorkflowPersistenceService persist =
                new SqlWorkflowPersistenceService(ConfigurationManager.ConnectionStrings["PaHubConnectionString"].ConnectionString,
                        true, TimeSpan.MaxValue, new TimeSpan(0, 0, 2));

            runtime.AddService(persist);

            runtime.AddService(scheduler);
            runtime.StartRuntime();
    Session["WorkflowRuntime"]=runtime;
    }

    and in workflow project...

     public static WorkflowRuntime CurrentWorkflowRuntime
            {
                get
                {
                  return Session["WorkflowRuntime"] as WorkflowRuntime;
                  
                }
             
            }


      public static void StartWorkflow()
            {
                WorkflowRuntime runtime = GlobalMethods.CurrentWorkflowRuntime;
                ManualWorkflowSchedulerService scheduler;
                StepFlowImpl stepFlowImplObj;

                scheduler = runtime.GetService<ManualWorkflowSchedulerService>();

                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                runtime.AddService(dataService);

                stepFlowImplObj = runtime.GetService<StepFlowImpl>();
                if (stepFlowImplObj == null)
                {
                    stepFlowImplObj = StepFlowImplProvider.GetStepFlowImplObj();
                    dataService.AddService(stepFlowImplObj);
                }

                if (!runtime.IsStarted)
                {
                    runtime.StartRuntime();
                }
                WorkflowInstance instance = runtime.CreateWorkflow(typeof(StepExecutionWorkflow));
                instance.Start();
                scheduler.RunWorkflow(instance.InstanceId);
                GlobalMethods.InstanceId = instance.InstanceId;
            }

    As I mentioned earlier that we have moved to sqlserver session so we cannot store Workflowruntime into session anymore so where should I store it and how can i get it back?

    Thanks in Advance
    Gaurav

    Gaurav Trivedi
    Wednesday, January 21, 2009 7:26 PM

Answers

  • Each web server in the farm will have its own application-level instance of the workflow runtime, but that's fine because any particular workflow instance can only be loaded into one runtime at a time anyway.

    If the workflow is created on one server, and then saved to the persistence service, then even if the user gets routed to a different web server on the next request, that server's workflow runtime will then be able to load the instance from persistence.

    I think the only place you'd run into problems is if the workflow has a lot of active work to do, and doesn't have any idle points where it will persist to the database. Like this:

    1. A user hits web server 1, and the workflow is started. The workflow has to do some work that takes 3 minutes to complete.
    2. One minute after the first request, the user gets routed on the next reques to web server 2, and needs to interact with the workflow. That workflow instance will still be loaded on server 1 and actively working, so any attempts for web server 2 to load the instance will fail.

    This probably isn't a typical scenario, and putting the workflow runtime in "Application" doesn't help or hurt, but it's just something you might run into once you start working in a load balanced environment.
    • Proposed as answer by edhickey Monday, February 2, 2009 10:54 PM
    • Marked as answer by Michael Wasser Wednesday, February 4, 2009 10:55 PM
    Thursday, January 22, 2009 12:45 AM

All replies

  • You should really be storing the WorkflowRuntime at the Application level, not the session level. The runtime can handle requests from multiple asp.net requests at the same time, so storing it in Session just creates a lot of unnecessary runtimes, and has got to be hurting your performance...

    http://msdn.microsoft.com/en-us/library/aa349445.aspx
    Wednesday, January 21, 2009 10:59 PM
  • Hi
    Thanks for your reply.

    If I store WorkflowRuntime to Application then Is that would work with mulitple web server (Load balancing env)?

    Gaurav

    Gaurav Trivedi
    Thursday, January 22, 2009 12:13 AM
  • Each web server in the farm will have its own application-level instance of the workflow runtime, but that's fine because any particular workflow instance can only be loaded into one runtime at a time anyway.

    If the workflow is created on one server, and then saved to the persistence service, then even if the user gets routed to a different web server on the next request, that server's workflow runtime will then be able to load the instance from persistence.

    I think the only place you'd run into problems is if the workflow has a lot of active work to do, and doesn't have any idle points where it will persist to the database. Like this:

    1. A user hits web server 1, and the workflow is started. The workflow has to do some work that takes 3 minutes to complete.
    2. One minute after the first request, the user gets routed on the next reques to web server 2, and needs to interact with the workflow. That workflow instance will still be loaded on server 1 and actively working, so any attempts for web server 2 to load the instance will fail.

    This probably isn't a typical scenario, and putting the workflow runtime in "Application" doesn't help or hurt, but it's just something you might run into once you start working in a load balanced environment.
    • Proposed as answer by edhickey Monday, February 2, 2009 10:54 PM
    • Marked as answer by Michael Wasser Wednesday, February 4, 2009 10:55 PM
    Thursday, January 22, 2009 12:45 AM
  • hi Thanks for your reply, 

    May I know what would be the performance difference if I put WorkFlowRuntime into Application, Cache or store into static object?

    Thanks
    Gaurav

    Gaurav Trivedi
    Thursday, January 22, 2009 3:51 PM
  • I'm not sure. I don't think there would be any point to trying to cache the object, though.
    Thursday, January 22, 2009 4:49 PM