Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS app pool recycle + quartz scheduling

I'm running a web app on IIS 7.5 and it needs to recycle occasionally (otherwise memory usage gets out of handing, something i'm looking into!).

When it recycles, it is effectively not running until another request comes in, which quartz is not going to run.

Is there any way to have IIS automatically bring up 1 work process immediately after recycling the app pool to ensure quartz is always online?

like image 572
Paul Creasey Avatar asked Jun 21 '12 14:06

Paul Creasey


People also ask

What happens when IIS application pool recycle?

When an application pool recycles, IIS will start another worker process to handle future requests to the websites serviced by the application pool. The new worker process must initialize web applications before they can begin servicing incoming requests.

Why is the IIS default app pool recycle set to 1740 minutes?

The 1740 story Wade suggested 29 hours for the simple reason that it's the smallest prime number over 24. He wanted a staggered and non-repeating pattern that doesn't occur more frequently than once per day. In Wade's words: “you don't get a resonate pattern”. The default has been 1740 minutes (29 hours) ever since!

How many jobs can quartz handle?

The actual number of jobs that can be running at any moment in time is limited by the size of the thread pool. If there are five threads in the pool, no more than five jobs can run at a time.


2 Answers

Yes!

http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx details it quite nicely, basically you need to:

  1. Edit C:\Windows\System32\inetsrv\config\applicationHost.config to include:

    <applicationPools> 
        <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" /> 
    </applicationPools>
    
  2. Declare what should be run as the "warm-up" for your site

    <sites> 
        <site name="MySite" id="1"> 
            <application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />
        </site> 
    </sites>
    <serviceAutoStartProviders> 
        <add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" /> 
    </serviceAutoStartProviders> 
    
  3. Configure your application with whatever "warm-up" logic you would like:

    public class PreWarmCache : System.Web.Hosting.IProcessHostPreloadClient {
        public void Preload(string[] parameters) { 
            // Perform initialization and cache loading logic here... 
        } 
    } 
    

Note: If all you need is for the w3wp.exe process to be present I believe only step 1 is necessary. If you also need other items (like certain things to be loaded into memory) then step 2 and 3 would also be used.

like image 98
Stephen S. Avatar answered Oct 15 '22 17:10

Stephen S.


Starting with IIS 8.0, there is an option to simulate a request to the root page, thus a full application initialization: Application Pool advanced settings -> Preload enabled = true.

Of course, startMode should be AlwaysRunning.

More details about how to enable this feature can be found here.

like image 1
Alexei - check Codidact Avatar answered Oct 15 '22 17:10

Alexei - check Codidact