Need Quality Code? Get Silver Backed

Better, Faster, Stronger - Why you should use a CDN

20thDec

0

by Gary H

My crown is called content, a crown that seldom kings enjoy

William Shakespeare

If you're a regular visitor of the Leaping Gorilla site then you may have noticed some major improvements in speed over the last few days. That's because we've updated our site to use Amazon CloudFront - a Content Delivery Network (CDN).

What is a CDN?

A CDN acts as a middle man between your server and your users. A good CDN will take content from your servers and cache it in edge locations dispersed around the globe. These are located closer to your users so can serve the cached content faster than it would take for a full trip to your servers.

Lets take an example of retrieving a page from the Leaping Gorilla site without a CDN. Here's a typical trace route to get the home page:

TraceRoute to 54.247.74.254 [www.leapinggorilla.com]
Hop	(ms)	(ms)  (ms)	IP Address	    Host name
1 	 0 	  	0 	  0 	8.9.232.73	    xe-5-3-0.edge.dallas.level3  
2 	 127 	126   126 	4.69.145.126	vlan70.csw2.dallas1.level3  
3 	 129 	129   129 	4.69.151.146	ae-73-3.ebr3.dallas1.level3  
4 	 129 	130   129 	4.69.134.22	    ae-7-7.ebr3.atlanta2.level3  
5 	 129 	128   128 	4.69.132.86	    ae-2-2.ebr1.washingt.level3  
6 	 129 	130   130 	4.69.134.134	ae-7-7.csw2.washingt.level3  
7 	 131 	129   129 	4.69.134.149	ae-2-72.ebr2.washngt.level3  
8 	 130 	130   130 	4.69.137.49	    ae-41-41.ebr2.paris1.level3  
9 	 130 	130   130 	4.69.153.241	ae-2-12.bar1.dublin3.level3  
10 	 130 	130   130 	195.16.170.102	 -  
11 	 130 	131   130 	178.236.0.130	 -  
12 	 132 	144   132 	178.236.0.125	 -  
13 	 132 	132   132 	79.125.0.137	ec2-LGMACHINE.eu-west-1  

As you can see, the request gets bounced around numerous servers as it moves through the internet to the Leaping Gorilla site. each of these hops adds latency to the request (more time for your user to wait) and dont forget this is just to retrieve the initial page. The browser will then need to get all of the resources - CSS, JavaScript, Images etc. that the page requires to render.

CDN to the Rescue

By using a CDN we eliminate all of these lookups. We change our DNS records to point at the CDN CNAME. When a user requests the Leaping Gorilla site now they instead get redirected to the nearest edge server for the CDN. If the page that they requested has been cached this will be immediately served back - we wont even hit the server! If it hasn't been cached the edge location will use an optimised path to pull the page from your server and distribute it to the user.

How much of a difference can this make? Let's take a look at a traceroute for the Leaping Gorilla home page with a CDN enabled:

TraceRoute to 54.230.120.44 [www.leapinggorilla.com]
Hop	(ms) (ms) (ms)  IP Address		Host name
1 	  1    0    0   8.9.232.73	  	xe-5-3-0.edge3.dallas1.level3  
2 	  0    0    0   4.69.145.11	  	ae-1-60.edge2.dallas1.level3  
3 	  0    1    1   4.68.63.10	   	  -  
4 	  0    0    0   129.250.196.38	ae-0.amazon.dllstx09.us.ntt.net  
5 	  0    0    0   54.230.120.44	server-54-230-120-44.cloudfront

We go from 15 hops to 5 and just look at the difference in latency! We're using our CDN's dedicated infrastructure for the lookup so it happens over blazing fast dedicated connections.

Benefits

The benefits to Leaping Gorilla have been huge. We've gone from a very troubling load time of up to 6 seconds per page when accessing our EU servers from the USA to under 300ms. Also, whilst the content is served from the edge it means that it doesn't hit our server reducing load and enabling us to serve more requests with less infrastructure.

Cost

Nothing comes for free, so how much does it cost? So far - peanuts. We're looking at a monthly bill in the single digit dollar range. On tests with our clients we've been able to deliver a 10x improvement in page load from remote geographical areas whilst serving ~100GB of data/month for around $75. The kicker to this though? The edge locations reduced load on the main servers enough that we were able to thin out the server farm resulting in a net gain to the client.

I Want One!

If you are interested in setting up a CDN yourself then we would heartily recommend you use the CloudFront documentation as a starting point. If you would like our help to do this then feel free to contact us for a quote.

News , Performance , AWS

Comments are Locked for this Post