One’s and Zero’s

Technology at it’s best and its worst

My Experimental Fix for the “Digg Effect”

October 16th, 2007 by Nate

DiggWith the increase of large social networking sites, like Digg, Slashdot and Reddit popping up all over the web, it’s getting easier for the small-time bloggers to get their often well-deserved hour in the spotlight. All it takes is one interesting blog entry and one of your visitors taking a moment to share it with visitors of one of these bigger sites. What most bloggers don’t realize until it happens to them is an appearance on the front page of any one of these sites (which usually happens due to some sort of proprietary visitor voting system) could make your blog come to a very unexpected and immediate halt.

Some of these large social networking sites are so busy in fact, that often times the very minute your entry appears on the front page, hundreds or even thousands of curious people have already clicked to your blog to read your entry. Most small-time websites aren’t prepared for this kind of influx of traffic.

There are ways to optimize your blog to help remedy this problem, but there is no guaranteed fix short of paying an arm and a leg in extra server costs. So what do you if your blog does end up succumbing to the flood of visitors?

Introducing CoralCDN.

CoralCDN is a decentralized, self-organizing, peer-to-peer web-content distribution network. CoralCDN leverages the aggregate bandwidth of volunteers running the software to absorb and dissipate most of the traffic for web sites using the system. In so doing, CoralCDN replicates content in proportion to the content’s popularity, regardless of the publisher’s resources—in effect democratizing content publication.

In basic terms, CoralCDN can make a copy of your blog entry or web page (including pictures) and host it on these volunteer servers so people can still read your entry! Ideally you would want people to come to your blog directly, but this is the next best thing if your blog does go down.

So how do you use CoralCDN?
To use CoralCDN, a content publisher—or someone posting a link to a high-traffic portal—simply appends .nyud.net:8080 to the hostname in a URL.

By appending .nyud.net:8080 to the end of your host name (i.e. http://www.1s0s.com.nyud.net:8080/your_entry) visitors can reach a copy of that same page. It’s not really important HOW CoralCDN accomplishes this (although if you are interested, you can read more on their website). The important thing is harnessing this awesome service in a useful way.

Enter the unprecedented fix

Okay here’s where we have to get just a little more technical but bear with me and read this part more than once if need be.

On most web servers you can run a command called “uptime”. When you run this command it will return some text to you that will look something like: “09:53:15 up 119 days, 19:08, 10 users, load average: 3.73 7.98 0.50″. It’s at the end of this returned information that that we’re interested in. Load average.

Load average tells you how busy your web site or blog is. The first number, in this case 3.73 indicates how many processes were running (on average) in the last 1 minute. The second number 7.98 indicates the same thing for the last 5 minutes, and the last number indicates the last 15 minutes.

If through some server side code, in our web page, we determined what that first number was (lets say 36.73 for example) and at the same time decided on a maximum load (lets say 30.00 for example as this may be indicative of the “Digg Effect”) we can tell our web page that 36.73 is too high of a server load and that we want to start redirecting the page to the CoralCDN copy! Instead of running hundreds of lines of code, dozens of database calls, loading images, et (as is the case with most blogs), we run just a few lines of code (thus using hardly any resources) and redirect the visitor to CoralCDN (this time using NO resources). The result is your blog has time to catch up to this huge demand of traffic and visitors never get the dreaded “Page has timed out”.

Since PHP is one of the more commonly used languages for blogs and websites I’ll present the code for just such an experiment. This code should be pasted above all other code in your web page. If you are using wordpress, you can place this inside index.php at the very top (just below < ?php ).

-------------------------------

$cpuload = get_cpu_load();
$maxload = 30;
if((float)trim($cpuload[0]) > $maxload && !strstr($_SERVER[”HTTP_USER_AGENT”], “CoralWebPrx”)) {
header(”Location: http://” . $_SERVER[”SERVER_NAME”] . “.nyud.net:8080″ . $_SERVER[”REQUEST_URI”]);
exit;
}

function get_cpu_load() {
$cpuload = shell_exec(”uptime”); //looks like this 09:53:15 up 119 days, 19:08, 10 users, load average: 3.73 7.98 0.50
$cpuload = explode(”:”, $cpuload);
$cpuload = trim($cpuload[4]); //looks like this 3.73 7.98 0.50
$cpuload = explode(”, “, $cpuload);
return $cpuload; //[0] 1 min [1] 5 min [2] 15 min
}

Posted in Coding, Computer | No Comments »

iPod Building

September 8th, 2007 by Nate

This building is at Avenida Santo Amaro in São Paulo SP, Brazil. Take a close look at the side of the building. Someone has redone the exterior of two floors of the building in the shape of an iPod:

iPod building

Posted in Computer Art, Gadget | No Comments »

iPod Video

September 8th, 2007 by Nate

Like no other iPod video you’ve seen before…

ComiPod video

Posted in Funny, Gadget | No Comments »

Printer Frustration

August 18th, 2007 by Nate

ah, wouldn’t we all like to do something like this from time to time:

Posted in General | No Comments »

Compusa Service

July 22nd, 2007 by Nate

Hmmmm, what exactly is Compusa offering here?

Compusa Service

Posted in Computer, Funny | No Comments »

You awake to find yourself making out with a hedgehog!!!!

May 18th, 2007 by Nate

You know you’re in for a strange day when you get this on your Nintendo DS

Nintendo DS WTF?

Posted in Gadget | No Comments »

Spam Trap

May 17th, 2007 by Nate

A Geek solution to all the spam that comes via fax:

Spamtrap

“Spamtrap” - watch the video

Posted in General | No Comments »

There’s A Reason That You Slow Down At The Toll Booth

May 17th, 2007 by Nate

Yes, there is a very good reason why you should slow down at the toll booth:

Posted in Video | No Comments »

Cool Traffic Light Art

April 19th, 2007 by Nate

While I’m not sure how legal this is, it makes the traffic lights a lot more interesting:

Traffic Light Art

Traffic Light Art

Traffic Light Art

Posted in Art | 1 Comment »

If A Geek Were To Build A Toilet

April 16th, 2007 by Nate

If a geek were to build a toilet, this is what it would look like.

Geek Toilet

I especially appreciate the glass of beer on the side table ready and waiting…

Posted in Computer | 1 Comment »

« Previous Entries