| Overview | Features | Setup |
|
Have you ever accessed your web site after some time of inactivity, only to discovered how slow it is in servig up the first page? Open-KeepAlive helps solving the first-hit problem.
This HttpModule will make an automatic request to a page you designate, every time the .NET runtime releases its resources, so that when the next real user requests a page, he/she will not suffer any delay due to the reloading of needed resources. The Site is kept alive.
You can also specify a set time interval to refresh your site, as well as log all module activities in a log file.
|



|
|
What It Does
It keeps the site "alive", when:
- The .NET process recycles its resources automatically
- The web.config file is changed (but not when it is FTPd)
- A new .dll is introduced or a change of an existing .dll is made in the /bin directory
It does not keep the site "alive" when:
- IIS worker processes are shut down, either gracefully or not
Note:
According to Microsoft: "The [IIS] worker process is subject to a feature named process recycling. Process recycling consists in the aspnet_isapi ability of automatically starting a new process when the existing one is consuming too much memory, responds too slowly, or just hangs. When this happens, new requests are serviced by the new instance, which becomes the new active process. However, all the requests assigned to the old process remain pending. When the old process has finished with pending requests and enters idle state, it is terminated. If the worker process crashes, or in anyway stops processing the requests, all pending requests are reassigned to a new process."
So, under some, but not all circumstances, when your aspnet_wp.exe or w3wp.exe is recycled or killed, the aspnet_isapi automatocally starts a new process, and that should explain why on occasion Application_End is not fired. As a consequence of this behavior, sometimes the first-hit slowness will remain. The frequency of such occurrances depend on your Internet Host settings and memory capacity.
How It Does It
- When the first request is made, a pool of HttpApplication instances is created and the Application_Start event is raised.
- The HttpApplication instances process the first and subsequent requests.
- Periodically, the HttpApplication pool instances are disposed of by the .NET runtime, and/or, the .NET runtime releases its application resources, causing the disposal of the HttpApplication pool
- In either case, when the last HttpApplication instance is disposed of, the Application_End event is invoked
- Just before the Application_End event is called (technically, this will happen every time an HttpApplication instance is disposed of), KeepAlive-Server/Open-KeepAlive will make a request to a .aspx page designated in the web.config file, thus reinitiating the HttpApplication pool
- As a result, the initial delay that is the natural consequence of a page request after recycling, will not occur. KeepAlive-Server/Open-KeepAlive will have already made that request automatically
There are a number of factors that cause the Application_End event:
- Machine.Config settings, may dictate that the HttpApplication process be recycled at regular
intervals or when the appropriate memory conditions are present (see machine.config's processModel tag).
- web.config changes. (Note: this works when NOT using ftp clients. When using ftp clients to upload the changes to web.config, you will need to refresh your site manually)
- .dll changes
|
Setup
General:
Since KeepAlive-Server/Open-KeepAlive is implemented as an HTTP Module it requires no changes to any source code.
- Copy the KeepAlive-Server/Open-KeepAlive .dll in the /bin directory.
- Modify the web.config file as explained below.
Web.config modifications:
The Typical web.config file may already contain the following sections, if not, you will need to add the missing sections.
<configuration> <configSections> <!-- here is where sectionGroups will be defined --> </configSections> <system.web> <!-- here is where the sectionGroups defined above will be implemeted --> <httpModules> <!-- here is where the httpModules are added --> </httpModules> </system.web> </configuration>
In order to setup KeepAlive-Server/Open-KeepAlive, the web.config file, will need to nest the following code inside the above structure:
<configuration> <configSections> <!-- here is where sectionGroups will be defined --> <!-- define the configuration section needed by KeepAlive-Server/Open-KeepAlive --> <sectionGroup name="system.web"> <section name="keepalive" type="XepientSolutions.XSLibrary.XSKeepAlive.KeepAliveConfigurations.KeepAliveConfigurationHandler,XSKeepAlive" /> </sectionGroup> </configSections> <system.web> <!-- here is where the sectionGroups defined above will be implemeted --> <!-- instantiate the configuration section needed by KeepAlive-Server/Open-KeepAlive --> <keepalive automaticRequestHours="1" logFileCacheHours="24" logFileVirtualPath="~/XSKeepAliveLog/KeepAlive.log"> <urls> <add url="http://www.your_site.com/your_page1.aspx" /> <add url="http://www.your_site.com/your_page2.aspx?parameter=value" /> </urls> </keepalive> <httpModules> <!-- here is where the httpModules are added --> <!-- implement the functionality of KeepAlive-Server/Open-KeepAlive --> <add type="XepientSolutions.XSLibrary.XSKeepAlive.XSKeepAlive,XSKeepAlive" name="XSKeepAlive" /> </httpModules> </system.web> </configuration>
Web.config modifications explained:
The following is an explanation of what each section will do, and how to configure the attributes needed to optimize KeepAlive-Server/Open-KeepAlive.
Section: <keepalive>
The keepalive section contains the following attributes that apply to all the urls to be kept alive:
- automaticRequestHours attribute. This parameter allows you to specify a time interval in Hours, at wich the module should make requests to the urls specified in the urls section. This function is a cache unload callback. This means that if this parameter is set, a cache entry is made and marked for expiration at the time interval you specify. Since cache is recycled by the runtime when resources are needed, the time interval is only approximate, as it may happen befrore or after your specifications. Even if Cache is dumped from memory at an earlier interval, the requests would be made in any case.
The next two parameters will allow you to keep a log of when the module is invoked. This is usefull if there are any errors that you want to track. If you keep the two parameter blank, or delete them, there will be no logging, which is desireable in a stable environment.
- logFileCacheHours attribute. The absolute time that you want a log to be kept for, before it is overwritten.
- logFileVirtualPath attribute. The virtual path where the log file will be kept. If the directory does not exist, it will be created automatically. Make sure that the ASPNET user (win2k) or Network Services (win2003) has r/w access to the root.
Section: <urls>
The urls section allows you to specify multiple urls that should be refreshed. Note that all urls must be in the same domain.
- url attribute. This is where you indicate what page to call in order to keep your site responsive. If you are pointing to your default page, there is no need to put default.aspx in the url.
|
|
| |
|
|