howdymars
howdymars

Reputation: 11

IIS 10 application pool slow initialization times after recycle

we have an application pool that has a slower initialization time after an app pool recycle in IIS 10. (around 5-7 seconds after recycle then 30-50 ms after the first request.) I have done some research and found that the "Application Initialization." module should do the trick. I installed it onto the server and set the application pool to "AlwaysRunning" and the corresponding site to "PreloadEnabled == True." After making those changes we tested by recycling and the response times seemed a bit better...down to 3 to 4 seconds after recycle. I tried to then disable the "overlapped recycle" to see if that helped and again it did a bit better 1.5 to 2 seconds after recycle and then 20 to 30 ms after the first request.

Question is: Is that the best we can expect? I was hoping there would be away to fully pre-warm the app pool so that even the first request is around a few ms. The issue is that test messages we are sending to the API are small and the ones in Prod would be much larger so an initialization of 3-4 seconds could be much much longer in Prod.

Upvotes: 1

Views: 2865

Answers (2)

Matthias Schuchardt
Matthias Schuchardt

Reputation: 787

IIS saves doAppInitAfterRestart in the web.config of the application, which might be overwritten by future deployments. Therefore I'd put the web.config under source control and make it part of the deployed artifact.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />

    <!-- Add this node to web.config -->
    <applicationInitialization doAppInitAfterRestart="true">

      <!-- Only needed when website contains multiple child apps -->
      <add initializationPage='/hangfire',hostname='' />

    <applicationInitialization />
  </system.webServer>
</configuration>

Upvotes: 0

Abhiman Tiwari
Abhiman Tiwari

Reputation: 282

Following are the steps you can perform to Auto Initialize application hosted on IIS –

• Installed Application Initialization feature - IIS 8.0 Application https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization

• Make sure the warmup.dll (which should load from C:\Windows\SysWOW64\inetsrv\warmup.dll or from C:\Windows\system32\inetsrv\warmup.dll depending on the bitness of your process) present

• Configure the app pool to be always running (from the advanced properties) eg. In the applicationHost.config (%WINDIR%\system32\inetsrv\config\applicationHost.config) file the application pool setting looks like this –

<add name="PreLoadApp" autoStart="true" managedRuntimeVersion="" startMode="AlwaysRunning">
                <processModel idleTimeout="00:00:00" />
            </add>

• Scroll down a little more in applicationHost.config to the configuration element. Within that section there will be an entry, modify your application as below

<site name="PreLoadApp" id="5">
                <application path="/" applicationPool="PreLoadApp" preloadEnabled="true">
                    <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\PreLoadApp" />
                </application>

• Then selected the site from the IIS manager tree view on the left-hand side and go to the configuration editor.

  • this time underneath the <system.WebServer/applicationInitialization> tag, and look at the list of requests
  • set the request to only target a page called (host header is optional) and also you can provide a query string q=abhi // to identify if request is coming from preload only.
  • set the doAppInitAfterRestart parameter to true and apply the settings enter image description here

And you should be good by now, try recycling your application pool, it should Initialize and warmup automatically.

You can refer these MS docs to know more about Application Initialization and configuration steps – https://learn.microsoft.com/en-us/iis/configuration/system.webServer/applicationInitialization/ https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization

Upvotes: 2

Related Questions