Friday, July 21, 2006

Amazon S3 Part 1

Two days ago I began looking into Amazon's S3 web service. For those of you who don't know, S3 is described as follows by Amazon:

"Amazon S3 is storage for the Internet. It is designed to make web-scale computing easier for developers."

Hmm...web-scale computing made easy...as a geek there's no way I'm not checking this out, so I went ahead and signed up for an account. The signup process was really easy, I just had to break out my Discover card and they promised to bill me monthly, excellent deal. Once I was signed in I had access to all of the documentation and example code. The cost by the way are as follows:

Pricing
* Pay only for what you use. There is no minimum fee, and no start-up cost.
* $0.15 per GB-Month of storage used.
* $0.20 per GB of data transferred.

I figure I'll owe them a few pennies each month, no big deal. I really just want to play around and figure out what kind of cool stuff I could build if I had the time.

I downloaded the .NET C# SOAP example. Installed it, put in my super secret key, recompiled and kaboom, I was up and running. The example showed me how to program the core concepts with S3 via a command prompt. Here are the technical concepts a developer would need to understand:

1. Buckets

A bucket is simply a container for objects. Each user can have up to 100 buckets. This may sound low, but in reality you only need 1 bucket.

2. Objects

Objects are like files, but they have meta-data around them. Meta-data is data about the objects, key/value pairs. You also have to setup ACL's (Access Control Lists) for each object. You can have an unlimited number of objects. At first glance you may be wondering how to organize all of the objects in a bucket. What is really cool is that you can can use any type of delimeter you want to group objects. UNIX people are use to the "/" seperator, Windows uses the "\" seperator, but you can use whatever fits your application.

3. Keys

Every object has a unique key.

4. Operations

Example operations:

a. Create a bucket
b. Write an object
c. Read an object
d. Delete an object
e. List Keys

That's it. Pretty easy concepts to understand, but it's pretty powerful. So the example project showed me the basic concepts but I wanted to build something useful. So I decided to improve "My Internet Based File System" by creating a program that will allow me to

1. Upload a folder to S3
2. View a list of objects in my S3 account.
3. Download the object to my local hard disk.
4. Delete objects from S3.

After about an hour I had a working version. The hardest part was fixing their example code to handle binary files as well as text files. Once I got that it was just a matter of hammering out the code.

Here is a screenshot of the working version (and yes I do design work on the side):


The main problem with this code is that it reads the entire file into memory before sending the object to S3. Not a problem with small files, but if you ever wanted to upload a big mp3 or something it wouldn't work. In order to get this to work, you really need to "stream" the object to S3. But, doing this via SOAP is rather hard. The basic problem is that SOAP is primarily XML going back and forth. You would need to either dig deep and format the objects yourself (not recommended) or use a concept called "DIME Attachments". Good luck finding example code. And a bigger problem for me was that Microsoft switch their "Web Services Enhancements (WSE)" to use MTOM instead of DIME between versions 2.0 and 3.0. I don't really have the time to try to get this mess working. But I have some other ideas I'm going to play with first to see if I can get this working in a simpler manner, stay tuned.

If you are wondering how S3 works on the backend, the API docs give some clues, here is one:

"If the object already exists in the bucket, the new object overwrites the existing object. S3 orders all of the requests that it receives. It is possible that if you send two requests nearly simultaneously, we will receive them in a different order than they were sent. The last request received is the one which is stored in S3. Note that this means if multiple parties are simultaneously writing to the same object, they may all get a successful response even though only one of them wins in the end. This is because S3 is a distributed system and it may take a few seconds for one part of the system to realize that another part has received an object update. In this release of Amazon S3, there is no ability to lock an object for writing -- such functionality, if required, should be provided at the application layer."

Thursday, July 20, 2006

Some helpful hints when using mysqldump

I always have to go to the mysql reference manual for this, so I'm going to blog about it so that I'm fewer clicks away and I don't have to re-read the mysql manual every 3 days.

First, mysqldump is useful for a variety of reasons, primarily backup purposes, but it can also be very useful for dumping a very small subset of data. We do this commonly to dump live data to test databases.

Here is an example:

Say you have a database called 'webmail' with a table called 'address' and you want to dump all of the address data for a particular user ('owner') from the live system to the test system to debug a problem. You would run mysqldump in the following manner:

mysqldump --skip-opt --quick --extended-insert --no-create-info --user=testing -p --where="owner = 'kevin@domain.com'" webmail address > tmp.txt

mysqldump by default uses the parameter "--opt" which means:
--add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset

Most likely you don't want most of those in this scenario, so that's what all of the options are about.

And to import the data run:

mysql --user=testuser -p webmail < tmp.txt

The most important tip is to make sure mysqldump doesn't add the "DROP TABLE" commands!

Perl

Sometimes perl is a little too forgiving, this little bug has existed for over two years in one of my programs and I just now spotted it...

if(length($hostname < 5)) {
#precaution
return 1;
}

Wednesday, July 19, 2006

You throw like a girl

Yesterday I tried to give Jil and Velvet some pointers on how to throw a softball. Both of them had issues turning their shoulders properly, which isn't a big deal if throwing small distances, but if you really want to throw like the boys you have to turn those shoulders. My other big tip is to get your elbow up. By the end of the practice they were both throwing much better.

I think girls can throw just as well as boys, but I think they don't get enough practice. You won't throw like a girl for very long if you keep practicing because it's just not going to go the distance you want nor have the accuracy you want until your mechanics are good. Eventually you body will train itself to put the arm, legs, and shoulders in the proper positions. So my biggest piece of advice is to keep practicing. Be sure to start slowly though, throwing a ball overhand is not a natural motion for the human arm. It is very easy to get a sore elbow or shoulder so be sure to stretch and warm up properly.

I'm looking forward to our softball season, but I hope it cools down soon, yesterday my Jeep told me the temperature was 105....

Photos From My Phone

It's been over a year since I cleaned up the photos on my phone, here are some good ones...





Tuesday, July 18, 2006

Colin Cowherd UVA Rant

If you haven't heard this clip and are a VT Hokie fan, check it out... UVA fans probably shouldn't listen.

Local News

Webmail.us announced today that we are now staffed in our customer care division 24 x 7 x 365. And yes, all of our customer care staff works from our Blacksburg, VA office. I'm very excited about this announcement because it is an important milestone for our company.

In somewhat related local news, it seems a lot of local communities are really pushing forward with providing wireless Internet access for all of their citizens. Check out this Roanoke Times article. I'm amazed that the smaller communities such as Bland, Hillsville, Radford, and Pulaski are actually leading the way in this area. At the same time I can't help but wonder how they plan on supporting their users.

I have a good friend who actually started a wireless ISP two years ago that primarily services the rural parts of Montgomery county plus some of Christiansburg. He's been very successful and I'm sure he's earned a lot of loyalty due to the excellent customer service he provides. I'm sure his business will continue to grow as long as he is able to continue providing great customer service.

Wednesday, July 05, 2006

More Debugging Tools

Here are a couple of cool debugging tools that will help you accomplish more in less time:

strace
------

strace allows you to attach to a process and watch every system call that the process executes. It is very helpful for tracking down exactly what a program is doing without having to use gdb. It is run like this (use the -f option to strace forks):

strace -tt -o log.txt -p

For an example run this:

strace -tt "uptime"

lsof
---
Another cool command is the "lsof" command. It will give you a list of open files (including sockets) for a process.

lsof -p 3387