Hello World,
been quite a long time since my last post here..
This blog post is about URL shortners and specifically my URL shortner (MyURL) based on the infrastructure of AmmarServer
For more information on AmmarServer you can read this
URL shortners are internet tools that take long and impossible to remember URL strings like http://www.youtube.com/watch?v=lR9mNuLIPBU and add an easier to remember (or a random) alias that makes it shorter..!
like http://tinyurl.com/d69n5sr or http://myurl.ammar.gr/fadetoblack ..
This web-service of course is a pretty straightforward one since it is just a lookup table with aliases pointing to strings and thats about it ,on the server side.. Thats also the reason why it is one of the first “service applications” of AmmarServer..
The code itself is simple and at the time around 420LOC , though I would like to reduce them even more..
The whole server executable is around 90KB ( taking efficiency seriously ;P )
and apart from the server binary there is also a plain-text file called myurl.db which contains the aliases and real links. Literally these are the two things you need and you got yourself a URL shortner.
Of course the db file is read only one time on startup and it is written every time a new alias is added from a user.
Basically what we do is spawn an AmmarServer instance on port 8080 and use an apache proxy to redirect traffic going to myurl.ammar.gr to 127.0.0.1:8080 . This can be easily done by enabling mod_proxy ( sudo a2enable mod_proxy , sudo a2enable mod_proxy_http ) and by adding a virtual host like the next code segment
<VirtualHost *:80>
ServerName myurl.ammar.gr
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
( Note : I would really like to make a proxy based on AmmarServer and probably will do to be able to get rid of apache completely )
Of course as I do with most things I tested MyURL against other popular URL Shortners , ( namely tinyurl.com , bit.ly , goo.gl , tr.im and ow.ly ) and found out a good performance advantage ..
As demonstrated below :
Task Shortening ->
time wget http://www.youtube.com/watch?v=lR9mNuLIPBU
2013-04-19 17:05:03 (840 KB/s) – `watch?v=lR9mNuLIPBU.1′ saved [232418]
real 0m0.755s
user 0m0.000s
sys 0m0.008stime wget http://myurl.ammar.gr/fadetoblack
2013-04-19 17:50:19 (12.7 MB/s) – `fadetoblack.7′ saved [127/127]
real 0m0.066s
user 0m0.000s
sys 0m0.000stime wget http://tinyurl.com/d69n5sr
2013-04-19 16:15:08 (815 KB/s) – `d69n5sr’ saved [232370]
real 0m1.082s
user 0m0.000s
sys 0m0.008stime wget http://bit.ly/plIyZu
2013-04-19 16:18:03 (716 KB/s) – `plIyZu’ saved [232383]
real 0m1.038s
user 0m0.000s
sys 0m0.008stime wget http://goo.gl/XAQqU
2013-04-19 16:19:22 (742 KB/s) – `XAQqU’ saved [232387]
real 0m0.825s
user 0m0.004s
sys 0m0.008stime wget http://tr.im/42d2q
2013-04-19 16:23:29 (825 KB/s) – `42d2q’ saved [232693]
real 0m1.218s
user 0m0.000s
sys 0m0.012stime wget http://ow.ly/kdVRX
2013-04-19 16:36:15 (806 KB/s) – `kdVRX’ saved [232907]
real 0m1.209s
user 0m0.004s
sys 0m0.008s
Of course this is not an accurate benchmark since myURL currently only has around 30 aliases while the other services have possibly millions , and also I am testing this from Crete , Greece , and the myURL server is in Athens Greece , while most of the others are on the US ( which implies a lot of “jet”lag ) , and network congestion might vary from time to time..
Then I took a look on the filesizes of the responses , which to my amazement was ~300KB .. Turns out that due to the Redirection using 301 headers wget was actually going on and retrieving the full youtube page so i then went on subtracting this time from each of the responses which yielded
myURL 0.066s <- myURL performance
tinyurl 0.327s
bit.ly 0.283s
goo.gl 0.07s <- this is also awesome
tr.im 0.463
ow.ly 0.454s
So that being said , considering my non-special hardware server , my plain DSL connection , my DynDNS DNS , my D-Link ADSL modem doing NAT and serving the data , myURL performance is overall superfast
!
One question is how the f*$# is google going “as” fast ( and while providing a better service , analytics , user based “tracking” ;P etc ) and another one is how much faster could I go
!
When running a test through a local loopback connection I get
time wget http://127.0.0.1:8080/fadetoblack
2013-04-19 17:27:05 (5.55 MB/s) – `fadetoblack.1′ saved [127/127]
real 0m0.010s
which is the maximum throughput the server can go at ( it is 7 times less than google’s net time ) If I only knew a little bit about how fast goo.gl go from inside their LAN , or what their software architecture is like
You can find MyURL here -> http://myurl.ammar.gr/ , although it is in alpha stage and thus will probably not be always online ( as I am performing tests on it , recompiling ,restarting etc ) ..!
Also ammar.gr is not exactly a high-availiability site , mainly thanks to my ISP ![]()
Of course as mentioned above myurl.ammar.gr is the same as calling http://ammar.gr:8080 . Of course calling myurl.ammar.gr also adds an overhead for the proxy thing to take place but for now it will have todo , Also I might change ports in the future so myurl.ammar.gr will be the thing to remember..







