This post talks about how I sped up a good chunk of my page loads by 6-10 seconds (no joke) and why I had such terrible load times to begin with.

What Happened?

My blog pages run on PHP, but every other page on my site is part of a .NET web app. By default, IIS will shutdown a web app after 20 minutes of idle time to save resources. Shared hosting providers often crank that time down even further as a cost saving measure. My host uses a timeout of 5 minutes.

In other words, if no one visits my site for 5 minutes, it shuts down, and the next person to visit gets to wait for IIS to start it back up. Unfortunately, Coder’s Block does some pretty heavy lifting on startup:

  • It uses SuperFeed to reach out to 6 social media APIs, parse the results, and display them as a feed on my home page.
  • It dynamically resizes and crops the images shown within the feed.

This is where the 6-10 second delay comes from. I cache the results, but the cache is wiped every time IIS shuts down my site — which is pretty often, given that short 5 minute window.

Update: My site doesn’t run on shared .NET hosting anymore, so I no longer have this problem. But for a while, the solution described below served me well.

The Game Plan

Here’s the plan: make something that pings my site every 4 minutes. In theory, this ensures my site is never idle for 5 minutes, so IIS won’t shut it down, the cache stays alive, which means subsequent page loads don’t have to redo all that heavy lifting, cutting out that 6-10 second delay. How’s that for cause and effect?

And so I wrote a tiny utility that lets my site ping itself every 4 minutes. My site is basically talking to itself to stay awake.

Introducing EverPing

All it does is hit a URL, repeatedly, on a given time interval. Here’s how you use it:

EverPinger.Start("http://codersblock.com/ping", 240000); // every 4 minutes

Yep. Seriously, that’s it. Check out the EverPing GitHub repo and you’ll see there’s not much under the hood, either.

The Results

Results were… Alright. The average startup-to-shutdown time of my site went from about 5-10 minutes to about 1-2 hours. A nice improvement, although it’s clear my site is still getting the occasional shutdown for reasons other than being idle. That’s life on a shared host, I guess.

Also, it’s worth noting that I could just use a service like Uptime Robot, even if it is overkill for what I need. But hey, sometimes it’s more fun to make something yourself.