Murat Yasar - Asp.net Application Warm Up By Utilizing Windows Service
When you make a request to get a page from any Asp.Net application,
it takes server some time to respond your request with
office 2010 activation key . In the course of this
waiting period, some server side tasks occur.
Application Life Cycle generally According to MSDN:
1-)User requests an application resource from the Internet server.
2-)ASP.NET receives the first request for the application.
3-)ASP.NET core objects are created for every single request.
4-)An HttpApplication object is assigned for the request.
5-)The request is processed by the HttpApplication pipeline.
When
a request is produced to an application the first time, ASP.NET
compiles application items. This very first request's response will be
slow due to compiling method that is getting completed by ASP.NET. After
this compilation method, the subsequent requests can get more quickly
response than the very first time response.
But if any of the
following occurs, this compilation approach takes spot once again, in
other words they will lead to an application restart.
* Whenever you modify the supply code of your Web application.
* Any time you add, delete or modify assemblies from the application's Bin folder.
* After you add, delete or modify localization resources from the App_GlobalResources or App_LocalResources folders.
* After you add, delete or modify application's International.asax file.
* When you add, delete or modify source code files in the App_Code directory.
* Whenever you add, delete or modify Profile configuration.
* Whenever you add, delete or modify Web service references inside the App_WebReferences directory.
* Once you add, delete or modify the application's Net.config file.
All
pending requests will be served by the existing application domain
along with the old assemblies ahead of restarting application domain, if
an application restart is expected.
Other than above items, an application pool can be restarted based on its own settings.
When
this application restart takes place, we have to wait for some time to
acquire response from the server if we hit it the first time. Waiting
could be tolerable in some circumstances but not each of the time. The
application could possibly be very important or just annoys us to wait
to acquire response from the application. Additionally, do you consider
the guests are patient sufficient to wait?
If
you serve your application from shared hosting environment and don't
have much control over application pool settings, in addition you are
able to not set isolated application pool for your application and other
application causes to restart the application pool you happen to be in
and as a result you've got to wait just after each application pool
restarting within the server. There is a answer they're able to offer
you but what for those who don't choose to spend added cash for this..
While
I was thinking feasible solution for this, I thought if I could
generate a request periodically to my application, I'd not get a late
response. Because I may possibly be capable of warm up my application
devoid of waiting the initial request to hit my app.
Afterwards I
started contemplating a method of building request automatically. I
thought that a windows service may be really valuable. What I did was
basically I built a windows service which creates a request to URL's.
The URL addresses is read from an xml file called settings.xml.
Not
very effective but it is possible to sort of get an facts about your
web application up time by inspecting logs that the service keeps.
Should you look at the supply code you are going to see that a status
code returns from every single requests. If particular code isn't
returned, we take them as error and wrote its code into log.
Even
even though the remedy appears suitable, there is a single drawback. We
require a machine which will run continuously with an net connection.
Now,
I am going to attempt to clarify every step I've taken and it is best
to at the same time if you wish to apply this resolution. All files,
executables, pictures utilised in this article are downloadable and you
can see those files in the finish of this writing.
This settings.xml
file should really be in the identical path where service's executable
file stays. It is possible to write as several URL addresses as you
would like produce request to, enable or disable logging, specify how
frequently we should generate request to URL.
All these settings may be performed inside settings.xml file.
I wrote this windows service by employing;
----------------------------------------------------
Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.five SP1
on Windows Vista Property Premium Service Pack 2
These three has to be set "Restart the Service" otherwise the service will not work as it can be expected.
After
waiting the time you specified in settings.xml file between 3 tags,
you'll want to be able to see the log inside event viewer with the key
"WarmUpAspNetApp Service". Once again I assume you've adequate privilege
to write into event viewer. I use Windows Event Viewer to keep log on
these requests. You could implement some other mechanism while you've
the source code. Writing into txt file, or sending an e-mail when an
error occurs or something else you appreciate with.
If you do any
changing in settings.xml file, you must restart the service manually in
order to take effect those changes. Otherwise, it will take effect just
after the service restarted by its logic.
I have explained
every single step I've taken here with screenshots in the following
link. It is possible to also download the answer file, only necessary
files to install the service as well as the screenshots from this link
also.
* Right click on the service and choose "Start" for beginning the service.
Setting
"Restart the Service" for 3 type of failures is pretty crucial. For
those who don't do this, service will not be able to restart itself, if
something goes wrong though it is becoming runned. Also every 10 hours,
service is being restarted in case any
windows 7 activation key memory leak.