Thursday Jul 17, 2008

BitTorrent on Solaris (Nevada, Solaris 10 Update 5)

After years of trying to squirrel away a few minutes to install my only BitTorrent swarm in our lab, I've finally done it! I thought I'd put the instructions out here on the web since it seems that explicit Solaris-based instructions are relatively sparse (they are sparse because the version I'm using is relatively easy to use and not relegated to a single platform...thus the lack of Solaris-specifics).

I started with a clean build of Solaris 10 Update 5 on one machine, and Build 94 of Nevada on another set of 4 machines. These are the Sun Fire x4150s I've discussed in other posts.

Retrieving all of the packages I needed was straightforward with (an open source software repository for Solaris). In fact, with just a few commands I had a complete BitTorrent stack installed that runs with Python (don't have Python on the system...Blastwave takes care of that too).

Install BitTorrent
First, read the HOWTO on using Blastwave. I only made it through a few steps of the HOWTO before I was up and running, so don't sweat it if it seems long and you are attention-challenged (like me without a special Nespresso Level 8 or above espresso). Of course, I'm fumbling around more than I should so be sure to read the whole thing when you do have time, it contains information on directories and where stuff gets put (at least I think it does...). Installing what you need to use Blastwave takes only a few minutes. Once you have Blastwave ready and running, retrieve BitTorrent and all its dependencies (primarily Python):

/opt/csw/bin/pkg-get -i bittorrent

That's it, BitTorrent is now installed in /opt/csw/share/BitTorrent

Remember the BitTorrent Components
Here is the 2 minute review of important BitTorrent Network Components and terminology that follows the general deployment diagram here (this is the swarm I've installed in my lab so I'll refer to it throughout):

  • Torrent - A "file" that is prepared to be distributed by BitTorrent, torrent may also refer to the metadata file prepared from the contents of the file you will be distributing
  • Tracker - A "tracker" helps refer downloaders (peers) to each other, sort of an organizer of nodes
  • Swarm - A group of peers that are delivering content to a requester (the downloader itself often becomes a part of the swarm for another requester very early in the download process)
  • Seed - A full copy of a file that clients can obtain. This seems like a heavy load on a single server, but very early on clients will lessen their load on the Seed systems and depend on other peer clients for chunks of the torrent.

In the scenario below, the Tracker and the Seed for my torrent (OpenSolaris 08.05 ISO) are one and the same. The Seed should typically be split from the Tracker though...the Tracker is a bottleneck and you don't want it to be pounded on by Peers.

Start a Tracker
We will start the tracker first. A tracker can be started as a background task. It will sit on a port and listen for requests and write output to a file.

./ --port 6969 --dfile dstate --logfile tracker.out

Your tracker is now up and running and ready to organize clients.

Create a Torrent
A "torrent" metadata file contains all of the information about a particular file that can be retrieved through BitTorrent. The torrent is associated with a tracker and when complete will contain a variety of information to ensure the integrity of the final torrent when a client receives it.

The README.txt with the BitTorrent download didn't have proper instructions for building a torrent (seemed a little out of date), so be careful and don't get frustrated. Use the command to build the torrent file. I've chosen to create a torrent from the OpenSolaris 08.05 distribution (my favorite distribution of all, of course...):

./ --comment "OpenSolaris 08.05 from Pauls Swarm" os200805.iso

Notice the use of the tracker that I set up. You can show the meta information that was generated by using the command:

# ./ os200805.iso.torrent
btshowmetainfo 4.0.4 - decode BitTorrent metainfo files

metainfo file.: os200805.iso.torrent
info hash.....: fdf239d2524e44432892d01ab354e20a8b77b7e6
file name.....: os200805.iso
file size.....: 719087616 (2743 \* 262144 + 26624)
announce url..:

Setting up a Seed
You need a web server available from the system that is going to be a "Seed". Nevada has Apache 2.2 (at least in my build) installed by default, you simply have to turn it on (mileage may vary). You can do this by typing:

# svcadm enable apache22
# svcs | grep -i apache2
online 20:41:36 svc:/network/http:apache22

A better instruction set can be found on BigAdmin.

With a little nosing around the system, I found my httpd.conf file at /etc/apache2/2.2. Look in the file for the DocumentRoot, something like this works:

# cat httpd.conf | grep DocumentRoot
# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/var/apache2/2.2/htdocs"

We will place our .torrent file (created earlier) in the DocumentRoot.

Most web servers you also have to associate the mime type "application/x-bittorrent" with the file extension "torrent", this was already done for the pre-installed Apache 2.2 on Nevada.

Finally, put the complete file on a server (the same one would work like I am doing, but a separate server is recommended). Run the BitTorrent download, saving the file into the location that the file already exists. BitTorrent is smart enough to see all of the chunks are there, but it spends time verifying the are correct. When complete, the computer you run the download is a Seed. This command works for the OpenSolaris 08.05 torrent I created earlier:

# ./ --url --save_as os200805.iso

This takes a while as it runs through hash checks on the existing file.

The torrent is now ready as a Seed for peer to peer access. You can add as many Seeds as you want depending on how popular you think your file is going to be.

Use another Client to Download a File
I can now go to x4xx-02 and start the headless download, just as the previous one ran.

# ./ --url --save_as os200805.iso

Remember the torrent itself points back to the tracker. There should be some brief activity by the tracker during the download to see if other peers in the swarm can help.

During the download, you will become a part of the swarm from which other clients can download chunks of OpenSolaris (you have to give it, if you want to get it - The Suburbs).

As the file starts to download, you will see the transfer rate start to go up. With a single Seed, I started slowly ramping up. BitTorrent is careful to balance requests. Remember, I now have a Seed and a Peer with chunks of the file. With a single download in progress, I reached about 20 KB/sec (the upload from the Seed and the download from the client)...there is some obvious throttling going on somewhere.

What if I start a download of the torrent on x4xxx-03? The Seed remained uploading around 20 KB/sec. After an initial hit on x4xxx-02 down to about 14 KB/sec, I quickly moved back to over 20 KB/sec, while x4xxx-03 was peaking near 30 KB/sec. As more chunks moved onto x4xxx-03, x4xxx-02 also sped up, since it could grab chunks from two peers. The Seed remained constant at a 20 KB/sec upload, but x4xx-02 was now also uploading at 20 KB/sec and x4xxx-03 was able to have the aggregate bandwidth.

But wait, I have two more clients sitting idle, I started up x4xxx-04 and x4xxx-05 with the download. Again, an initial hit from x4xxx-02 occurred, as it was heavily relying on the original Seed and clients were also relying on it. Within about a minute, the original Seed was still uploading at 20 KB/sec, but -02, -03 and -04 were also uploading at 20 KB/sec. All clients were now downloading at 20 KB/sec with the original seed still uploading at a constant 20 KB/sec...peer to peer amortization of upload bandwidth at its finest.

As the download moved along, more chunks flooded onto the remaining peers and the sharing became much more efficient. Each of the clients regularly found their way over 25 KB/sec and often into the 30 KB/sec range.

I decided that the graphical output wasn't very fun, so I added my home system that I VPN with into the party using Azureus. With Azureus, I'm able to get graphical displays of what's going on. Here is a picture of my swarm:

Note that the center circle is my client, the fully blue circle is the seed, and you can see the other peers don't yet have a lot of chunks of the file.

Here is another interesting view from Azureus:

Of particular note is the Swarm Speed, we have hit about 100 KB/sec with our 5 peers and an obvious upload throttling on each client at around 20 KB/sec. Well, I'll obviously be looking into that...but I think I've run out of words for the evening and I've more than achieved my purpose tonight. Enjoy BitTorrent on Solaris!

Now, I just have to figure out what other kinds of fun I can have with my swarm :-)




« July 2016