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 ) . 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://github.com/AmmarkoV/AmmarServer ” ) you can use the bash script provided in the repository and called “MirrorAmmarServer.sh”
Lets say that your WordPress blog is hosted on http://ammar.gr .
STEP 1 ) Being on the parent directory of AmmarServer issue “./MirrorAmmarServer.sh http://ammar.gr”
wget will gradually start to mirror the site into static files and create a subdirectory called ammar.gr/ 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]=”ammar.gr/”;
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 http://127.0.0.1:8080 ( 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 )
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 ) , 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..