How to Improve Amazon S3 Download Performance with a CDN
January 2, 2013 | Justin Dorfman
Say it with me: S3 is not a CDN
— David Cramer (@zeeg) February 3, 2013
|Amsterdam, NL||1,751ms||171ms||-1,580ms (90.23%)|
|Chicago – GLC||1,208ms||120ms||-1,088ms (90.62%)|
|New York – VZN FIOS||1,242ms||591ms||-651ms (52.41%)|
Step 1: Create Your S3 Bucket
$ curl -I http://s3.amazonaws.com/netdna/Max-Juggling-800x1228.png HTTP/1.1 200 OK x-amz-id-2: uXxRZBOYCBapOWjbhgeyyoKuOEnCxf+yi4W7BYjDuSvQluIBpbvx8EEqEjr4miPg x-amz-request-id: 663DBAC989E2992D Date: Thu, 03 Jan 2013 00:25:42 GMT Last-Modified: Wed, 02 Jan 2013 21:31:21 GMT ETag: "c0a8b02d44d6771eeb5d034e941a62ee" Accept-Ranges: bytes Content-Type: image/png Content-Length: 350404 Server: AmazonS3
Step 2: Create Your (CDN) Pull Zone
Our next step is to create a Pull Zone on MaxCDN. [Updated] Follow these steps: http://support.maxcdn.com/howto/create-a-pull-zone/
Now that the Pull Zone is provisioned, check to see if the image is cached on the CDN:
$ curl -I http://s3pullnetdna.jdorfmanqa.netdna-cdn.com/Max-Juggling-800x1228.png HTTP/1.1 200 OK Date: Thu, 03 Jan 2013 00:13:02 GMT Content-Type: image/png Content-Length: 350404 Connection: keep-alive x-amz-id-2: zXcIev2CEQbxeyukY07YljRGt5OjbjupEXREuXvtY4T8yauyXsJFp4QHh3wkfYy3 x-amz-request-id: A5F6FE3774D58024 Last-Modified: Wed, 02 Jan 2013 21:31:21 GMT ETag: "c0a8b02d44d6771eeb5d034e941a62ee" Server: NetDNA-cache/2.2 X-Cache: HIT Accept-Ranges: bytes
Notice the 2 new headers in the response:
- Server: NetDNA-cache/2.2
- X-Cache: Hit
Server is the version of the NetDNA Caching Server. X-Cache shows if the upstream Edge Server had the file cached. The first two requests will have a value of MISS, since Edge Servers only cache files once they are requested twice (this prevents rarely-accessed long-tail content from filling caches).
Step 3: Measure Performance
Using Chrome’s Developer Tools, we can peek at the file load time from the browser’s perspective (well under a second):
But that’s a single data point. With Catchpoint, we ran a detailed 4-hour performance test. As you can see, there’s a huge improvement when using a CDN vs. S3.
- Average response: CDN (300ms) vs. S3 (1.8 – 2.7s)
- Median response: CDN (200 – 400ms, worldwide) vs. S3 (1.2 – 4.2s, worldwide)
A dedicated CDN offers consistent performance, and global load times up to 10x better than S3. But there’s no need to choose: use S3 as your origin server, and MaxCDN to speed up your site for every visitor.