Julien Danjou: Doing A/B testing with Apache httpd
When I started to write the landing page for
The Hacker's Guide to Python, I wanted
to try new things at the same time. I read about A/B testing a while ago,
and I figured it was a good opportunity to test it out.
A/B testing
If you do not know what A/B testing is about, take a quick look at the
Wikipedia page on that subject.
Long story short, the idea is to serve two different version of a page to
your visitors and check which one is getting the most success. When you
found which version is better, you can definitely switch to it.
In the case of my book, I used that technique on the pre-launch page where
people were able to subscribe to the newsletter. I didn't have a lot of
things I wanted to test out on that page, so I just used that approach on
the subtitle, being either "Learn everything you need to build a successful
Python project" or "It's time you make the most out of Python".
Statistically, each version would be served half of the time, so both would
get the same number of view. I then would build statistics about which page
was attracting the most subscribers. With the results I would be able to
switch definitively to that version of the landing page.
Technical design
My Web site, this Web site, is entirely static and served by
Apache httpd. I didn't want to use any dynamic
page, language or whatever. Mainly because I didn't want to have something
else to install and maintain just for that on my server.
It turns out that Apache httpd is powerful enough to implement such a
feature. There are different ways to build it, and I'm going to describe my
choices here.
The first thing to pick is a way to balance the display of the page. You
need to find a way so that if you get 100 visitors, around 50 will see the
version A of your page, and around 50 will see the version B of the page.
You could use a random number generator, pick a random number for each
visitor, and decides which page he's going to see. But it turns out that I
didn't find a way to do that with Apache httpd at first sight.
My second thought was to pick the client IP address. But it's not such a
good idea, because if you got visitors from, for example, people behind a
company firewall, they are all going to be served the same page, so that
kind of kills the statistics.
Finally, I picked time based balancing: if you visit the page on a second
that is even, you get version A of the page, and if you visit the page on a
second that is odd, you get version B. Simple, and so far nothing proves
there are more visitors on even than odd seconds, or vice-versa.
The next thing is to always serve the same page to a returning visitor. I
mean that if the visitor comes back later and get a different version,
that's cheating. I decided the system should always serve the same page once
a visitor "picked" a version. To do that, it's simple enough, you just have
to use cookies to store the page the visitor has been attributed, and then
use that cookie if he comes back.
Implementation
To do that in Apache httpd, I used the powerful
mod_rewrite
that is shipped with it. I put 2 files in the books directory, named either
"the-hacker-guide-to-python-a.html" and "the-hacker-guide-to-python-b.html"
that got served when you requested "/books/the-hacker-guide-to-python".
RewriteEngine On
RewriteBase /books
# If there's a cookie called thgtp-pre-version set,
# use its value and serve the page
RewriteCond % HTTP_COOKIE thgtp-pre-version=([^;])
RewriteRule ^the-hacker-guide-to-python$ % REQUEST_FILENAME -%1.html [L]
# No cookie yet and
RewriteCond % HTTP_COOKIE !thgtp-pre-version=([^;]+)
# the number of seconds of the time right now is even
RewriteCond % TIME_SEC [02468]$
# Then serve the page A and store "a" in a cookie
RewriteRule ^the-hacker-guide-to-python$ % REQUEST_FILENAME -a.html [cookie=thgtp-pre-version:a:julien.danjou.info,L]
# No cookie yet and
RewriteCond % HTTP_COOKIE !thgtp-pre-version=([^;]+)
# the number of seconds of the time right now is odd
RewriteCond % TIME_SEC [13579]$
# Then serve the page B and store "b" in a cookie
RewriteRule ^the-hacker-guide-to-python$ % REQUEST_FILENAME -b.html [cookie=thgtp-pre-version:b:julien.danjou.info,L]
With that few lines, it worked flawlessly. Results The results were very good, as it worked perfectly. Combined with Google Analytics, I was able to follow the score of each page. It turns out that testing this particular little piece of content of the page was, as expected, really useless. The final score didn't allow to pick any winner. Which also kind of proves that the system worked perfectly.
The other week I was toying with using GNU stow to build an NFS-share, which would allow remote machines to boot from it.
It worked. It worked well. (Standard stuff, PXE booting with an NFS-root.)
Then I started wondering about distributions, since in one sense what I'd built was a minimal distribution.
On that basis yesterday I started hacking something more minimal:
Java Sound on Linux
I m often in the position of having my favorite Java program (AltosUI)
unable to make any sounds. Here s a history of the various adventures
I ve had.
Java and PulseAudio ALSA support
When we started playing with Java a few years ago, we discovered that
if PulseAudio were enabled, Java wouldn t make any sound. Presumably,
that was because the ALSA emulation layer offered by PulseAudio wasn t
capable of supporting Java.
The fix for that was to make sure pulseaudio would never run. That s
harder than it seems; pulseaudio is like the living dead; rising from
the grave every time you kill it. As it s nearly impossible to install
any desktop applications without gaining a bogus dependency on
pulseaudio, the solution that works best is to make sure dpkg never
manages to actually install the program with dpkg-divert:
There are several friends and family I want to be able to call with free software. The only way I could make it accessible to them was to burn
WebRTC has been in the most recent stable releases of 
I have always thought that having flexible deadlines in MOOCs is important,
despite not having used them too much. Until last night, that is.
The course in question is Stanford's 
I wanted to have a directory in my Dropbox where every file placed get some sort of encryption. They might be personal pictures (if you know what I mean), finance notes, patent ideas, or the like. I create those files constantly, often with my phone. While I would like to back them up on the cloud, I don t need to access them regularly. The problem is that I don t want my phone to storage them (at least not plain) for obvious reasons. And, on top of this, Android s Dropbox app does not allow to disable synchronization by folder.
So, here is the scheme I came up with. Maybe it is also useful for you or you get some idea how to improve it.
You will need an always-on-line computer with
Zoe slept through last night, which was lovely. We had nothing really
planned for today.
The Bulimba Library has a story time thing at 10:30am on a Friday. I've
never bothered to take Zoe because it would have been too much of a hustle
to get her there after her Brazilian Jiu-Jitsu class, particularly by bike.
Since today we didn't have a BJJ class, it made getting to story time much
easier.
So we had a nice lazy start to the day, and then Zoe just wanted to
procrastinate anyway, so since we were in no particular rush, I let her play
in her room for a bit and I read for a while. We eventually had teeth and
hair brushed and biked over to the library.
Not having been to the story time thing before, I assumed it was in the kids
area, but it turned out it was downstairs in the general purpose room, which
we only discovered after story time had started. I'm certainly glad I never
busted a gut to get to the library in time for it, because it wasn't
anything particularly exciting. They did give all the kids a colouring sheet
and there was some colouring and a couple of songs, but really it was
nothing to phone home about.
I did run into Jacob and his mum Laura from Kindergarten. They live locally,
and so I invited them over for lunch and a play date. They had some grocery
shopping to do, and I had to go to the pharmacy to get a prescription
filled, so we agreed to meet at our place in about an hour.
We biked to the pharmacy to get my prescription filled and some more
sunscreen for Zoe, and the pharmacist gave her a free
I woke up to the news that, after a very short tenure,
As a Drupal user, I have so far attended two DrupalCamps (one in Guadalajara, Mexico, and one in Guatemala, Guatemala). They are as Free Software conferences usually are great, informal settings where many like-minded users and developers meet and exchange all kinds of contacts, information, and have a good time.
Torre de Ingenier a
This year, I am a (minor) part of the organizing team. DrupalCamp will be held in
Back in 2007 I stumbled over the "Plus Fours Routefinder", an invention of the
1920's. It's worn on the wrist and allows the user to scroll through a map of
the route they planned to take, rolled up on little wooden rollers.
For a while now I've been looking for ways to improve my photo workflow - to simplify and speed up the process. Now I've gotten a new toy to help that along - a Panasonic FlashAir SD card with WiFi connectivity. I was pretty sure that build-in workflows of some more automated solutions would not be a perfect fit for me, so I got this card which has a more manual workflow and a reasonable API, so I could write my own.
Now I am trying to work out my requirements, the user stories if you will.
I see two distinct workflows: live event and travel pictures.
In both cases I want the images to retain the file names, Exif information and timing of the original photos and also have embedded GPS information from the phone synced to the time the photo was taken. And if I take a burst of very similar photos, I want the uploading process to only select and upload the "best" one (trivial heiristic being the file size) with an ability for me to later choose another one to replace it. There would need to be some way of syncing phone and camera time, especially considering that phones usually switch to local time zone when traveling and cameras do not, maybe the original time the photo was taken would need to be changed to local time zone, so that there are no photos that are taken during the day, but have a timestamp of 23:45 GMT.
When I am in Live Event mode I would like the photos that I take to immediately start uploading to an event album that I create (or choose) at the start of the shoot with a preset privacy mode. This assumes that either I am willing to upload via 3G of my phone or that I have access to a stable WiFi network on-site. It might be good if I could upload a scaled down version of the pictures during the event and then later replace the image files with full-size images when the even is over and I am at home in my high-speed network. I probably don't need the full size files on my phone.
When I am in Travel mode, I want to delay photo uploading until I am back at the hotel with its high speed Wifi, but also have an option to share some snapshots immediately over 3G or random cafe Wifi. I am likely to take more photos that there is memory in my phone, so I would like to clear original files from the phone while keeping them in the SD card and in the cloud, but still keeping enough metadata to allow re-uploading an image or choosing another image in a burst.
Now I need to flesh out the technical requirements from the above and write an Android app to implement that. Or maybe start by writing this in Python as a cross-platform command-line/desktop app and only later porting it to Android when all the rought parts are ironed out. This will have an extra benefit of people being able to run the same workflow on a laptop instead of a phone or tablet.
Let's assume that this is written in a pretty flexible way, allowing to plug in backends for different WiFi SD cards, cloud services, plug-in points for things like instant display of the latest photo on the laptop screen in full-screen mode and other custom actions, what else would people love to see in something like this? What other workflow am I completely overlooking?