Archive for the ‘video’ Category

Consistent Memcache Hashing and Failover with PHP

Monday, August 11th, 2008

I’ve written about Memcache before because it’s one of the best pieces of software written. It’s power lies in it’s simplicity and how easily you can plug it into any application. One of the things I really wanted was to implement consistent hashing and failover.

After checking out the PHP/Memcache documentation, the code to achieve this is fairly simple:

ini_set('memcache.allow_failover', true); // default is usually true
ini_set('memcache.hash_strategy', 'consistent');

Somewhere in your configuration/initialization script, make sure these memcache settings are in place. Allow failover tells the memcache client to try another server if it cannot connect to a particular memcache daemon. The hash strategy is pretty self explanatory. Now onto the actual server code:

$failCount = 0;
$realInstance = new Memcache;
$testInstance = new Memcache;
 
$servers = array("server1", "server2", "server3");
$defautlPort = '1';
foreach($servers as $host) {
    if($testInstance->connect($host)) {
        $realInstance->addServer($host);
        $testInstance->close(); // only close if connection was success
    } else {
        $realInstance->addServer($host, defautlPort, true, 1, 1, -1, false);
        $failCount++;
    }
}
$isConnected = true;
if($failCount == count($servers)) {
    // set false if every server is marked as failed
    $isConnected = false;
}

I use two instances of Memcache (might not be most optimal solution) to check the availability of that server and if it is available, add it to the pool with all of the default options. If it is not available, set up the connection to automatically failover but also maintain its position in the server pool. These options are set using this paragraph from the PHP docs:

bool Memcache::addServer ( string $host [, int $port [, bool $persistent [, int $weight [, int $timeout [, int $retry_interval [, bool $status [, callback $failure_callback ]]]]]]] )

retry_interval: Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry.

status: Controls if the server should be flagged as online. Setting this parameter to FALSE and retry_interval to -1 allows a failed server to be kept in the pool so as not to affect the key distribution algoritm. Requests for this server will then failover or fail immediatly depending on the memcache.allow_failover setting.

There’s also error checking to ensure that at least one server is online to be considered connected to a memcache pool.

Classic Children TV Shows

Tuesday, July 15th, 2008

Found these two videos on Youtube and it really brought me back to the good ole days:

Camp Videos: The Nostalgia Song:

Classic Nickelodeon Show Intros:

Sopcast and TVAnts: Stream Live TV or Movies From Home

Sunday, June 22nd, 2008

I’m a really big sports fan, especially soccer. Living in the United States, this means that most international games are always 7 or more hours earlier than usual, and sometimes, they don’t even broadcast locally.

Using Sopcast and TVAnts, I’m able to watch any game I want, when I want. Granted, this is streaming P2P video so it is not the best quality and due to the latency, images can get choppy. For popular content like the current Euro 2008 or most UEFA Champions League matches, speed and quality can rival that of Vimeo or Youtube.

After painstakingly getting Sopcast to work on my linux box, I found this really easy to use tutorial on installing both Sopcast and TVAnts:
http://simonsmess.blogspot.com/2007/11/watching-sopcast-tvants-on-ubuntu.html

For TVAnts, get a link from a website or open the program under wine, double click a channel and write down link from popup box. This will start the stream on your local computer where you can use VLC or other capable media programs to view that stream.

With Sopcast, the method to start the stream is very similar. You can download the actual program and run it under wine or use the command line version which also creates a stream from your local computer like TVAnts.

Now that you have a link and you are streaming, use your favorite media play to stream or record that link. My favorite, VLC, makes it fairly easy to open and save that link. To just open the link, VLC has an option under “File” >> “Open Network Stream”. To save the stream is the same except you specifiy where you want your stream to be saved.

In order to provide Tivo-like recording, I use my crontabs to start and stop the stream. Here is a pretty good tutorial on using crontabs. Of course it would be much easier to use MythTV if the content was available on your tv, but Sopcast and TVAnts provide a way to accomplish almost the same functionality with a more work.

March Madness On Demand and Akamai

Thursday, March 20th, 2008

March Madness is the best tournament on earth. For 3 weeks during the end of March and beginning of April, 65 college football teams square off in an orgy of upsets and thrillers. This year, CBS expanded its online on demand live streaming. Working all day, the only time I have to watch games are at night. By streaming the videos, it gives me a chance to at least listen to the games while I work. This way everyone wins: I get to keep track of my favorite games and CBS gets to serve me more ads.

Being a geek, I really wanted to see how the March Madness on demand service will handle the bandwidth of serving the video. I found this InformationWeek article that points out that Akamai is used to stream their videos. This makes sense because Akamai has always been a huge player in the contend delivery market. From their site, Akamai claims it “handles 20% of the world’s total Web traffic.” Now those are big numbers. Even with Akamai’s large content delivery network, “CBSSports.com monitors and throttles its system based on usage and historical data patterns” so that it won’t overload their system. The fact that CBS has to restrict the amount of people using this service shows how far the US has to go if it wants to be completely digital.

For really cool visualization of global web traffic, check out this Akamai flash app.