Improve Page Render Time with Amazon Cloudfront

34
Improve Page Load Time with Amazon CloudFront

description

Amazon's CloudFront provides a self-served CDN solution without a contract. In this talk we will walk through the steps to set up CloudFront. We will also talk about how we measure page render time and take a look at how using CloudFront affects page render time for Polyvore in different countries. Slides from Polyvore Tech Talk #1

Transcript of Improve Page Render Time with Amazon Cloudfront

Page 1: Improve Page Render Time with Amazon Cloudfront

Improve Page Load Time with Amazon CloudFront

Page 2: Improve Page Render Time with Amazon Cloudfront

Faster site → happier users

Page 3: Improve Page Render Time with Amazon Cloudfront

Faster site → more site usage

Page 4: Improve Page Render Time with Amazon Cloudfront

Faster site → lower hardware cost

Page 5: Improve Page Render Time with Amazon Cloudfront

Faster site → better google ranking

Page 6: Improve Page Render Time with Amazon Cloudfront

Polyvore is a image-heavy site

7000 images served per second (peak)240M images served per day40TB images served per month

Page 7: Improve Page Render Time with Amazon Cloudfront

Polyvore is a global site

Global user baseAt the speed of light, round trip from Europe to California takes more than 100 msOur images load slowly for international users.

Page 8: Improve Page Render Time with Amazon Cloudfront

CDN: Geologically distributed caches

We can't speed up light.

But we can shorten the distance.

Page 9: Improve Page Render Time with Amazon Cloudfront

User connects to the nearest server (the edge server)

Lower latencyFaster downloadMore reliable connection

Page 10: Improve Page Render Time with Amazon Cloudfront

More servers serving data

Increases bandwidth by eliminating central server bottleneck.

Page 11: Improve Page Render Time with Amazon Cloudfront

Amazon CloudFront

Amazon's CDN offeringSelf-served, no sales peoplePay as you goAPINo contract

Page 12: Improve Page Render Time with Amazon Cloudfront

Setup CloudFront

Page 13: Improve Page Render Time with Amazon Cloudfront

Set up an origin server

An origin server stores the definite version of your objects.Could be an Amazon S3 bucket or your own web server

Page 14: Improve Page Render Time with Amazon Cloudfront

Create a distribution

A distribution specifies the location of your origin server.A distribution has a unique CloudFront domain name, e.g. d2zdxp93p38w2g.cloudfront.net

Page 15: Improve Page Render Time with Amazon Cloudfront

Create a distributionIn the AWS managing console:

Page 16: Improve Page Render Time with Amazon Cloudfront

Serve objects under the distribution domain

http://d2zdxp93p38w2g.cloudfront.net/images/logo.jpg

→ www.polyvore.com/images/logo.jpg

Page 17: Improve Page Render Time with Amazon Cloudfront

Use CNAMEsOptional, but recommendedSet it up in the distribution and your DNS

Page 18: Improve Page Render Time with Amazon Cloudfront

Why use CNAMEs

No more cumbersome CloudFront domain

More flexibility to change CDN provider

Page 19: Improve Page Render Time with Amazon Cloudfront

Cache controlObjects expire in 24 hours by default.Set your own cache control headers to override the default. e.g.

Expires: Mon, 12 Apr 2021 00:26:56 GMT Cache-Control: max-age=31536000

Minimum expiration time you can set is one hour.

Page 20: Improve Page Render Time with Amazon Cloudfront

Object invalidationRemoves an object from cache before it expires.Useful when updating an object.Call the InvalidationBatch function in the API

Page 21: Improve Page Render Time with Amazon Cloudfront

Reporting tools

Amazon doesn't provide much.

Download access logs and roll your own analysis.

Page 22: Improve Page Render Time with Amazon Cloudfront

Does it really help?

Page 23: Improve Page Render Time with Amazon Cloudfront

Compare performance

Single image file download time:156 ms vs 478 ms

Measured by Pingdom, through their global server network.

Page 24: Improve Page Render Time with Amazon Cloudfront

Compare performance

Page load time improvements:

Page 25: Improve Page Render Time with Amazon Cloudfront

Compare performance

Slower in some countries, mostly countries with low traffic.

Overall 11% improvement in page load time.

Page 26: Improve Page Render Time with Amazon Cloudfront

How we measure itUse Javascript to measure page load time and beacon it back

At the top of each page(function() { // record page start time var start = new Date().getTime(); window.onload = function() { // record page load time var _end = new Date().getTime(); // fetch the beacon and pass in (_end - _start) ... });};})();

Process our access log to gather the beaconed data.External resource files may throw the number off

Page 27: Improve Page Render Time with Amazon Cloudfront

Should I use CloudFront?

Page 28: Improve Page Render Time with Amazon Cloudfront

Cache hit rate dictates CDN performance

A missing object needs to be retrieved from the origin server before it can be served, and it is more expensive than serving it from the origin server directly.

Page 29: Improve Page Render Time with Amazon Cloudfront

What determines hit rate?

Access pattern to your objects1 object accessed 10M times → good10M objects accessed 1 time each → bad

How much space is allocated on edge serversObject eviction: when edge servers are short on space, objects may get removed before they expire.Amazon doesn't share specific stats about eviction.

Page 30: Improve Page Render Time with Amazon Cloudfront

So what's our hit rate?Amazon doesn't provide this stats. We determined it's around 85% by analyzing CloudFront's access logs and our own.

Page 31: Improve Page Render Time with Amazon Cloudfront

Bonus material Akamai vs CloudFront

Page 32: Improve Page Render Time with Amazon Cloudfront

Akamai: bigger, faster, and cheaper?

More edge servers.Competitive price

Page 33: Improve Page Render Time with Amazon Cloudfront

Akamai performance test

Twice as fast in single file testLive traffic test non-conclusiveWorking with Akamai to diagnoseWe'll post updates

Page 34: Improve Page Render Time with Amazon Cloudfront

Questions & follow-ups

[email protected]