Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot warm up pages using applicationInitialization in webconfig

I have a simple Umbraco 7.7.2 application and I'm hosting it on Azure (app-service). When I restart the server it takes 20-40 seconds for first time requesting a page which is really annoying specially when the load is high and you are Scaling out to reduce the response times.

I've tried this setting in my webconnfig, but it doesn't seem to work.

<system.webServer>
  <applicationInitialization>
    <add initializationPage="/page1/?warmup=1" hostName="mydomain.com" />
    <add initializationPage="/page1/page2/?warmup=1" hostName="mydomain.com" />
  </applicationInitialization>
</system.webServer>

I might be trying it in a wrong way, but what I did was to restart the server and I've left it for 2-3 minutes without requesting any page.

I've checked my Umbraco logs and the application wasn't even started. Then I've requested the home page and it took 40 seconds to come up.

Then I've tried mydomain.com/page1 and it also took 20 seconds since it was the first request to access it.

*P.S: after the first request, the site is very fast and each page takes less than 100 ms to load

Update

I've implemented a rewrite to stop next redirects as Kevin has suggested. As a result, my Umbraco will start up, but still the requests doesn't reach to the pages.

On my master page, I've added a line to write a line in the logs if it has the warmup in the querystring and it works it the page is hitted from the browser:

if (!string.IsNullOrWhiteSpace( Request.QueryString["warmup"]))
    {
        var pageC = Model.Content;
        logger.Info(pageC.UrlAbsolute()+" "+ Request.QueryString);
    }

However, there is nothing in my logs after

2018-02-08 15:16:51,245 [P7036/D2/T1] INFO Umbraco.Core.CoreBootManager - Umbraco application startup complete (took 12727ms) 2018-02-08 15:16:54,911 [P7036/D2/T1] INFO MyNamespace.Web.CustomStartup - base config done!

Here is the confing that I've added based on Kevin's answer:

 <rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{REMOTE_ADDR}" pattern="127.0.0.*" />
              </conditions>
          <action type="Rewrite" url="{URL}" />
        </rule>

Also, I've found another similar config on Microsoft:

   <rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="localhost" />
            <add input="{HTTP_USER_AGENT}" pattern="Initialization" />
          </conditions>
          <action type="Rewrite" url="{URL}" />
        </rule>
like image 880
Ashkan S Avatar asked Feb 05 '18 11:02

Ashkan S


1 Answers

Note that azure will warm up the URL on http, so if you are forcing https using rewrite rules, the full site will not warm up, only the redirect module will. Then it needs to finish warming up Umbraco after azure adds it into the load balancer and the first https gets through to the umbraco code. We found that out by checking the http logs when scaling out.

We couldn't figure out how to tell azure to warmup using https, so we allowed Azure to access the site on http by making a rule before our force https rewrite to stopProcessing when {REMOTE_ADDR} matches 127.0.0.*.

    <rule name="Allow localhost to warmup" stopProcessing="true">
      <match url="(.*)"/>
      <conditions>
        <add input="{REMOTE_ADDR}" pattern="127.0.0.*" />
      </conditions>
    </rule>
like image 156
Kevin Avatar answered Sep 22 '22 23:09

Kevin