asp.net - Pre-Load Web Application Pages After Deployment to Prevent Slow Loading -


we build , deploy our web application our dev environment automatically every night (using vsts). when come office in morning, first person access application has wait extended period each page load first time. subsequent loads fast.

the problem has greater impact in our live environment where, after deployment, potentially end-user first person access application , complain of slowness. mitigate this, member of team accessing every page of application manually after deployment live environment 'pre-load' every page, works, time-consuming!

i've done fair bit of searching on subject, , have configured appropriate application pool in our iis server (iis 8.5) start mode set "alwaysrunning". i've edited our applicationhost file , set appropriate sites preloadenabled="true" attribute. did after reading instructions in helpful microsoft documentation.

however, if i'm reading documentation correctly, pre-loading of website might alleviate issue we're having (and i'm not kind of pre-loading i'm thinking of) takes place when server, iis service of application pool restarted. isn't happening in our case. need pre-loading take place following deployment of application iis server.

is there way automate pre-loading?

one way of doing perform http request automatically:

  • as app deployed (by running task deploying machine)
  • before application pool has chance shut down (using task scheduler instance)

personally, use tool run in both cases keep site warmed up.

advantages

  • robust control on how , when warm-up executed.
  • it's independent iis or web.config setup.

disadvantages

  • generates "bogus" log information.
  • keeps app permanently in memory (the pool never time-out, wasting server resources sites low # of visitors).

sample

such tool simple console app written follows:

var taskinfo = new {     url = "http://www.a-website-to-keep-warm.url",     usehostheader = true,     hostheader = "www.a-website-to-keep-warm.url",     httpmethod = "head" };  httpstatuscode statuscode = httpstatuscode.unused; long contentlength = 0;  try {     dictionary<string, string> headers = new dictionary<string, string>();     httpwebrequest webrequest = (httpwebrequest)webrequest.create(taskinfo.url);      webrequest.method = taskinfo.httpmethod.toupper();     if(taskinfo.usehostheader)         webrequest.host = taskinfo.hostheader;      using (httpwebresponse webresponse = (httpwebresponse)webrequest.getresponse())     {         //did warm-up site successfully?         statuscode = webresponse.statuscode;         contentlength = webresponse.contentlength;          //optionally read response headers         foreach (string header in webresponse.headers)         {             headers.add(header, webresponse.headers[header]);         }     }      decimal kilobytes = math.round(contentlength / 1024m, 1);     debug.writeline($"got {kilobytes:f1} kb statuscode: \"{statuscode} \" ..."); } catch (exception ex) {     debug.writeline($"taskinfo failed exception: {ex.message}"); } 

in case, read bunch of taskinfo objects json file , execute them asynchronously every x minutes, making sure x lower pool-timeout value. run after every deploy.

because we're not interested in getting entire content, uses http head request instead of get. lastly, supports multiple sites on same host adding host header request.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -