Alvin Stefanus
Alvin Stefanus

Reputation: 2153

MVC: Keep alive or make the initial load super fast

The goal is that I want my overall website response time to be instantaneous.

The problem is that I do no have IIS access, my website is hosted using external service and I have no control to the IIS panel.

My current approach now is having a scheduled code that keeps my website alive. The problem with this only approach is the hosting service has an algorithm to shutdown all their hosted website like every some hours.

This is why I need to implement another approach which to warm up / pre-load the website each time it runs.

How to do this when there is no access to the IIS panel?

Upvotes: 1

Views: 1087

Answers (2)

user585968
user585968

Reputation:

The solution requires no 3rd party sites; robots; or apps, you merely write a very simple app yourself that periodically performs a trivial web function, perhaps a REST GET. By performing this function say every few minutes not only do you guarentee that the IIS pool won't timeout and be cold for a client, but it also has the nice effect of ensuring your website is up and running in a warm condition (JIT'd; and running) ready for a real request for your non-heartbeat website requests.

e.g.

In your website expose a REST API, say www.misspiggy.com/api/hiyaaaa that does nothing other than to return HTTP 200 OK.

By implemententing this in your ASP.NET app, any request to the above URL will cause your stopped or cold ASP.NET website to be JIT'd during:

  1. first deployment (and even then only during a request is made to it)
  2. after the IIS AppPool has timed out and needs to restart on demand

The client code that makes the REST request can be anything:

  • a console app
  • a Windows service
  • WinForms/WPF app

The console app can be triggered to fire via Windows Task Scheduler say every 5 minutes thus saving you the hastle of building in a scheduler.

My current approach now is having a scheduled code that keeps my website alive. The problem with this only approach is the hosting service has an algorithm to shutdown all their hosted website like every some hours

I suggest you set your ping period to be a matter of minutes rather than hours.

No admin access to server required

The problem is that I do no have IIS access, my website is hosted using external service and I have no control to the IIS panel

It should be pointed out that this solution does not require you to install anything new on the server nor make any changes on the server.

Azure

It is interesting to note that Azure Application Insights has Availability Tests that though designed for testing web site availability, can be used for this exact same purpose of keeping your website alive and warm ready to go for web clients. In fact this is what I do for my web apps.

Doing so keeps response times and latency as low as possible.

enter image description here

Upvotes: 5

Macilquham
Macilquham

Reputation: 282

There are a number of things you can do but a real simple solution is to use a website monitoring site something like statuscake or uptime robot there are a large number of them out there. You set them up call a page or pages on your website at set intervals to ensure it is still up this has the added bonus of keeping the site warm.

I would also precompile your mvc app if you arent already doing that.

HTH

Upvotes: 0

Related Questions