Ocelot: The story of a torrent tracker

119 points by Goonbaggins ↗ HN
I took this directly from a newspost on what.cd, and I have no association with anything written here. Just thought HN would find it interesting.

What.CD is a private tracker. Thus, the entire site, staff, and community all revolve around a common piece of software - the tracker backend. Complementing the site frontend, which you're looking at now, the tracker itself handles connections between peers.

With over five million peers, our tracker receives an average of 3,500 hits per second, although after a period of tracker downtime, load can spike up to past 12,000 hits per second. This means that, when your client announces, the tracker has 80 microseconds to search through its database of over 900,000 torrents and 5,000,000 peers, compute a response, and send it back to you. That's a lot of stress on a piece of software!

We anticipated this problem, of course, back before the site even started. That's why we elected to use what was then the fastest private tracker backend in the world - XBTT.

Lauded for its speed, XBTT handled the peers very well for the first few months of the site's existence. We brought on a developer - asm - whose job was to tune it and modify it as needed, and he was able to do that just fine - for a few months. However, asm was reluctant to make any major changes. When we asked why, his response was that XBTT's code was too weird, and that he was afraid he'd break something.

A bit surprised, we lead site developers peered into the bowels of XBTT for the first time, and we found that he was correct. XBTT's internal code worked fine in practice, but strange/outdated design decisions and the inclusion of thousands of lines of unnecessary code gave us worries about how well it would scale to a swarm of the size we had planned, as well as whether we'd be able to continue modifying it to our needs.

So a plan was formed. We would create a tracker of our own.

Late winter 2007

It made perfect sense. We were already replacing the outdated TBDev source with our own new Gazelle source, so why not replace XBTT with another piece of software as well? Make it fast, make the code pretty, give it a cool-sounding exotic animal name, and we'd be set. It couldn't possibly take very long - trackers are very simple pieces of software, after all. The only problem was that XBTT had scared asm into hiding, the other developers were all php developers (php is a language that is fast to write and slow to run) and we wanted the tracker coded in C++ (slow to write, fast to run). The solution was thus to outsource.

January 2008

Our first developer choice was a young developer called rootkit. Immensely intelligent, but perhaps not the greatest people person in the world, rootkit decided that he wanted to write the tracker in haskell instead. We weren't too excited to have the tracker written in a weird language that no one understood, but he promised that it'd be fast so we let him go at it. We don't think he ever wrote more than a hundred lines of it before he gave up and stepped down.

While we searched for a new developer, WhatMan decided to try an experiment - to see if a php tracker could outperform XBTT. He hacked away for a weekend and created Lioness - a beautiful little tracker, no doubt one of the fastest php trackers ever made. Unfortunately, it wasn't quite fast enough for our needs - upon testing, the swarm crushed our poor webserver, and we were forced to go back to XBTT.

By this time, XBTT was barely able to keep up with the load. The timeouts had already started, and we did whatever we could, but in the end, the only thing that really helped was when we moved to our new (then) ridiculously oversized server in Canada.

March - May 2008

Another developer had been found! The guy was smart, mature, well educated, fluent in C++, and seemingly very able. We told him what we needed, and he started coding. A month later, the new dev - lenrek - had created the first tracker to call itself Ocelot.

lenrek's ocelot looked promising. It was new, shiny, and multithre...

8 comments

[ 3.7 ms ] story [ 31.6 ms ] thread
Interesting story. Especially how often they tried to develop a new tracker. Any more insights why they failed so often?

Another already opensourced torrent tracker is opentracker http://erdgeist.org/arts/software/opentracker/. Its written in c and was developed because other trackers were slow or needed much resources. After some time piratebay started to use opentracker because it was much faster then the other trackers.

There was also a great talk[1] (German) at the 24C3 about the development of opentracker and some nice insider stories about running a big torrent tacker like getting a call from the provider "you are under a ddos attack.." "aeh no, thats normal and the load on the server is really low" (they had to change the hosting company ;0)

[1] http://dewy.fem.tu-ilmenau.de/CCC/24C3/mp4/24c3-2355-de-trac...

I have a little experience in designing software for HPC that, for the most part, is quite a bit more complicated than a BT tracker. Here's something I found on the opentracker website:

All technologies to implement this are around for more than twenty years. Still most implementations suck performancewise.

I have a feeling that mediocre programmers (or programmers who really don't know as much about systems as they think they do) are to blame here :(.

Edit: A little more detail.

Opentracker is built by a C programmer who knows his stuff. He knows that disk access in a app like this would be suicide and designed around that. Advantage #1.

Opentracker uses libowfat which looks to be written by another good systems programmer with an eye for clean design. He has also had a quite a bit of time to perfect his implementation. Advantage #2

Libowfat is inspired and partially architected using libdjb written by Dan Bernstein (a phenomenal old school systems developer with a long track record). His design models have been at work for years and years. Bernstein is truly a 'legend.' Advantage #3

Short answer: same as always; smart people doing smart things :).

(comment deleted)
Thanks for the pointer to libowfat, looks quite interesting!
I just skimmed opentracker's sources (they're surprisingly small, < 5K LOC of clean C). Not sure why ocelot wasn't based off of opentracker.

One possibility is that (as I understand it,) What.cd is a "private" torrent tracker -- meaning they have a ratio for each user that they need to keep track of. Opentracker doesn't seem have anything to support this and up until the very end, no one at What.cd seemed to be comfortable writing C, let alone C++ for ocelot.

> It was new, shiny, and multithreaded

sigh, when will people learn about asynchronous I/O.

It would be interesting to see if something like this could be implemented in a programming language that has relatively "slow" virtual machines (e.g. Ruby) but base it on a fast event-processing library (e.g. Eventmachine). The tracker doesn't do a lot computation. It's mostly I/O, isn't it?

Another interesting choice would be node.js. A framework that seems to be optimized for that kind of architecture. A bit of caching and a scalable backend (e.g. Riak) would be a nice combination...

I dare you... :)
"A9 had the brilliant idea of daring oorza to write a high performance tracker in java..."

This can, in fact, be done. Pando's [X] managed, torrent-like p2p platform has a solid, fast, Java-based tracker component.

X http://www.pandonetworks.com