Caching for Fun and Profit: Or why would you ever cache a page for 5 seconds?

There are a lot of ways to cache data. You can cache a piece of data, a query, a page fragment, an entire page, or an entire website. You can cache to local memory, local file storage, distributed memory, distributed file storage, a front cache, or a Content Delivery Network (CDN). You can cache for ever, until the process regenerates, 5 years, 5 months, 5 days, 5 hours or 5 minutes. Heck, it might even, depending on the system, make sense to cache something for 5 seconds. Maybe less.

Why would I cache something for 5 seconds?

I know, I know, it seems silly to cache something for 5 seconds. You probably think this is a silly attempt at a ridiculous headline to grab clicks. However, let's explore. To get much benefit from caching, cache the content longer than the service time. The service time is the total amount of time it takes to service the request and return the desired item. As an example, if a piece of content takes 5 seconds to generate, the service time is 5 seconds. To get any real benefit, we should cache the content for longer than 5 seconds.

What happens if the service time is longer than the cache time?

If the service time is longer than the cache time, requests for the piece of content will queue. With caching, we want to AVOID queuing, so it's important to know the service time of the call under a variety of circumstances. You mathematical types can read up on Little's law, if you are curious: http://en.wikipedia.org/wiki/Little%27s_law

A practical example

Now, most cachable content has a service time of less than 5 seconds. Let's talk about what would happen in 2 identical systems. To make things simple, we'll pretend the following:
  • There is only one process
  • The service time of the process is 1 second
  • The request levels are 1, 5, 15 and 30 requests per second.
  • The non-cached system is real time, the cached system is cached for 5 seconds
In the non-cached system, here's how the requests per second (RPS) would look during 1 traffic hour:
  • 3,600 @ 1 RPS
  • 18,000 @ 5 RPS
  • 54,000 @ 15 RPS
  • 108,000 @ 30 RPS
WOW! I bet we'd have some major problems in a real time system under these conditions. Let's compare with the system using a 5 second cache:
  • 720 @ 1 RPS
  • 720 @ 5 RPS
  • 720 @ 15 RPS
  • 720 @ 30 RPS
Hmm, that looks odd. The requests in the 1 hour period never get over 720. Seems like an insurance policy against load.

Let's look at the amount of requests we save at each of the levels:

  • 3,600-720=2,880 @ 1 RPS
  • 18,000-720=17,280 @ 5 RPS
  • 54,000-720=53,280 @ 15 RPS
  • 108,000-720=107,280 @ 30 RPS

Wow! By caching for 5 seconds, we saved between 2,800 = 107,280 requests per hour.

What's more interesting we can see we established a service ceiling for our system. We'll never generate more than 720 requests an hour. No matter how many times the link goes viral on www.FunnyCats.com. As traffic rates increase, the value from a 5 second cache also increases. In a world full of email blasts, viral links, email, IM, social media, we see more and more bursts of traffic. As traffic bursts, we approach the natural threshold of a system. A system can only go as fast as the slowest part, (http://en.wikipedia.org/wiki/Amdahl%27s_law) so we need to make sure the slowest part is good enough for what business problem we are trying to solve.

So should we cache everything at 5 seconds?

A 5 second cache isn't the answer to every problem though. Some content can't be cached at all. Like a shopping cart. Some content can be cached forever, like static content (named with a version number). Some content types do not seem cachable, but maybe could possibly be. An example would be a page listing inventory. Perhaps the business is able to fulfill limited quantities of out of stock items. Maybe the products don't change often and come in all the time. In this case, it might be ok to cache inventory for 5 seconds and handle out-of-stock items by delaying shipment. The right answer depends on the business problem and the constraints on solutions. Which is a better problem to have, a down website, or a few out-of-stock orders to deal with?

Just for fun, let's look at the difference in caching for 5 seconds and caching for 5 minutes over 1 traffic hour:

  • 720-20=700 @ 1 RPS
  • 720-20=700 @ 5 RPS
  • 720-20=700 @ 15 RPS
  • 720-20=700 @ 30 RPS
The new service ceiling is 20 requests per hour. This is better than 720, for sure. However the savings aren't as dramatic as the no-cache to 5 second cache example. The reason why this is important is because we must balance the needs of the business with the needs of the system serving the business needs. Maybe the business can't afford to have information stale for 5 minutes, but 5 seconds is a reasonable level. You'd only have to have your system able to support 720 hourly requests, versus 108,000. You can get away with a lot more at the 720 RPH (requests per hour) level than you can at 108,000 RPH. I put together some charts showing the point of diminishing returns on longer cache intervals. The first chart shows the total number of requests in a 30 minute period at different traffic level times. Note the 5 minute period as the point in which there is no benefit visible on the chart.

The second chart shows the total number of requests in a 4 minute period at different traffic level times. Note again, the 5 minute period as the point in which there is no visible benefit, considering the starting point.

The answer is, as always, "It Depends"

The right time to cache a piece of content really depends on all the elements in the equation. Caching, even in non-intuitive ways, can be used to solve business problems within the available solution constraints.

Why my computer shut off automatically

One of my laptops used to immediately shut off. This always happened to me when I was in the middle of working on something important. Since the shutdown was immediate, not graceful, I would lose all my unsaved work.

I noticed this usually happened after the fan had been running. The fan would run at high speed for a while, then the computer would immediately shut off.

After a few months of this, my amazing powers of deduction led me to take apart the computer looking for some hardware issue. Here is what I found:

Apparently, there was a lot of dust blocking the fan exhaust. Once I removed all of this, the computer has always worked perfectly. It has not shut off automatically in 6 months.

I have no idea where this dust came from, by the way. I promise we are clean people!

What To Do When A Hard Drive Fails

When a hard drive crashes, you can lose all your data. Corrupt hard drives happen out of the blue and for seemingly no good reason. If your hard drive fails, what can you do?

One option is to call a hard drive recovery company. If your data is worth a lot of money to you, you can pay a forensic computer company to get the data off your hard drive. Before you write a check though, try a little Do-It-Yourself first.

What is going on inside the hard drive is a bunch of little platters spinning at high speed. When data is accessed or written to the disk, a little head (sort of like on a record player) moves to the right spot and does it's magic. The space between the head and the platter is very very tiny. Freezing the hard drive will shrink the head and the platter ever so slightly, often allowing you to read data.

Here is how I got the data off of a failed hard drive.

  1. Remove the hard drive from the computer.
  2. Place the hard drive inside of a zip top freezer bag. (don't buy a cheap bag.)
  3. Place the wrapped hard drive inside of ANOTHER zip top freezer bag. (yes, you need to do this) (see figure 1 below)
  4. Place the double wrapped hard drive in the coldest part of your freezer.
  5. Leave the hard drive in the freezer for 12 hours at least. You want it good and cold! (see figure 2 below)
  6. Once very chilled, install the hard drive in your computer and start pulling off data. Begin with the most valuable data.
  7. At some point, the hard drive will fail again. When it does, mark the last successfully copied data, pull out the hard drive, double wrap it again and stick it in the Chill Chest for another 12 hours.
  8. You may need to do this a number of times to get all the data you want, or until the hard drive stops working completely.

Double Wrapped Hard Drive

Hard Drive in the Freezer

New Northern Virginia ColdFusion User Group

A new ColdFusion User Group has started in Northern Virginia. Run by Denny Springle, this group will serve Northern Virginia's ColdFusion and Flex developers. The initial NVCFUG meeting, topic "CF Coding Standards, Code Refactoring and Code Re-Use", is tomorrow night, Feb 16th in Fairfax, VA.

So, if you are anywhere remotely close to Fairfax, please come out and support this new group!

Check out Meeting Information and NVCFUG information.

4551 Views Print Print Comments (0) Wow

So you wanna convert Open Office Documents to Wiki format?

While working on some Model-Glue documentation we needed to convert an open office document to TracWiki format. I'm not fluent in TracWiki and I certainly didn't want to manually format 30-40 pages. Thankfully, there is an Open Office --> TracWiki conversion macro that will automate pretty much all of it. It helps if you used the Styles features of Open Office because the TracWiki will be cleaner, but no worries, it'll convert it anyways if you didn't. Here is how it works.

  1. Open the Open Office document you want to copy text from. We'll call it the Source document.
  2. Set the macro permissions to Medium or Low by going to the menu -> Tools -> Options -> Open Office.org -> Security -> Macro Security
  3. Download and open the Open Office Template Macro (ODT file)
  4. Remove all text in the newly opened ODT file.
  5. Highlight the text in your Source document, copy it, then paste it into the ODT file.
  6. Press the button with the correct format, the text will be converted to the correct wiki format and copied to the clipboard. (English is on page 2)
  7. Paste the text from the clipboard into the edit box in your wiki.

You now have converted Open Office document text to wiki format.

The conversion picked nearly everything. I manually cleaned up white space issues and also added in code blocks around all the source code sections, but I was very pleased with the amount of work handled by the OpenOfficeToTracWikiScript.

To The Most Courageous Woman I Know

This year has been a year of turmoil and also a year of blessings. Most years are like that, though this one has been particularly full of highs and lows. I wanted to take a moment to give a shout out to the most courageous woman I know.

My cousin, Erika Bogan was badly injured in a terrible car crash in early 2002 when she was ejected from the vehicle, suffered major damage to her spinal cord and was in a coma for 10 weeks. When she woke up, she found she was paralyzed from the waist down. Imagine for a moment, what it would be like to be riding in a car one second, awake in a hospital the next second to be told 10 weeks had gone by, and by the way, you'll never walk again.

Erika had a long road ahead of her. She had a lot of choices to make and none of them were easy. You can read more on her story on her blog.

Erika became an advocate for people with disabilities and became active helping and inspiring others. This year, Erika competed for and won the Ms. Wheelchair North Carolina 2009 title. She then competed against tough competition to win Ms. Wheelchair America 2009 title. We are all very proud of her.

The mission of Ms. Wheelchair America is to provide an opportunity for women of achievement who happen to be wheelchair users to successfully educate and advocate for the more than 52 million Americans living with disabilities. In her short term as Ms. Wheelchair America, she's:

  • Served as Participant, Mentor and Speaker at Camp Discovery
  • Learned to Surf, through Life Rolls On (Yay for surfing)
  • Honored as Guest speaker for the Real Economic Impact Tour Kick-off on behalf of the IRS and the NDI along with Robert David Hall from CSI, at the National Press Club in D.C.
  • Visited the White House

As we roll (pun intended) into the Thanksgiving holiday, I'd like to pause and give thanks to Erika for her inspiration to me and to the many people she's impacted with her life.

If you are interested in learning more about Erika, the Ms. Wheelchair America competition or advocacy for the disabled, you can:

Erika Crowned Ms. Wheelchair America

Erika Before Speaking to the IRS and the NDI

Erika with CSI's Robert David Hall

"Come to the edge, he said. They said: We are afraid. Come to the edge, he said. They came. He pushed them and they flew." -Guillaume Apollinaire

My Brother the Alligator Wrestler

I'm from Florida, as you know. Florida is home to Alligators, a much maligned animal that generally doesn't deserve such an awful reputation. My brother wrote me to tell me of a recent gator encounter on the beach last night. I'll let him tell the story:


So the kids and I decide to go for a quick walk on the beach last night before homework and dinner...

As we are walking down the beach we see some commotion up ahead and decide to walk down there and see what's going on. As we get close I can see a 7 foot alligator and a guy with a cast net on the freaking beach! This is my second encounter with gators on the beach, the first was surfing on Vilano and a gator swam by outside the line up. This one is equally as weird!

We get up to this gator and you can tell it is very tired from swimming in the ocean, the wind and waves have just beat his butt cause he wants nothing to do with us unless we grab his tail, then he lets us know without question that he is pissed. Tail thrashing, hissing, chomping of the jaws, the whole bit. So a lifeguard comes up to us and while talking to him he says he has to call a trapper who will come and likely kill the gator because it will be seen as a nuisance to humans. So my kids and this other fellas kids start talking about how we should save the gator. So between the kids, tourists and hippy residents down on the beach this guy (Paul) and I become the "gator savers". It's at about this time my kids decide I'm freaking nutz for the plan we hatch.

[More]

How Many Zeros In A Million

This blog hit over a million total views today. Well, I think it was today, I can't be sure.

Last week I noticed the page count was somewhere near 990k and I wanted to get a screen shot of when the site rolled over to a cool million. It looks like I missed it by a few hundred. Oh well, I guess I can try to pay better attention when I hit a billion. (Heh.)

So thanks to those who come and read articles from nodans.com. I hope you found them as helpful to you as they were to me when I wrote them.

Bluetooh Headset: Plantronics Voyager Pro Review

I wrote about wanting the Plantronics Voyager Pro bluetooth headset a few months ago and left the reader with the promise of a review. Well, here it is.

In short, the Plantronics Voyager Pro is well worth the money. I paid $100 when I purchased it from Best Buy (the only place that had it in stock) and the price meant this headset would have to perform in the top 5% of all headsets for me to be pleased. The good news is the headset excelled in all categories. Stop reading this now. Go get one.

Things I like

  • Super long battery life
  • Very quick charging
  • Very comfortable wear
  • Good noise cancelling for constant background noise
  • Seems hard to break

Things I don't like

  • --- editors note: do I have to make up something to put here before I release this article? I want people to think I'm fair and balanced, not in love with this headset, which I actually am.

The headset I'm replacing

I replaced an Aliph Jawbone 2, which I didn't like at all over the Jawbone 1. Both Jawbones have less battery power than the Plantronics Voyager Pro and both Jawbones are likely to break when placed in a pocket, unlike the Plantronics Voyager Pro. Both Jawbones are likely to pop loose from my ear as well, whereas the Plantronics Voyager Pro is much more likely to stay on my ear, even if I shake my head like a dog, or a death metal rocker.

Info On The Plantronics Voyager Pro

If you want, you can watch this simple video demonstration of the Plantronics Voyager Pro Bluetooth Headset.

It looks like the price is holding around $99 dollars, pretty much what I paid for it. See results and reviews at the Google Products page for the Plantronics Voyager Pro so you might as well head to the local Best Buy and pick one up. After 2 months of continual use, I am completely happy with the Plantronics Voyager Pro and don't miss either my Jawbone 1 or my Jawbone 2 in the least.

New Bluetooth Headset On Order

I live and die by bluetooth headsets. Holding the phone up to my ear during a long conversation is as annoying as being covered in sugar water and buried in a Fire Ant hill. I'm just not very happy doing it.

I loved the Aliph Jawbone Headset. Apart from some issues with the charger, that was the most perfect headset ever invented. The Aliph Jawbone 2 was demonstrably worse in all ways, including call quality. I've been on the hunt for a new headset ever since.

Today I found the Plantronics Voyager Pro and am ordering it right now. Rather than bore you with the details of how the Plantronics Voyager Pro deals with a barrage of noise, a cacophony of wind and other call quality reducers, I'll leave it to you to watch this simple video demonstration of the Plantronics Voyager Pro Bluetooth Headset.

Want one?

It seems Best Buy is the exclusive source right now. Amazon shows a month back order. I'm going to get mine from Best Buy today. If there is enough interest from the readers of this blog, I'll post periodic reviews of the Plantronics Voyager Pro Bluetooth Headset. Whaddya say? Do you guys/girls care about what I think of this product?