Archive for the ‘Tech Notes’ Category

Amazon’s Elastic Compute Cloud for Low-Use Game Hosting

Thursday, December 31st, 2009

My friend Dan and I enjoy playing first-person shooters, where it’s just the two of us going head-to-head in a game.  It’s something we’ve been doing off and on since the days of serial cables connecting two Commodore Amiga’s in one room.  Dan has since moved across the country from me, but the growth of the Internet and gaming technology has allowed us to keep the gaming going, even if it involves a bit more complexity now.  A few years ago, I was looking for an inexpensive way to host a game server that would have a reasonably low and equivalent latency for both of us.  At the time, the virtual hosting services I looked at were running about $25/mo, which isn’t bad but seemed like overkill, given that we’d only be using the server once a week or so (late-night Friday sessions are the norm for us).

As luck would have it, about this time Amazon introduced their virtual hosting/cloud computing service called the Elastic Compute Cloud (EC2).  It allows users to create an image for a virtual server that can be activated and shut down easily, with service charges at $0.10/hour for a running instance plus a bit for data transmission.  When the instance is not running, the user is only charged for data storage of the image on Amazon’s Simple Storage Service (S3), at $0.15/GB per month (charges listed here may vary in the future or over different configurations).  So with several gigs of storage and running a few hours each week, this is a much better deal than paying for an always-running virtual server.

One annoying thing when EC2 first became available was that you couldn’t make changes to data stored with the instance.  Building and provisioning an instance would take a few hours.  After that, it could be started and stopped within minutes, but any changes would be lost between boots.  If you wanted to upload a new map for your game, you’d have to rebuild the instance.  Within the last year or so, Amazon introduced Elastic Block Storage (EBS).  This allows a user to create a volume within S3 that can be mounted by an instance at boot time.  Any changes on that volume are permanent.  Snapshots of the volume state can also be made, allowing for recovery if the volume data becomes corrupted or you need to return to a previous state of the volume.  Of course, you do have to pay for the data space used by these volumes and snapshots, but the pricing, as I indicated above, is pretty reasonable.  Even when Dan and I have done quite a few hours a month of gaming, I seldom go over $3/mo in total charges.

If you do the math, using EC2 for a game server that is up and running constantly is no bargain.  If this is your need, it’s definitely better to look at a virtual hosting service rather than EC2.  But, if you only need the game server running a few times a month, EC2 is pretty hard to beat.

Half-Life 2 Deathmatch (HL2DM) is the game of choice for me and my friend right now.  It’s been ideal under EC2, since the standalone Steam server runs under Linux and is easily configured and controlled using the command line and scripts.  At some point, I’d like to post more details on my installation.  I have some cool features going—including using a Linux service that communicates the dynamic IP of the EC2 instance to DynDNS.org and associates it with a hostname so that when we fire up Half-Life 2, we don’t have to point the game to a new IP each time and instead just reference a static hostname.

Here are a couple handy URL’s if you’re interested in giving EC2 and a Half-Life 2 game server a try:

Amazon Web Services (AWS) Management Console

http://aws.amazon.com/console/

Source Dedicated Server (srcds)

http://www.srcds.com/

Thinkpad T61p Battery Failure and Replacement

Saturday, December 12th, 2009

My main computer system right now is a Lenovo Thinkpad T61p—type and model 6459-CTO.  I have the Advanced Mini-Dock with dual monitors, external 5.1 USB sound, parallel port printer, etc.  So when I dock, I don’t really yearn for a more powerful desktop system.  I’ve had this set-up for about a year and a half.  I also purchased the extended warranty, making for a full three years of generally well-regarded hardware protection.

A few weeks ago, I sit down to work at my docked laptop and notice a flashing orange battery light.  I’d never seen this before.  A quick check of the power manager shows an error message—also sent to my Lenovo message center.  It reads “Battery error is detected:  A battery error has occurred.  The battery cannot be charged.  Replace the battery”.  This doesn’t give me a warm, fuzzy feeling.  The battery charge level icon is showing 100% and the battery isn’t all that old and has been holding a charge just fine.  It sounds like something beyond normal battery wear and tear.  So, I decide to pop the thing out of the dock and see what happens—after all, I have 100% charge, right?  Well, I should have hibernated.  As soon as I undock, it immediately shuts down, acting like there is no battery present.  I get the idea now that the 100% indicator means my laptop isn’t talking to the battery and doesn’t know how much charge is left.  You’d think it would show 0%, instead.  Go figure.

Some quick web searches show that others have experienced the same problem.  Actually, Lenovo has acknowledged the problem for a few battery models and done a recall.  But, upon running their recall check tool, I find that mine isn’t one of the batteries that it is part of the recall.  From the Lenovo parts inventory of my original purchase—found at the Lenovo warranty site—the part number is 92P1132 and the FRU number is 42T4619.  The description is a “SANYO 9 CELL BATTERY FRU”.  FRU is short for Field-Replaceable Unit, I believe.  Not only that, but the extended warranty doesn’t cover the battery—it’s only warranted for one year.  Lovely.

I thought about calling Lenovo tech support and trying to get a replacement, regardless, but decided after reading other comments on-line that it probably wouldn’t have do any good, since others hadn’t succeeded in prying a new battery out of Lenovo who were in the same situation.  Instead, I bit the bullet and bought a new Lenovo battery at a decent price off of eBay.  There are cheaper no-name clones, but I don’t like to risk clones with such large-capacity batteries as are in laptops.  They cost a lot and I don’t want to have a fire—that may be just paranoid, but there it is.

I did a parts search through the Lenovo store and found that the current recommended battery for my laptop is model number 40Y6797.  There are several on-line vendors that offer the original Lenovo battery for much less than it costs when ordered directly from Lenovo.  But the price I found on eBay was better still, and the seller had received much positive feedback on this specific item.  It arrived promptly and is working great.  The diagnostic information shown by the battery status program I use says it was made by Panasonic.  This is good to know, since I read some buzz saying that the Panasonic batteries are better than the Sanyo ones—though I’d say take this with a grain of salt.  But considering my old one was made by Sanyo, I’m happier this way.  Also, the name of the battery shows as 42T4620, which looks like a FRU number and is a one-notch increment from the FRU of my old battery.  Some web searching indicates that the Lenovo part number for this battery is 92P1134.  So there you have all the numbers for both the old and new batteries.  This should be useful if you run into similar issues with your Thinkpad.

Translating Character Codes from iTunes Playlist Exports for Android

Friday, December 11th, 2009

I have a Perl script I use to take an iTunes playlist export text file and turn it into a DOS batch script for copying music to my Android phone’s microSDHC card, as well as creating an M3U playlist.  This may sound like a strange way to do things, but I have a VMware Ubuntu instance installed under Windows Vista and run my Perl scripts from there.  But, it’s easier to copy my music files from Vista when my Android phone is mounted, which makes the auto-generated DOS script a simple way to do things.

In order to make sure that files with greater than 7-bit character codes in their names get copied and played correctly, I had to do some interesting things.  There may be easier or smarter ways to do this, but at least this seems to work according to the 80/20 rule of time spent investigating versus results. =)

It looks like the iTunes playlist export files use the UCS-2 character set.  The upside of this is that each character has a two-byte representation that shows up as an extra 0x00 byte for each character.  I strip the nulls and end up with characters in ASCII representation.  For the M3U playlist, I convert the characters with more than seven bits to their corresponding UTF-8 two-byte representation.  For example, a lower-case “e” with an acute over it is 0xE9 coming from the iTunes file, after having its null stripped.  The UTF-8 representation is 0xC3A9.  After this conversion, programs under Android that read the file names in the M3U file and compare them to file names in the file system work just fine.

Now, to copy the files from my hard drive to the microSDHC card via a DOS batch script, I had to convert the ASCII character codes to what I have found is the CP437 character set—also known as Extended ASCII.  That’s because the DOS shell uses it for the file names.  So, in order to get comparisons and file moves to work via the batch script, the 8-bit character codes in file names had to be converted to it.  In the case of our lower-case “e” with an acute, 0xE9 becomes 0x82.  The file names for the files as they were copied to the microSDHC card were left in this format.  The files then are seen just fine by the Android OS and programs running under it.

I’m writing an Android program that uses these M3U playlist files to access music files I’ve transferred as described above.  As I investigated the character sets and representations, I found that the Android SDK’s Java presents file names as UTF-8 strings.  When my M3U playlist contained ASCII 8-bit characters, my file names would not match the file names as retrieved by Java.  Using the Eclipse debugger, 8-bit characters from the M3U file were shown as a small rectangle, meaning Java didn’t recognize them.  Using the getBytes() String method to dump a string to a byte array showed the character represented as 0xEF 0xBF 0xBD, which I’ve found is the UTF-8 representation of “I have no idea what this character is.” =)  Using the debugger in this way also led me to learn that Java doesn’t store the character bytes as unsigned short ints like C, which is what I’m most familiar with.  Java doesn’t have the concept of an unsigned int at all.  Thus, 0xEF 0xBF 0xBD showed up as three consecutive bytes with decimal displays of -17 -65 -67.  The bytes are in 2’s-complement, so subtracting their absolute values from 256 results in decimal 239 191 189, which in hex are the codes described above.