Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


Creating a Local Keep Alive Service on your Web Server

Most of us have experienced that lesser visited DNN (or other ASP.Net) web sites need some time to start when browsing to the first page. The reason for this is the shut-down of the ASP.Net worker process that happens after no request to the Application Pool has been done for a given number of time - the default is 20 minutes. Beyond that, the worker process is shut down every 29 hours (1740 minutes) by default even when it is not idle.

What happens when a request comes in?

These are the first steps that happen against a client request:

  1. IIS checks whether a worker process is active or not.
  2. If not:
    1. IIS it creates the worker process by starting w3wp.exe.
    2. The worker process hosts aspnet_isapi.dll - this is the handler mapped to "aspx" files. IIS checks for the script map and routes the request to the handler.
    3. The request is passed to the .Net runtime (which is hosted in the worker process as well).
    4. The application domain is created by a class called ApplicationDomain. This provides isolation between different applications, e.g. for global variables, and allows to unload applications separately.
    5. Inside the application domain, the hosting environment is created as an instance of the HostingEnvironment class. It provides information about the application such as a unique application ID, the physical path on disk where it is stored, the name of the site etc.
    6. ASP.Net creates core objects like HttpContext, HttpRequest, HttpResponse etc.
    7. The application is started as an instance of the HttpApplication class - or, if there is a global.asax file, it creates an instance of it's own class (that derives from HttpApplication).
    8. If required, ASP.Net compiles the top-level items in the application (including code in the App_Code folder).

Keep Alive Services

It is (or should be) quite clear that this takes some time, and therefore it is quite clear why we have to wait sometimes. The good news is that you can do something against it. One solution could be to increase the value(s) for the shut-down(s) in IIS Manager by configuring the application pool. This will help only if you can say that you have one visitor e.g. once an hour and set the time-out to e.g. 90 minutes - but are you really sure about this?
The other way is to use a keep-alive service, such as the great and free DNN Monitor that makes a request to your web site every five minutes - and also records response times and provides some statistics for you.
But what if this is a website in your intranet that is not accessible for DNN Monitor?

There are two things to know:

  • DNN provides a script named KeepAlive.aspx (which resides in the root of the DNN installation). This script is doing nearly nothing, it contains a call to an ASP.Net method that returns the server's current date and time, and uses the HTML-Meta-Tag to reload itself every 5 minutes.
  • Windows contains a very powerful command line shell named Windows Power Shell.

Knowing the first one allows you to install a keep-alive service. Just start a browser on any PC in your network and call the KeepAlive.aspx page (e.g. by typing http://intranet.company.local/KeepAlive.aspx in your browser's address bar. Don't close the browser, don't log off or shut down the computer and you're done.

There is a more elegant way. You can write a Windows Power Shell script using your preferred text editor. The script requests the web site, and then you can call the script on a regular basis using a scheduled task. The script is not really complicated, it just instantiates a web client object and requests the page:

$WebClient = New-Object Net.WebClient
$WebClient.DownloadString("http://intranet.company.local/")

Save the script somewhere on your web server, e.g. C:\PowerShellScripts\KeepAlive.ps1. Open Power Shell, navigate to the folder where you stored it and execute the script:

PS H:\> C:
PS C:\> CD \PowerShellScripts
PS C:\PowerShellScripts> .\KeepAlive.ps1
<html> (... Lot of stuff ...) </html>

Got an error? The reason is most propably the execution policy that requires signed scripts. You can change this to Remote Signed by entering

Set-ExecutionPolicy RemoteSigned

You can avoid the output by assigning the last call to a variable, so change the second line of the code to

$Source = $WebClient.DownloadString("http://intranet.company.local/")

The last step is to create a scheduled task on your web server that starts powershell.exe under the SYSTEM account every 5 or 10 minutes with the name of the script as parameter. You can do this using the graphical interface for Scheduled Tasks in Windows or using the SCHTASKS command (in a command window or Power Shell):

SCHTASKS /CREATE /RU SYSTEM /RL HIGHEST /TN "Keep Web Site Alive" /SC minute /MO 10 /TR "powershell.exe C:\PowerShellScripts\KeepAlive.ps1"

 

Happy DNNing!

UPDATE: DNN Monitor does not exist anymore.

Comments

Richard Howells
Hi Michael. If you are on IIS recent. I think it's IIS 8 and later you can do this with a setting.

Go to site settings advanced and set Preload to True.

http://blogs.msdn.com/b/vijaysk/archive/2012/10/11/iis-8-what-s-new-website-settings.aspx
Richard Howells Thursday, July 17, 2014 8:58 AM (link)
Michael Tobisch
Hi Richard, thanks for this useful information. In my eyes, the app pool recycling makes sense (as it releases a lot of unused resources) - but I'll check if this still happens with this setting.

Best wishes
Michael
Michael Tobisch Thursday, July 17, 2014 10:14 AM (link)
Richard Howells
Hi Michael. I believe the recycling still takes place. AIUI after the fresh AppPool is ready to go the system sends a priming request through for all sites using that pool which have Preload=True. Then the fresh AppPool is swapped for the old one.
Richard Howells Thursday, July 17, 2014 11:13 AM (link)

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out