Tuesday, August 9, 2011

Go Faster Stripes for site performance and google ads


Carrying on our performance experiments with Amazon AWS and Go..

Repeating the same experiments, but comparing EC2 with S3.

S3 looked like this last time:

Document Complete
Fully Loaded
Load Time
First Byte
Start Render
DOM Elements
Time
Requests
Bytes In
Time
Requests
Bytes In
First View
0.518s
0.391s
0.000s
14
0.518s
1
1 KB
0.518s
1
1 KB
Repeat View
0.363s
0.237s
0.000s
14
0.363s
1
0 KB
0.363s
1
0 KB

Document complete in under half a second, with TTFB of 0.391s and document complete 0.518s

These look pretty respectable, but now compare with an EC2 instance (t1.large linux) using Google Go language as a HTTP server


Document CompleteFully Loaded
Load TimeFirst ByteStart RenderDOM ElementsTimeRequestsBytes InTimeRequestsBytes In
First View0.342s0.212s0.000s140.342s11 KB0.342s11 KB
Repeat View0.389s0.224s0.000s140.389s11 KB0.389s11 KB

Faster across the board - TTFB has halved to 0.212s and this is time saved off document complete and fully loaded. I was expecting that S3 would be very fast at serving static content, and its looks reasonable, but compared to this single server (large admittedly) its a fair % slower.

Now what happens with Google adverts? we get a similar google ads penalty to last time, 1.5s penalty on document complete and fully loaded:

Document CompleteFully Loaded
Load TimeFirst ByteStart RenderDOM ElementsTimeRequestsBytes InTimeRequestsBytes In
First View1.582s0.283s0.411s1751.582s1051 KB1.582s1051 KB
Repeat View1.184s0.210s0.523s1751.184s26 KB1.184s26 KB

Whats hidden in these numbers is a little gem - the ~0.200s saved using the EC2 instance is still there, i.e. this performs ~0.200s faster than S3 even when using Google Ads.

So even if you have a very heavy page, and are using CDN or other techniques to speed things up, you really need to see if you can get your TTFB down - and that may mean looking at async HTTP servers such as Go or Node.js

Here is the Go code for this example (the HTML is literal using back-quotes `), based on one of the Go examples:


package main


import (
        "fmt"
        "http"
)


func Hello(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w,
`
<!doctype html>
<html lang="en-GB">
<head>
  <meta charset="utf-8">
  <title>Croydon</title>
  <meta name="description" content="Croydon">
</head>
<body>
        <article>
                <p>Croydon</p>
                <p>Information on Croydon: shops, restaurants, property, schools, council & government</p>
        </article>
        <script type="text/javascript"><!--
                google_ad_client = "pub-7600935420912685";
                google_ad_slot = "7690333966";
                google_ad_width = 336;
                google_ad_height = 280;
                //-->
        </script>
        <script type="text/javascript"
                src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
        </script>
</body>
</html>`)
}


func main()  {
        http.HandleFunc("/", Hello)
        http.ListenAndServe(":8080", nil)
}


Note that the previous tests were rerun to ensure no significant variance in timings. The next set of test will be to see if we can keep sub-0.300s for template based content (as opposed to hard-coded HTML)


No comments: