Wednesday, May 31, 2006

Hurrah!

For the last few days I've been trying to get Boost.Python examples to compile with no success whatsoever. After over an hour of messing about with Jamfiles, bjam and Jamrules (and all the other things that Boost decided they would require to compile a 12-line program) this morning, I chanced upon a page that gave the g++ commands needed, bypassing the ridiculously troublesome boost-build procedure.

Monday, May 29, 2006

Axon in C++

Axon is the core of Kamaelia - the stuff that co-ordinates everything else, ensuring messages go from outboxes to their recipients' inboxes and running the components in turn. Kamaelia is primarily written in Python but there is proof-of-concept code for C++ in the CVS.
I've been creating my own (not-so-)MiniAxon in C++, focusing on efficiency unless it would overcomplicate the API. A Kamaelia implementation in C++ must provide much that the Python developer takes for granted. For example, Duff's device serves as a potent and yet intrinsically sinful implementation of generators:
#include <iostream>

static int generatorstate = 0, x = 1;
int generator()
{
switch (generatorstate)
{
case 0:
std::cout << "Hello World\n";
generatorstate = 1; return 1;
case 1:
for (;;)
{
std::cout << x << "\n";
x = x + 1;
generatorstate = 2; return 1;
case 2:
std::cout << x << "\n";
x = x * x;
generatorstate = 3; return 1;
case 3:
;
}
}
}

int main()
{
generator();
std::cout << "Run 1 time\n";
generator();
std::cout << "Run 2 times\n";
generator();
generator();
generator();
std::cout << "Run 5 times\n";
generator();
generator();
generator();
generator();
generator();
std::cout << "Run 10 times\n";
}

Labels: ,

Sunday, May 28, 2006

Character set woes

I've found another bug in my HTTPServer - Python's character set support is horrid. Unfortunately, Python assumes that everything is ASCII by default, rather than a more sensible choice like UTF-8, and I've yet to get it to play nicely with Unicode. What's worse is that this bug only occurs when the IRC logs contain special characters:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 19621: ordinal not in range(128)
What a nasty complication to an otherwise simple language!

I've made something nice to use for my streaming testing - a video of the swans at the local lake.



I'm playing around with Boost.Python, with an aim to wrapping libtorrent although I've yet to get the examples to compile!

Saturday, May 27, 2006

Apt-proxy

I discovered apt-proxy today. Like a standard HTTP proxy, it caches files (packages) requested, but as it understands that what it's downloading is for apt, it can intelligently delete out of date packages. Since I've got Dapper installed on 3 PCs now, this should save me a fair bit of time and bandwidth. Apt-proxy is running well on my old 500 MHz server (which has Ubuntu Breezy on it).

Labels:

Friday, May 26, 2006

Metalink

I found (or more accurately was pointed to) another cool possible basis for Kamaelia component - metalink. It's a download metadata format/system for grabbing parts of a download from multiple sources. For example, if your BitTorrent download is stuck at 99.2% then there's FTP mirrors you could try, or if the primary HTTP server for a file is slow you could grab bits from several mirrors. It's a good idea but I had some reservations - namely that you really should store hashes for parts of the file as well as the whole so that the correctness of each section can be confirmed, rather than having to start again if one byte was wrong. This is how BitTorrent checks the integrity of files. The author kindly sent me the Metalink 3.0 Draft Specification which I'm perusing right now. It's XML based and so easily extensible which is nice.

In other news, I've added a non-witty mode to Kambot (say "stfu kambot" to toggle it) to stop it from saying stuff during meetings etc. on #kamaelia.

Thursday, May 25, 2006

And so it begins...

This is to be my progress log for my work on Kamaelia for Google Summer of Code 2006. I'll be making a set of BitTorrent components for downloading and uploading files through BitTorrent, for making .torrent files and for moving .torrent files from A to B. The scope of my work is somewhat wider than just BitTorrent however. I've made a basic but effective HTTP server and an IRC logger bot for Kamaelia so far.
I'm currently experimenting with using SWIG to wrap C++ modules for Python.

Monday, May 22, 2006

HTTP Benchmarking

Benchmarking my HTTP server revealed some issues - I was not closing components after their TCP connection closed. Initially I was getting throughput of about 5 hits/sec. After some tweaks, such as only yielding when left with nothing to do, I managed to get 100 hits/sec for highly dynamic pages or 800 hits/sec for small static pages when using persistent connections. This is fairly good, although an simple, efficient webserver written in C could probably handle several thousand hits/sec. I've been using siege to do the load testing/benchmarking.

I found a bug in the Kamaelia TCP components - they raised an exception when the remote host disconnected unexpectedly, taking down the entire HTTP server in the process. :D

I've made a handy little Python script to convert tabbed code to spaced code.

#!/usr/bin/env python
import sys, string

def tabsToSpaces(path):
myfile = open(path, "rb")
contents = myfile.read()
myfile.close()
lines = string.split(contents, "\n")
contents = []
for line in lines:
tabs = 0
replacement = ""
while line[tabs:tabs+1] == "\t":
tabs += 1
replacement += " "
contents.append(replacement + line[tabs:])

contents = string.join(contents, "\n")
myfile = open(path, "wb")
myfile.write(contents)
myfile.close()

if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: tabsToSpaces.py "
else:
tabsToSpaces(sys.argv[1])

Saturday, May 20, 2006

Dapper Drake - First Impressions

UbuntuI've upgraded to Ubuntu 6.06 (Dapper Drake) beta and I have to say I'm fairly impressed on the whole. The upgrade procedure from 5.10 was very simple - modify your apt sources.list to say 'dapper' where it previously said 'breezy', then run apt-get update and apt-get dist-upgrade. It's a lot less troublesome to get setup than Fedora Core 5 was, although I'm only using the x86 version of Ubuntu rather than AMD64 as I did with Fedora.

I was having a minor problem with colour (#fcfcfc would appear considerably darker than #f0f0f0) but the new nVidia drivers (available through apt in Dapper) fixed it. I also had problems on an older Pentium II machine - everything after grub and before the login screen is garbled most likely due to buggy ATi drivers (it's a All-in-Wonder based on the Radeon 7200). I'm considering going back to Breezy on that PC.

sudo dpkg-reconfigure gnome-applets fixed the CPU applet (after the upgrade it was no longer SUID so you couldn't pick a frequency. The gnome-art package is great for customising the appearance of Gnome.

It also has Firefox 1.5, gstreamer-0.10 and a working mplayer package and Eclipse C++ support which were some of the main things I wanted, seeing as I had them on Fedora Core 5 before.

In summary, Dapper is better than any Linux distro I've seen before, but only by a little. Its default colour scheme (brown and orange) is hideous but the other colour schemes don't look as modern. Legacy ATi support needs work - I've seen similar problems reported on the Ubuntu bug tracker. The games, as with most Linuxes, are pathetic. They are of no comparison to the majority of commercial games. That said, if I wanted my PC primarily for gaming, I'd be using Windows XP Home Edition...

Friday, May 19, 2006

All up and working again


My new graphics card (an Asus nVidia 6200 AGP) arrived and my computer is working fine again thanks to it. It's also passively cooled - there has been a noticeable drop in the PC's noise level. Though it's not as powerful as my broken 6600GT was, it was a good buy at £35.
For your information, the faulty component was an XFX product - I will be avoiding them at all costs in the future.
HTTPServer is coming along. I've added better support for complex URLs.
I've also tied it to the IRC logger successfully.