Demonstrates the power of underlying technology X - first project
with technology X

Industry standard - obsolete. There are likely better solutions.

Obviously this is somewhat tongue-in-cheek. There is a lot of great
software out there and not all of it fits these stereotypes. However,
next time you are about to describe a library as "a smart, fast scalable
X for Y" do the translation in your head first and have a self-aware
chuckle first.

The Internet is dead! Long live the Internet (v6)! You need IPv6. I need
you to have IPv6 so you can view this website over the next generation
Internet Protocol. If you and I both had IPv6, we would be able to
forget about such inconveniences as NAT. We could video chat without
having to have a separate server. We could share files directly. We
could do a whole lot of really cool stuff.

Now, the question is: how do you get IPv6? Here is one way using
SixXS and a Raspberry Pi.

This is my current method, since it is low cost and requires no special
router setup. Basically, IPv6 packets are encapsulated into IPv4+UDP via
the Anything-in-Anything protocol. UDP traverses NAT boundaries
fairly easily and SixXS provides a very nice service so that you don't
have to manually tell them that your public IP has changed. Using this
setup, I've basically created a generic IPv6 tunnel endpoint and router
that I can connect to almost any LAN and it would automagically enable
IPv6 on that network. Let me show you how:

Step 1. Obtain a Raspberry Pi and install Linux on it. This is beyond the
scope of this post, and documented well elsewhere. You can also use
any other always-on device on your network, but I will assume you will
get a Raspberry Pi for the purpose here.

Step 2. Get an account with SixXS. This is a multi-step process
where some steps require manual approval, but it goes pretty quickly.
Once you have your account, request a tunnel and a subnet. For the
reason, state something like "I want to get my local network IPv6
enabled", but with more detail. Make sure to select the AYIYA type of
tunnel.

Note that we are letting two IPv6 subnets through:
2001:4830:xxxx:xxx::/64 and 2001:4830:xxxx:Yxxx::/64. The one with the
Yxxx is going to be the routed subnet. That's the one that the rest of
the devices on your network will use. The one with just the xxx will
only have two addresses on it: ::1 (the remote end of your tunnel) and
::2 (your Raspberry Pi).

Step 5. Make sure your firewall is enabled at boot time. This is easy:

Put the following into /etc/network/if-pre-up.d/ip6tables-load, and make
it executable
($ sudo chmod 755 /etc/network/if-pre-up.d/ip6tables-load)

#!/bin/sh
ip6tables-restore < /etc/ip6tables.rules
exit 0

Now, put the following into /etc/network/if-post-down.d/ip6tables-save
and make it executable
($ sudo chmod 755 /etc/network/if-post-down.d/ip6tables-save)

Now, create an executable script at /usr/local/etc/aiccu-subnets.sh with
the following content:

#!/bin/sh
ip addr add 2001:4830:xxxx:Yxxx::1/64 dev eth0

Then restart aiccu: $ sudo /etc/init.d/aiccu restart. Now, your eth0
will have its own IPv6 address in the routed (Yxxx) subnet.

Step 8. Enable IPv6 for the rest of your LAN. This step is also very easy.
We will install radvd ($ sudo apt-get install radvd) and configure it
to advertise your routed network prefix. Create a file at
/etc/radvd.conf with the following content:

The problem

Always on a quest to make the Web faster (see Ping Brigade), I've
been thinking about
ways to speed up fetching web pages. My investigation started with the
fact that many popular web servers are backed by multiple
IP addresses. For example:

That's 6 IPv4 and one IPv6 address. Looking at this list, I don't know
which one is closer/faster/less loaded. How does, say,
a browser pick one of these? Well, typically one of these will be
picked at random and a connection will be attempted. The browsers
are smart enough to know whether the given machine has access to IPv6,
IPv4, or both and usually will prefer IPv6 if it is available.

After one address is picked, it is cached by the browser as the address
for the given hostname. The connection is attempted with a
fairly large timeout (30-45 seconds). If the connection succeed, the
browser proceeds as usual to fetch the web page over HTTP. If it fails,
the browser uses the next address in the list, making another attempt.

Notice how terrible this is for the user experience. If one of the 7 of
Google's servers is having an issue, then the user has to wait for
30-45 seconds before the next attempt is made. This is bizzarre,
especially since Google has no way to control the timeout of the
browser
(well, maybe Google does since they ship Chrome, but any other server
operator does not). This is definitely a setting you would want to
control:
saying that your web servers are expected to respond within, say 5
seconds, would give you control over the browser behavior. We do, in
fact have
something similar server-side, when we set up reverse proxies: you can
define how long to wait for a response from each upstream server before
moving onto the next one and marking the timed-out one as failed.
However, we have no such system to control browser behavior. I imagine
if we
were to add it, we could leverage DNS to supply such information.

I digress. The good news is that browser vendors can fix this with no
need for new infrastructure! All they'd have to do is change the
algorithm
they use to select the server they connect to. After playing around
with different ways of initiating TCP connections, I created a prototype
of
a Python framework for that attempts to make multiple connections and
selects the first one that succeeds. Some details:

The Hypothesis

Let's start with the idea that there are multiple A/AAAA records for the
hostname we are trying to connect to. This is certainly
the case with some very popular websites (Google, Facebook, etc.) My
hypothesis is that if we make multiple simultaneous connection requests
to each IP address, the first server to successfully complete the
three-way TCP handshake will fit one or more of the following criteria:

The server is physically closer to the client than others.

The server is closer to the client than others in terms of network
locality (e.g.: if you are in San Francisco and the server is in LA,
but your packets are routed through NYC, you are going to have a bad
time.)

The server has a faster, lower-latency internet connection than
others.

The server is less loaded.

The server is up, while others are down.

The last condition is especially important: we don't want our users
waiting for 30-45 seconds just to realize that one of the servers is
down.
I expect that the other conditions will have a marginal decrease in the
time it takes to fetch a resource over HTTP as well. Having this
hypothesis,
an obvious solution becomes apparent: let's make simultaneous
connection attempts!

The Experiment

connie-experiment is the result of my work on this topic. It is a
Python framework
for making and measuring simultaneous TCP connections. It provides
several useful interfaces on top of Python's socket API (which is really
just
a thin wrapper around the BSD socket API). First, it provides the
connie_connect() function which returns a connected socket to a
host/port combination as requested by the caller. Under the hood,
connie_connect() does the following:

Calls getaddrinfo() to get a list of IPs associated with a given
host/port.

Caches the association between host/port and the list of IPs
(currently for 60 seconds).

If after the specified connection timeout no connection is
established, it raises an exception.

If one of the sockets successfully connects, close() is called on
the rest of the sockets. The connected socket is returned.

Additionally, the codebase includes a similar implementation of a TCP
connection function called cached_dns_connect() where the
host/port => IP addresses mapping is also cached for 60 seconds, but
only a single IP address is picked and a connection is attempted. This
function is provided to help create benchmarks against
connie_connect() and the regular socket.connect().

Built on top of connie_connect() and cached_dns_connect(), are two
subclasses of httplib.HTTPConnection
which establish their connections using the two newly implemented
connection functions respectively.

Lastly, there are two benchmark files: one to test a TCP
connect/disconnect sequence, and another to test fetching web resources
over HTTP
after establishing connections using the different strategies provided.

The Results

I encourage everyone to try these out for yourselves. I was able to try
these on a few different setups and the results are below. As you will
seeconnie_connect() almost wins every time, sometimes by a significant
margin. In the cases where one of the servers is not reachable,
(think IPv6 address from a client with no IPv6 connectivity), that
server is simply ignored by connie_connect(). Let's take a look:

As you can see, on residential connections connie_connect() makes a
significant difference, so the hypothesis holds up. When run
in server environments with solid internet connections, it still makes
a significant difference when fetching web resources, but the time to
open/close a connection is very comparable to the canonical connection
strategy. Lastly, connie_connect() works as promised when
one of the servers is down.

Pro's and Con's

There are extra benefits to using an abstraction like the one provided
by connie_connect(). For one, IPv4 vs IPv6 is abstracted
away. Instead of looking at whether the system has a global IPv6
address and worrying whether the network is configured properly, you
can
rest assured that the connected socket returned to you works,
regardless of the underlying IP protocol. This way the transition to
IPv6
becomes a little more seamless. Secondly, DNS entries are cached in
memory for a small amount of time, preventing you from having to do
extra DNS lookups. Third, this connection strategy works for any code,
not just browser to webserver. For example, it can be used when
implementing client-side code for connecting to a REST or SOAP API, or
establishing any TCP connection.

There are some major negatives to using this project in production.
First, creating extra sockets and attempting to connect them will
result in more open files for your kernel to keep track of. Depending
on the workload, you may quickly run out of file descriptors which is a
bad thing. One way to remedy this would be to add a limit on how many
simultaneous connections will be attempted (my gut feeling is that 2-3
would yield good results).

Second, with every call to socket(), connect(), epoll(), and
close() you are introducing
a syscall, which will result in a context switch from your userspace
code to the kernel code. On a mostly idling workstation running a
browser,
this overhead will be minor compared to the latency of establishing a
TCP connection, but on a busy server with many processes all competing
for
system resources it can become more important. Additionally, memory
usage will be higher since more RAM is needed to keep track of TCP
connections
and polling objects.

Thirdly, the current implementation works on Linux only. This is due to
my choice to use epoll() instead of the more portable,
but more limited select(). This is an implementation shortcoming
which can be addressed by implementing the system-specific
polling mechanisms for the popular OS's of today.

Lastly, this code is experimental. It was written to run benchmarks, and
has not been vetted in long-running processes, etc. It is also not
thread-safe (the cache class has no locking). I do not believe it would
require much to get it polished enough to run on mission critical
systems, but that was not the goal of the project, so I am holding off
saying anything else until the project is properly reviewed by people
who,
unlike me, know what they are talking about.

You can get the source for connie-experiment from the GitHub
repo. Please feel
free to comment and contribute. I would love to hear what your thoughts
are. I would especially love to hear from the Google Chrome and Firefox
teams regarding the feasibility of getting this strategy implemented in
browsers.

My last post about mud runs generated quite a few pageviews, so I
figured I'd post a quick update. Hopefully, this info will be helpful to
people doing mud runs in the future. I recently completed my second mud
run (Zombie Escape at Panic Point), which was a great experience.
Here is what I learned there.

First, in addition to all the other things you should bring (towels,
change of clothes, water, cash and a distinctive bag), you should also
bring a snack. My preferred is trail mix and fresh fruits. You'll likely
want to have something like a banana right before you run to make sure
you have enough blood sugar to run fast.

Also, make sure that you bring all of these items with you to the race
location. Leaving a change of clothes in the car is no good if you want
to change after you shower. Panic Point had much better showers than the
previous mud run I did, so this time I actually washed off. They also
provided two tents, one for men, one for women, to change out of the
muddy clothes. The bag check worked very well for me this time around so
I felt no reason to keep all the things I brought in the parking lot.

Another interesting thing that I saw a lot of runners do is using
head-mounted action cams. One guy actually had two of them, plus a
tripod. I saw many videos (for example this one) on YouTube
afterwards that look like they came from these cameras. I doubt it'll
get you to Sundance, but it'd be at least fun to share it with
family/friends. There was also a very cool, but short official
video.

Lastly, this time around my team made our own T-shirts. We used white
cotton-polyester blend shirts and iron-on transfers printed on a high
quality inkjet. Surprisingly the transfers held up really well, though
the shirts are no longer white. The best part: the price. We paid about
$5/shirt, as compared to others at the event who ordered them online for
$20-$30.

I recently had the pleasure of using landslide to create a couple of
quick presentations. The premise here is great: write what you want to
say in Markdown, get elegant slides back. However, while I am familiar
with how to set up Python, install things from GitHub, etc., many are
not. To give the power of landslide to the people (and to use it for
myself), I created (drumroll please), LetSlide. Here, you have a
simple web interface to create landslide presentations, and a place to
host the results. Give it a whirl and let me know what you think.

On April 21st I did a mud run (Rugged Maniac) with a few of my
friends. There were a few things I learned about it that I am going to
pass on, or at least write them down so I don't foget them:

First of all there are certain things you should bring. I did not bring
all these, and should have. Here is my list:

Towels and rags. You will want these in your car on the way back.
You could also use a large towel to wrap around yourself to change.

A change of clothes. There were showers there, but people looked
dirtier coming out than in. The mud is very sticky and a hose
outside will not wash it off easily.

Sports drinks/water. Don't buy it there.

Cash. Almost nobody accepts credit cards there.

A distinctive looking bag for all the stuff. Rugged Maniac had a bag
check, but took forever to find it if the bag was not distinctive
enough.

The question I asked very often of others who have done this run was
"What should I wear?". The answer is not simple, since everyone has
their own preferences. However, here are some nuggets of wisdom I
managed to gleam:

Do not wear anything white or light. It will be ruined by picking up
the color of mud. That is unless you specifically intend to throw
out whatever you are brining.

Do not wear cotton. Spandex, polyester and rayon seem to do better
with repelling mud. I ended up wearing a Nike short sleeve shirt
with long spandex pants

Wear shoes you are willing to throw out. I put mine through the
washer twice and they are still very much mud color and in some
cases full of mud.

Consider Five Fingers style shoes. I do not own a pair, but one of
my running mates did and used it. It sees to have held up well
enough and he did not injure himself. If you already own a pair,
consider using it.

You will likely end up throwing out your socks and underwear.

"How do I train?" and "What obstacles will there be?" were other two
good questions. In general the obstacles included crawling through the
mud, jumping over things and climbing walls. As far as I know, there
isn't much to do to train for crawling in the mud, but you can train for
the jumps by practicing your broad jump. You should also work on
functional fitness, as you will be tested when climbing walls.
Thankfull, they were not too tall, and generally your teammates would be
able to help you if you cannot make it over one. Going into it, I
thought you'd have to be doing a lot of pulling your body up with your
arms only, but that turned out not to be the case with this race.
However, it seems that other races do have more strenuous obstacles that
might require more upper body strength.

There was also lots of running on uneven terrain. You will want to make
sure you have good balance and that you have strong ankles before race
day. Rolling your ankle in the middle of the race, in the middle of the
woods would really suck.

Selecting a mud run also seems to be an important consideration. If this
is your first time, consider doing something on the simpler side, such
as the Rugged Maniac. It was a 5k race, so most people end up finishing
it in about an hour. There are other, much longer races out there that
will take more out of you.

I am sunsetting two of my pet projects due to lack of use. The first is
LovelyCo.de. I never had time to market it properly so it got zero
use since the launch.

The second, is DiscID DB. I was the only user of this project, and
while it was a great experience, setting up and maintaining a public API
and I learned quite a bit, I decided not to continue working on it.

If you have a particular interest in either of these two projects,
please contact me via email (see the About page).