Writing a reverse proxy/loadbalancer from the ground up in C, part 2: handling multiple connections with epoll

Posted on 7 September 2013 in Linux, Programming

This is the second step along my road to building a simple C-based reverse proxy/loadbalancer so that I can understand how nginx/OpenResty works -- more background here. Here's a link to the first part, where I showed the basic networking code required to write a proxy that could handle one incoming connection at a time and connect it with a single backend.

This (rather long) post describes a version that uses Linux's epoll API to handle multiple simultaneous connections -- but it still just sends all of them down to the same backend server. I've tested it using the Apache ab server benchmarking tool, and over a million requests, 100 running concurrently, it adds about 0.1ms to the average request time as compared to a direct connection to the web server, which is pretty good going at this early stage. It also doesn't appear to leak memory, which is doubly good going for someone who's not coded in C since the late 90s. I'm pretty sure it's not totally stupid code, though obviously comments and corrections would be much appreciated!

[UPDATE: there's definitely one bug in this version -- it doesn't gracefully handle cases when the we can't send data to the client as fast as we're receiving it from the backend. More info here.]

[ Read more ]

New gadget: Nokia N900

Posted on 23 December 2009 in Gadgets, Linux

I got an early Christmas present today! Robert was able to find a Nokia N900 at a very reasonable price, and Lola decided to get it for me as combined Christmas and birthday presents...

The is a fascinating device. Nokia bill it as a "mobile computer"; it has about the CPU power of a 10-15-year-old PC (say, a Pentium II), but also has a modern graphics processor, and it runs Maemo, Nokia's rebranded version of Debian Linux. Earlier this month, Robert showed me his one running his own port of Frotz, and demonstrated that it had a full version of Linux; I saw the video of it running WebGL later on the same evening, and fell in love :-)

One thing I've noticed, though, is that although you can get a full Debian install running, it takes a little work and there's no good step-by-step documentation. I'll post about that next.

Dear lazyweb: what is is about Linux and WPA?

Posted on 11 January 2008 in Eee, Gadgets, Linux, OLPC XO, Rants

I don't think I really have enough of a readership for this blog to get an answer to this, but... perhaps someone passing by will know. Why is WPA support invariably so bad in Linux-based OSes?

Three examples:

  1. Despite having been a Linux user since 1992, I held off on switching my primary laptop, an aging Fujitsu-Siemens machine, from Windows for many years because no distribution I could find supported WPA out of the box with any kind of user interface I was willing to spend the time learning. This is not because I'm lazy -- I'm willing to put in weeks to learn web server configuration details, and years to learn programming languages. These things are inherently difficult and cannot be reasonably simplified. But connecting to an encrypted wireless network? Sure, the underlying tech is as complex as it gets, but if Microsoft can make it easy to use then why did it take so long for anything usable to get into any Linux distro? Sigh. Well, anyway, I eventually tried out Ubuntu 7.10, Gutsy Gibbon, and was delighted to discover that its support was OK. Not as good as Windows XP's, but good enough for me to switch the old lappy over, which I did sometime last autumn, and have never regretted. So, standard defined in 2004 or so, decent support in mid-2007. Hmm.

  2. So along came my new Eee, just before Christmas, and for some reason I have difficulties connecting to my work or home networks. Why? Well, I banged my head against it for a while, and eventually discovered that there was a bug in the scripts used for WPA connections that meant it could not connect if you had a key with a space in it. A bit of digging around on the Eee Wiki helped me sort that one out, but seriously...

  3. Anyhow, I posted earlier on today that I'd not been able to connect my OLPC XO to my work or home networks. No prizes for guessing what the problem was... from the Laptop.org wiki (found via):

    WPA is not working from the User Interface in Build 650! Some OLPCs (including in the G1G1 program) cannot connect to wireless routers protected with the WPA protocol. Although the networks are visible from the OLPC, the stall when user enters a password.

    The first solution they suggest is to switch off WPA. Right. Sorry, but I'm not Bruce Schneier, and there's no way I'm switching to WEP. It's almost enough to send me into some kind of Fake Steve Jobsesque rant.

    Luckily, some kind soul has worked out a hack to work around the problem, so I'll try that. [UPDATE, posted from XO: it works!]

But seriously -- what is the problem? Linux is a great OS, but WPA support seems to be seriously messed up. It can't just be a driver problem, because both the XO and the Eee have OSes built for them by the hardware manufacturers. Does anyone out there know?