Replacing my WebServer with the Pi..

Posted: 23rd October 2012 by Ammar Qammaz in Post

My very own Raspberry Pi just arrived today.. It took almost 10 days to come , but I got the updated 512MB RAM model so , everything went better than expected.. :D .. Now I can finally return the one that I borrowed ( the second one I borrowed :P anyways.. ) ..

Two Raspberry Pi's with modmy pi cases

Today I spent a good part of the day migrating my stuff to the Raspberry..
The SD card I have installed has a total size 4GB so unfortunately not all of my things could fit..!
Also I am very concerned about the memory wear problem so I am thinking of adding a USB hard drive and mounting all of the most active parts of the SD filesystem there ( /var /tmp /home/user/public_html etc.. )

The server that I plan to replace is this ( first time posing for the camera.. )
AmmarServer Mini-ITX Raspberry Pi Vs My current web server box

Its a cabling mess really :) with a case made out of the retail motherboard box..

The raspberry takes much less space and will draw much much less power making this site more eco-friendly :) .. My UPS will also be able to power it up for days in the event of a power failure ..

I also conducted some experiments with wordpress on the raspberry , it performs worse than my current machine but my upload bandwidth is such a big bottleneck that 300ms of delay are barely noticeable ( I tested it from the computers of some of my friends and sometimes it takes almost 20 seconds for it to completely load ) ..

As I’ve mentioned before , one of the original goals of AmmarServer was getting rid of my current web server and replacing it with a Raspberry Pi. As one can easily notice this site is based on wordpress ( one thing that is a little harder to notice is that it is hosted in a PC in my kitchen :P ) . WordPress is a heavy burden even on my current Intel Based machine let alone on the slower Raspberry Pi.

There are tools that cache the wordpress web pages or imporve PHP performance but basically all of them try to work around quering the database and PHP interpreter and serving static files instead..

To add to the CPU limitations of the Pi , using an SD card also means delays when writing/and reading to disk ( not to mention the finite read/write cycles ) when performing automatic caching operations , so instead of this I decided to add a script ( basically an alias for a wget call with the needed parameters ) that clones the whole site without hassle..

If you want to try it and after cloning AmmarServer ( with “git clone git:// ” ) you can use the bash script provided in the repository and called “”
Lets say that your WordPress blog is hosted on .
STEP 1 ) Being on the parent directory of AmmarServer issue “./”
wget will gradually start to mirror the site into static files and create a subdirectory called where the files will be stored
STEP 2 ) Edit the file src/main.c and change char webserver_root[MAX_FILE_PATH]=”public_html/”; to char webserver_root[MAX_FILE_PATH]=””;
If you want you can change the DEFAULT_BINDING_PORT to another port ( you may want to set it to port 80 because the default is 8080 )
STEP 3 ) issue “./make && ./run_ammarserver” and voila your site will be availiable at ( or any other port you choose )

Here is a comparison of pinging the Raspberry Pi and pinging my Intel Based Server PC on a LAN

The ping times of the intel system have an average of 0.158 ms while the raspberry pi has an average time of 0.543 ms , almost 3-4 times worse..

Here are some benchmarks conducted with chromium that give an overview of the performance difference ( all of the tests are done in a LAN so bandwidth is not a limiting factor ) :

Left : First Uncached Hit , Apache Serving regular WordPress on my regular PC ( 1.33MB transferred , DOMContent loaded @ 494 ms , onload @ 1.35s )
Right : First Uncached Hit , AmmarServer serving cached static files on Raspberry Pi ( 1.39MB transferred , DOMContent loaded @ 159 ms , onload @ 968ms )

Left : Second Hit after clicking Home , Apache Serving regular WordPress on my regular PC ( 22.67KB transferred , DOMContent loaded @ 566 ms , onload @ 2.04s )
Right : Second Hit after clicking Home , AmmarServer serving cached static files on Raspberry Pi ( 61.54KB transferred , DOMContent loaded @ 140 ms , onload @ 515ms )

Apache Serving cached static files on left compared to AmmarServer serving cached static files on right
Left : Apache Serving cached static files on my Regular PC
Right : AmmarServer serving cached static files on Raspberry Pi

Some things to notice is that in the static files version of the site , the image links on the menu bar that come directly from github , and the youtube embeds are the most laggy parts of the page and this distorts loading times. The onload event would drop by almost 400ms if they were part of the site..

Performance also gets better by increasing the priority of the webserver ( IRL decreasing it to -15 :P ) , removing cross-site content and making some other small tweaks. I have managed to drop times to around 50-60ms and I hope to further improve those numbers..

Network latency of course is the biggest bottleneck when dropping times so low and in any case even if i managed to serve the whole site from 60ms ( transaction latency ) + 150ms ( network latency ) in say 20ms ( transaction latency ) + 150 ms ( network latency ) the perceived difference from the average client will be very small..

Thats it for now.. :)

ETags 304 Not Modified and 200 OK headers..!

Posted: 17th October 2012 by Ammar Qammaz in Post
Tags: , ,

For the last couple of days I have been implementing ETags on AmmarServer which seem to be a nice way for cache handshaking ( and work very well with my internal server side caching mechanism ) ..

To profile my server’s behaviour I am using chromium and the very handy Developer Tools that come integrated in it , Especially the Network Timeline feature is great for debugging this sort of things.. RedBot is also a very useful tool! that I use for debugging HTTP handshakes..

Although my implementation isn’t ready yet I am getting some very weird results when I emmit 304 Not Changed responses illustrated in the screenshots bellow ..!

The screenshots are that big due to my dual 1080p screen setup :P

Apache And AmmarServer both serving 200 OK responses..

Apache and AmmarServer , AmmarServer emmiting 304 responses and Apache 200 OK

I can’t seem to grasp the reason why a 304 response has such a large “Waiting Time” , Is it my Response header that is missing something , is it the whole Keep Alive thing not being handled properly , or is the waiting time supposed to mean something else in the graph..
How is it possible when only 200 byte headers get served that the response time is 4 times worse than when the full files get served from memory ?

I haven’t still figured it out and it is driving me crazy , but I will get to the bottom of this :P ..

After some tweaking around and with the help of redbot it turns out that the 304 Not Modified header should retransmit all of the original fields transmitted with the first “200 OK” message.. This means all of the E-Tag , Date etc fields.. I was missing out some of them so including them fixed the behaviour..

AmmarServer has a Wiki now..

Posted: 12th October 2012 by Ammar Qammaz in Post

I just finished creating a Wiki for AmmarServer..
It is not very detailed but , I believe , gives an overview of what I am trying to achive..

Hope you find it useful..!

Testing the raspberry pi as a webserver!

Posted: 25th September 2012 by Ammar Qammaz in Post
Tags: , , ,

My friend Philimon lent me his new raspberry pi after experiencing problems using the usb ports on the board.. After a little tinkering I found out that using a usb hub with an external power supply solved the issues and everything worked fine so his problems must have been power related with the pi not supplying enough juice for the power hungry usb peripherals he connected.

Having the opportunity to first-hand test the pi I immediately apt-got git and cloned my AmmarServer repo to test it with the board :)

The results look very promising since the pi with ammarserver beats my current mini-itx intel atom based setup which is running the heavier apache webserver..

In more detail subsequently querying a static version of the the page you see right now ( as described in a previous post ) gave the following times..

Raspberry Pi using AmmarServer :
00:00:02.64 <- first uncached try with actual sd read time ( also worth to note that a Class 10 sd card is used )
00:00:00.706 <- rasp cached , no file reading involved
00:00:00.787 <- rasp cached , no file reading involved
00:00:00.818 <- rasp cached , no file reading involved
00:00:00.833 <- rasp cached , no file reading involved
00:00:00.788 <- rasp cached , no file reading involved
00:00:00.810 <- rasp cached , no file reading involved

My current webserver using apache ( and dynamic content [ php/mysql/wordpress ] ) :
00:00:02.802 <- with apache
00:00:01.561 <- with apache (some images etc. cached probably)

My current webserver using AmmarServer ( and static saved pages ) :
00:00:01.72 <- first uncached try with actual hd read time
00:00:00.678 <- with ammarserver cached , no file reading involved
00:00:00.652 <- with ammarserver cached , no file reading involved

As one can see the best times of the pi 00:00:00.706 are pretty damn close to the 00:00:00.652 of my current machine when the content is already cached in memory so I may be changing my web hosting setup soon..!

I will probably keep my current webserver as a platform to make dynamic webpages using the really nice GUI of wordpress and then pass static versions of them to the pi which will act as the always on webserver..
An additional thing that I didn't test was performance using more processes like a mumble server, an ftp server or an actual php/apache setup but..

When I'll order my own pi I will try all of them and blog back with my results..!