SlideShare uma empresa Scribd logo
1 de 58
Baixar para ler offline
• Philip Tellis

•                           .com
• philip@lognormal.com
• @bluesmoon
• geek paranoid speedfreak
• http://bluesmoon.info/




    Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   1
I <3 JavaScript




Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   2
So much that I wore Mustache socks to my wedding




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   3
I’m also a Web Speedfreak




Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   4
We measure real user website performance




Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   5
This talk is (mostly) about how we abuse JavaScript to do it




  Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   6
Abusing JavaScript to Measure Web
                Performance

           Philip Tellis / philip@lognormal.com


            Boston #WebPerf Meetup / 2012-07-24




Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   7
First, a note about the code




                       Note that in the code that follows,

                                       + new Date

                                      is equivalent to

                            new Date().getTime()




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   8
1
                               Latency



Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   9
1 Blinking Lights


        It takes about 16ms for light to get from SF to Boston
                        (24ms through fibre)

                                             ...




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   10
1 Blinking Lights


        It takes about 16ms for light to get from SF to Boston
                        (24ms through fibre)

             Though it takes about 100ms to ping... why?




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   10
1 HTTP




     Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   11
So to measure latency, we need to send 1 packet each way, and
                           time it




   Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   12
1   Network latency in JavaScript




      var ts, rtt, img = new Image;
      img.onload=function() { rtt=(+new Date - ts) };
      ts = +new Date;
      img.src="/1x1.gif";




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   13
1 Notes


    • 1x1 gif is 35 bytes
    • including HTTP headers, is smaller than a TCP packet
    • Fires onload on all browsers
    • 0 byte image fires onerror
    • which is indistinguishable from network error




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   14
2
                    TCP handshake



Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   15
2 ACK-ACK-ACK




     Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   16
2 Connection: keep-alive




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   17
2   Network latency & TCP handshake in JavaScript
    var t=[], tcp, rtt;
    var ld = function() {
        t.push(+new Date);
        if(t.length > 2) // run 2 times
          done();
        else {
          var img = new Image;
          img.onload = ld;
          img.src="/1x1.gif?" + Math.random()
                               + ’=’ + new Date;
        }
    };
    var done = function() {
       rtt=t[2]-t[1];
       tcp=t[1]-t[0]-rtt;
    };
    ld();
       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   18
Notice that we’ve ignored DNS lookup time here... how would
                      you measure it?




   Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   19
Network Throughput
                                3
Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   20
3 Measuring Network Throughput



                                     data_length
                                    download_time




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   21
Should you fly a 747 or a 737?



       • A 747 seats 400+ passengers
       • A 737 seats about 150
       • Both take about the same time to fly from SFO to BOS
       • A 747 takes longer to load and unload




   The best selling aircraft to date is the 737




            Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   22
3   Network Throughput in JavaScript




    // Assume global object
    // image={ url: ..., size: ... }
    var ts, rtt, bw, img = new Image;
    img.onload=function() {
       rtt=(+new Date - ts);
       bw = image.size*1000/rtt;     // rtt is in ms
    };
    ts = +new Date;
    img.src=image.url;




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   23
3 Measuring Network Throughput



        If it were that simple, I wouldn’t be doing this talk.




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   24
3 TCP Slow Start




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   25
3 Measuring Network Throughput



   So to make the best use of bandwidth, we need resources that fit
                         in a TCP window




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   26
3 There is no single size that will tax all available networks




   http://www.yuiblog.com/blog/2010/04/08/analyzing-bandwidth-and-latency/




           Boston #WebPerf Meetup / 2012-07-24        Abusing JavaScript to Measure Web Performance   27
3   Network Throughput in JavaScript – Take 2

    // image object is now an array of multiple images
    var i=0;
    var ld = function() {
       if(i>0)
          image[i-1].end = +new Date;
       if(i >= image.length)
          done();
       else {
          var img = new Image;
          img.onload = ld;
          image[i].start = +new Date;
          img.src=image[i].url;
       }
       i++;
    };

       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   28
3 Measuring Network Throughput



         Slow network connection, meet really huge image




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   29
3   Network Throughput in JavaScript – Take 3




       var img = new Image;
       img.onload = ld;
       image[i].start = +new Date;
       image[i].timer =
             setTimeout(function() {
                            image[i].expired=true
                        },
                        image[i].timeout);
       img.src=image[i].url;




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   30
3   Network Throughput in JavaScript – Take 3




    if(i>0) {
       image[i-1].end = +new Date;
       clearTimeout(image[i-1].timer);
    }




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   31
3   Network Throughput in JavaScript – Take 3




    if(i >= image.length
          || (i > 0 && image[i-1].expired)) {
       done();
    }




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   32
3 Measuring Network Throughput



                                    Are we done yet?




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   33
3 Measuring Network Throughput



                                    Are we done yet?
                                        sure...




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   33
3 Measuring Network Throughput



    Except network throughput is different every time you test it




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   34
Statistics to the Rescue




flickr/sophistechate/4264466015/
                 Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   35
3 Measuring Network Throughput



             The code for that is NOT gonna fit on a slide




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   36
But this is sort of what we see world-wide




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   37
And it’s different for different countries




   This is India




        Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   38
4     DNS



Boston #WebPerf Meetup / 2012-07-24    Abusing JavaScript to Measure Web Performance   39
4 Measuring DNS



                  time_with_dns − time_without_dns




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   40
4   Measuring DNS in JavaScript
    var t=[], dns, ip, hosts=[’http://hostname.com/’,
                               ’http://ip.ad.dr.ess/’];
    var ld = function() {
        t.push(+new Date);
        if(t.length > hosts.length)
          done();
        else {
          var img = new Image;
          img.onload = ld;
          img.src=hosts[t.length-1] + "/1x1.gif";
        }
    };
    var done = function() {
       ip=t[2]-t[1];
       dns=t[1]-t[0]-ip;
    };
    ld();
       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   41
4 Measuring DNS


    • What if the IP changes?
    • What if DNS is cached?
    • What if you map DNS based on geo location?




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   42
4   Wildcard DNS Entries




                               *.foo.com → IP address




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   43
4   Measuring DNS in JavaScript – take 2

    var base_url="http://*.foo.com/",
        timers = {}, gen_url="";

    function start() {
      var random = Math.random().toString(36),
          cache_bust = Math.random(),
          img = new Image();

        gen_url = base_url.replace(/*/, random);

        img.onload = A_loaded;

        timers.start = +new Date;
        img.src = gen_url + "image-l.gif?t=" + cache_bust;
    }

         Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   44
4   Measuring DNS in JavaScript – take 2



    function A_loaded() {
      var cache_bust = Math.random(),
          img = new Image();

        img.onload = B_loaded;

        timers.a_loaded = +new Date;
        img.src = gen_url + "image-l.gif?t=" + cache_bust;
    }


    I’ll let you figure out B_loaded



         Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   45
4 Measuring DNS



                   Full code in boomerang’s DNS plugin




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   46
5     IPv6



Boston #WebPerf Meetup / 2012-07-24    Abusing JavaScript to Measure Web Performance   47
5 Measuring IPv6 support and latency


    1   Try to load image from IPv6 host
           • If timeout or error, then no IPv6 support
           • If successful, then calculate latency and proceed
    2   Try to load image from hostname that resolves only to IPv6
        host
           • If timeout or error, then DNS server doesn’t support IPv6
           • If successful, calculate latency




        Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   48
5 Measuring IPv6 support and latency



                    Full code in boomerang’s IPv6 plugin
                        Note, only run this if you know IPv6 is supported by the client




      Boston #WebPerf Meetup / 2012-07-24          Abusing JavaScript to Measure Web Performance   49
6
                          Other Stuff



Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   50
6   Other Stuff We Measure




     • NavTiming – navtiming.js
     • navigation.connection.type – mobile.js
     • window.performance.memory – memory.js
     • Number of DOM nodes and byte size of HTML –
       memory.js




       Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   51
And we try to do it fast




Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   52
–
                                .done()



Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   53
Code/References




    • http://lognormal.github.com/boomerang/doc/
      (BSD Licensed)
    • www.lognormal.com




      Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   54
• Philip Tellis

•                           .com
• philip@lognormal.com
• @bluesmoon
• geek paranoid speedfreak
• http://bluesmoon.info/




    Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   55
Thank you
                       Ask me about a discount code




Boston #WebPerf Meetup / 2012-07-24   Abusing JavaScript to Measure Web Performance   56

Mais conteúdo relacionado

Mais procurados

Big Data Solutions for the Climate Community
Big Data Solutions for the Climate CommunityBig Data Solutions for the Climate Community
Big Data Solutions for the Climate CommunityEUDAT
 
Reorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondReorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondKazuho Oku
 
Promise of Push (HTTP/2 Web Performance)
Promise of Push (HTTP/2 Web Performance)Promise of Push (HTTP/2 Web Performance)
Promise of Push (HTTP/2 Web Performance)Colin Bendell
 
H2O - making the Web faster
H2O - making the Web fasterH2O - making the Web faster
H2O - making the Web fasterKazuho Oku
 
Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Alex Borysov
 
DVC: O'Reilly Artificial Intelligence Conference 2019 - New York
DVC: O'Reilly Artificial Intelligence Conference 2019 - New YorkDVC: O'Reilly Artificial Intelligence Conference 2019 - New York
DVC: O'Reilly Artificial Intelligence Conference 2019 - New YorkDmitry Petrov
 
Bulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless Spaces
Bulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless SpacesBulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless Spaces
Bulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless SpacesTokyo University of Science
 
"Enabling Googley microservices with gRPC" at JEEConf 2017
"Enabling Googley microservices with gRPC" at JEEConf 2017"Enabling Googley microservices with gRPC" at JEEConf 2017
"Enabling Googley microservices with gRPC" at JEEConf 2017Alex Borysov
 

Mais procurados (9)

Big Data Solutions for the Climate Community
Big Data Solutions for the Climate CommunityBig Data Solutions for the Climate Community
Big Data Solutions for the Climate Community
 
Reorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondReorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and Beyond
 
Promise of Push (HTTP/2 Web Performance)
Promise of Push (HTTP/2 Web Performance)Promise of Push (HTTP/2 Web Performance)
Promise of Push (HTTP/2 Web Performance)
 
H2O - making the Web faster
H2O - making the Web fasterH2O - making the Web faster
H2O - making the Web faster
 
Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.
 
DVC: O'Reilly Artificial Intelligence Conference 2019 - New York
DVC: O'Reilly Artificial Intelligence Conference 2019 - New YorkDVC: O'Reilly Artificial Intelligence Conference 2019 - New York
DVC: O'Reilly Artificial Intelligence Conference 2019 - New York
 
Bulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless Spaces
Bulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless SpacesBulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless Spaces
Bulk-n-Pick Method for One-to-Many Data Transfer in Dense Wireless Spaces
 
"Enabling Googley microservices with gRPC" at JEEConf 2017
"Enabling Googley microservices with gRPC" at JEEConf 2017"Enabling Googley microservices with gRPC" at JEEConf 2017
"Enabling Googley microservices with gRPC" at JEEConf 2017
 
Virtual Machines & Volunteer Computing
Virtual Machines & Volunteer ComputingVirtual Machines & Volunteer Computing
Virtual Machines & Volunteer Computing
 

Semelhante a Abusing JavaScript to Measure Web Performance

Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"Philip Tellis
 
Analysing network characteristics with JavaScript
Analysing network characteristics with JavaScriptAnalysing network characteristics with JavaScript
Analysing network characteristics with JavaScriptPhilip Tellis
 
Monitoring web application response times^lj a hybrid approach for windows
Monitoring web application response times^lj a hybrid approach for windowsMonitoring web application response times^lj a hybrid approach for windows
Monitoring web application response times^lj a hybrid approach for windowsMark Friedman
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScalePatrick Chanezon
 
Graphite, an introduction
Graphite, an introductionGraphite, an introduction
Graphite, an introductionjamesrwu
 
Mongodb beijingconf yottaa_3.3
Mongodb beijingconf yottaa_3.3Mongodb beijingconf yottaa_3.3
Mongodb beijingconf yottaa_3.3Yottaa
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAriya Hidayat
 
AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018
AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018
AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018Andy Davies
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterDoris Chen
 
Enabling Microservices @Orbitz - Velocity Conf 2015
Enabling Microservices @Orbitz - Velocity Conf 2015Enabling Microservices @Orbitz - Velocity Conf 2015
Enabling Microservices @Orbitz - Velocity Conf 2015Steve Hoffman
 
Monitoring web application response times, a new approach
Monitoring web application response times, a new approachMonitoring web application response times, a new approach
Monitoring web application response times, a new approachMark Friedman
 
Why is this ASP.NET web app running slowly?
Why is this ASP.NET web app running slowly?Why is this ASP.NET web app running slowly?
Why is this ASP.NET web app running slowly?Mark Friedman
 
Js foo - Sept 8 upload
Js foo - Sept 8 uploadJs foo - Sept 8 upload
Js foo - Sept 8 uploadDebnath Sinha
 
Introduction to JavaScript, Washington, DC February 2018
Introduction to JavaScript, Washington, DC February 2018Introduction to JavaScript, Washington, DC February 2018
Introduction to JavaScript, Washington, DC February 2018Thinkful
 
Web Performance Optimization @Develer
Web Performance Optimization @DevelerWeb Performance Optimization @Develer
Web Performance Optimization @DevelerMassimo Iacolare
 

Semelhante a Abusing JavaScript to Measure Web Performance (20)

Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
Abusing JavaScript to measure Web Performance, or, "how does boomerang work?"
 
Analysing network characteristics with JavaScript
Analysing network characteristics with JavaScriptAnalysing network characteristics with JavaScript
Analysing network characteristics with JavaScript
 
Web Leaps Forward
Web Leaps ForwardWeb Leaps Forward
Web Leaps Forward
 
Monitoring web application response times^lj a hybrid approach for windows
Monitoring web application response times^lj a hybrid approach for windowsMonitoring web application response times^lj a hybrid approach for windows
Monitoring web application response times^lj a hybrid approach for windows
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
 
Graphite, an introduction
Graphite, an introductionGraphite, an introduction
Graphite, an introduction
 
Keynote I
Keynote IKeynote I
Keynote I
 
Mongodb beijingconf yottaa_3.3
Mongodb beijingconf yottaa_3.3Mongodb beijingconf yottaa_3.3
Mongodb beijingconf yottaa_3.3
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
 
AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018
AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018
AB Testing, Ads and other 3rd party tags - London WebPerf - March 2018
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
Enabling Microservices @Orbitz - Velocity Conf 2015
Enabling Microservices @Orbitz - Velocity Conf 2015Enabling Microservices @Orbitz - Velocity Conf 2015
Enabling Microservices @Orbitz - Velocity Conf 2015
 
Monitoring web application response times, a new approach
Monitoring web application response times, a new approachMonitoring web application response times, a new approach
Monitoring web application response times, a new approach
 
Why is this ASP.NET web app running slowly?
Why is this ASP.NET web app running slowly?Why is this ASP.NET web app running slowly?
Why is this ASP.NET web app running slowly?
 
Using Embulk at Treasure Data
Using Embulk at Treasure DataUsing Embulk at Treasure Data
Using Embulk at Treasure Data
 
C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
 
Js foo - Sept 8 upload
Js foo - Sept 8 uploadJs foo - Sept 8 upload
Js foo - Sept 8 upload
 
Introduction to JavaScript, Washington, DC February 2018
Introduction to JavaScript, Washington, DC February 2018Introduction to JavaScript, Washington, DC February 2018
Introduction to JavaScript, Washington, DC February 2018
 
Web Performance Optimization @Develer
Web Performance Optimization @DevelerWeb Performance Optimization @Develer
Web Performance Optimization @Develer
 

Mais de Philip Tellis

Improving D3 Performance with CANVAS and other Hacks
Improving D3 Performance with CANVAS and other HacksImproving D3 Performance with CANVAS and other Hacks
Improving D3 Performance with CANVAS and other HacksPhilip Tellis
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonPhilip Tellis
 
Frontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou FurieuxFrontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou FurieuxPhilip Tellis
 
Frontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy PersonFrontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy PersonPhilip Tellis
 
Beyond Page Level Metrics
Beyond Page Level MetricsBeyond Page Level Metrics
Beyond Page Level MetricsPhilip Tellis
 
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...Philip Tellis
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonPhilip Tellis
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonPhilip Tellis
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonPhilip Tellis
 
RUM Distillation 101 -- Part I
RUM Distillation 101 -- Part IRUM Distillation 101 -- Part I
RUM Distillation 101 -- Part IPhilip Tellis
 
Improving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFramesImproving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFramesPhilip Tellis
 
The Statistics of Web Performance Analysis
The Statistics of Web Performance AnalysisThe Statistics of Web Performance Analysis
The Statistics of Web Performance AnalysisPhilip Tellis
 
A Node.JS bag of goodies for analyzing Web Traffic
A Node.JS bag of goodies for analyzing Web TrafficA Node.JS bag of goodies for analyzing Web Traffic
A Node.JS bag of goodies for analyzing Web TrafficPhilip Tellis
 
Boomerang: How fast do users think your site is?
Boomerang: How fast do users think your site is?Boomerang: How fast do users think your site is?
Boomerang: How fast do users think your site is?Philip Tellis
 
Boomerang at FOSS.IN/2010
Boomerang at FOSS.IN/2010Boomerang at FOSS.IN/2010
Boomerang at FOSS.IN/2010Philip Tellis
 
Measuring the web with Boomerang (YUIConf 2010)
Measuring the web with Boomerang (YUIConf 2010)Measuring the web with Boomerang (YUIConf 2010)
Measuring the web with Boomerang (YUIConf 2010)Philip Tellis
 

Mais de Philip Tellis (20)

Improving D3 Performance with CANVAS and other Hacks
Improving D3 Performance with CANVAS and other HacksImproving D3 Performance with CANVAS and other Hacks
Improving D3 Performance with CANVAS and other Hacks
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
Frontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou FurieuxFrontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou Furieux
 
Frontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy PersonFrontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy Person
 
Beyond Page Level Metrics
Beyond Page Level MetricsBeyond Page Level Metrics
Beyond Page Level Metrics
 
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
Frontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy PersonFrontend Performance: Beginner to Expert to Crazy Person
Frontend Performance: Beginner to Expert to Crazy Person
 
mmm... beacons
mmm... beaconsmmm... beacons
mmm... beacons
 
RUM Distillation 101 -- Part I
RUM Distillation 101 -- Part IRUM Distillation 101 -- Part I
RUM Distillation 101 -- Part I
 
Improving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFramesImproving 3rd Party Script Performance With IFrames
Improving 3rd Party Script Performance With IFrames
 
Extending Boomerang
Extending BoomerangExtending Boomerang
Extending Boomerang
 
The Statistics of Web Performance Analysis
The Statistics of Web Performance AnalysisThe Statistics of Web Performance Analysis
The Statistics of Web Performance Analysis
 
Rum for Breakfast
Rum for BreakfastRum for Breakfast
Rum for Breakfast
 
A Node.JS bag of goodies for analyzing Web Traffic
A Node.JS bag of goodies for analyzing Web TrafficA Node.JS bag of goodies for analyzing Web Traffic
A Node.JS bag of goodies for analyzing Web Traffic
 
Input sanitization
Input sanitizationInput sanitization
Input sanitization
 
Boomerang: How fast do users think your site is?
Boomerang: How fast do users think your site is?Boomerang: How fast do users think your site is?
Boomerang: How fast do users think your site is?
 
Boomerang at FOSS.IN/2010
Boomerang at FOSS.IN/2010Boomerang at FOSS.IN/2010
Boomerang at FOSS.IN/2010
 
Measuring the web with Boomerang (YUIConf 2010)
Measuring the web with Boomerang (YUIConf 2010)Measuring the web with Boomerang (YUIConf 2010)
Measuring the web with Boomerang (YUIConf 2010)
 

Último

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Último (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

Abusing JavaScript to Measure Web Performance

  • 1. • Philip Tellis • .com • philip@lognormal.com • @bluesmoon • geek paranoid speedfreak • http://bluesmoon.info/ Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 1
  • 2. I <3 JavaScript Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 2
  • 3. So much that I wore Mustache socks to my wedding Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 3
  • 4. I’m also a Web Speedfreak Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 4
  • 5. We measure real user website performance Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 5
  • 6. This talk is (mostly) about how we abuse JavaScript to do it Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 6
  • 7. Abusing JavaScript to Measure Web Performance Philip Tellis / philip@lognormal.com Boston #WebPerf Meetup / 2012-07-24 Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 7
  • 8. First, a note about the code Note that in the code that follows, + new Date is equivalent to new Date().getTime() Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 8
  • 9. 1 Latency Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 9
  • 10. 1 Blinking Lights It takes about 16ms for light to get from SF to Boston (24ms through fibre) ... Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 10
  • 11. 1 Blinking Lights It takes about 16ms for light to get from SF to Boston (24ms through fibre) Though it takes about 100ms to ping... why? Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 10
  • 12. 1 HTTP Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 11
  • 13. So to measure latency, we need to send 1 packet each way, and time it Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 12
  • 14. 1 Network latency in JavaScript var ts, rtt, img = new Image; img.onload=function() { rtt=(+new Date - ts) }; ts = +new Date; img.src="/1x1.gif"; Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 13
  • 15. 1 Notes • 1x1 gif is 35 bytes • including HTTP headers, is smaller than a TCP packet • Fires onload on all browsers • 0 byte image fires onerror • which is indistinguishable from network error Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 14
  • 16. 2 TCP handshake Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 15
  • 17. 2 ACK-ACK-ACK Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 16
  • 18. 2 Connection: keep-alive Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 17
  • 19. 2 Network latency & TCP handshake in JavaScript var t=[], tcp, rtt; var ld = function() { t.push(+new Date); if(t.length > 2) // run 2 times done(); else { var img = new Image; img.onload = ld; img.src="/1x1.gif?" + Math.random() + ’=’ + new Date; } }; var done = function() { rtt=t[2]-t[1]; tcp=t[1]-t[0]-rtt; }; ld(); Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 18
  • 20. Notice that we’ve ignored DNS lookup time here... how would you measure it? Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 19
  • 21. Network Throughput 3 Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 20
  • 22. 3 Measuring Network Throughput data_length download_time Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 21
  • 23. Should you fly a 747 or a 737? • A 747 seats 400+ passengers • A 737 seats about 150 • Both take about the same time to fly from SFO to BOS • A 747 takes longer to load and unload The best selling aircraft to date is the 737 Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 22
  • 24. 3 Network Throughput in JavaScript // Assume global object // image={ url: ..., size: ... } var ts, rtt, bw, img = new Image; img.onload=function() { rtt=(+new Date - ts); bw = image.size*1000/rtt; // rtt is in ms }; ts = +new Date; img.src=image.url; Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 23
  • 25. 3 Measuring Network Throughput If it were that simple, I wouldn’t be doing this talk. Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 24
  • 26. 3 TCP Slow Start Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 25
  • 27. 3 Measuring Network Throughput So to make the best use of bandwidth, we need resources that fit in a TCP window Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 26
  • 28. 3 There is no single size that will tax all available networks http://www.yuiblog.com/blog/2010/04/08/analyzing-bandwidth-and-latency/ Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 27
  • 29. 3 Network Throughput in JavaScript – Take 2 // image object is now an array of multiple images var i=0; var ld = function() { if(i>0) image[i-1].end = +new Date; if(i >= image.length) done(); else { var img = new Image; img.onload = ld; image[i].start = +new Date; img.src=image[i].url; } i++; }; Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 28
  • 30. 3 Measuring Network Throughput Slow network connection, meet really huge image Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 29
  • 31. 3 Network Throughput in JavaScript – Take 3 var img = new Image; img.onload = ld; image[i].start = +new Date; image[i].timer = setTimeout(function() { image[i].expired=true }, image[i].timeout); img.src=image[i].url; Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 30
  • 32. 3 Network Throughput in JavaScript – Take 3 if(i>0) { image[i-1].end = +new Date; clearTimeout(image[i-1].timer); } Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 31
  • 33. 3 Network Throughput in JavaScript – Take 3 if(i >= image.length || (i > 0 && image[i-1].expired)) { done(); } Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 32
  • 34. 3 Measuring Network Throughput Are we done yet? Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 33
  • 35. 3 Measuring Network Throughput Are we done yet? sure... Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 33
  • 36. 3 Measuring Network Throughput Except network throughput is different every time you test it Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 34
  • 37. Statistics to the Rescue flickr/sophistechate/4264466015/ Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 35
  • 38. 3 Measuring Network Throughput The code for that is NOT gonna fit on a slide Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 36
  • 39. But this is sort of what we see world-wide Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 37
  • 40. And it’s different for different countries This is India Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 38
  • 41. 4 DNS Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 39
  • 42. 4 Measuring DNS time_with_dns − time_without_dns Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 40
  • 43. 4 Measuring DNS in JavaScript var t=[], dns, ip, hosts=[’http://hostname.com/’, ’http://ip.ad.dr.ess/’]; var ld = function() { t.push(+new Date); if(t.length > hosts.length) done(); else { var img = new Image; img.onload = ld; img.src=hosts[t.length-1] + "/1x1.gif"; } }; var done = function() { ip=t[2]-t[1]; dns=t[1]-t[0]-ip; }; ld(); Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 41
  • 44. 4 Measuring DNS • What if the IP changes? • What if DNS is cached? • What if you map DNS based on geo location? Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 42
  • 45. 4 Wildcard DNS Entries *.foo.com → IP address Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 43
  • 46. 4 Measuring DNS in JavaScript – take 2 var base_url="http://*.foo.com/", timers = {}, gen_url=""; function start() { var random = Math.random().toString(36), cache_bust = Math.random(), img = new Image(); gen_url = base_url.replace(/*/, random); img.onload = A_loaded; timers.start = +new Date; img.src = gen_url + "image-l.gif?t=" + cache_bust; } Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 44
  • 47. 4 Measuring DNS in JavaScript – take 2 function A_loaded() { var cache_bust = Math.random(), img = new Image(); img.onload = B_loaded; timers.a_loaded = +new Date; img.src = gen_url + "image-l.gif?t=" + cache_bust; } I’ll let you figure out B_loaded Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 45
  • 48. 4 Measuring DNS Full code in boomerang’s DNS plugin Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 46
  • 49. 5 IPv6 Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 47
  • 50. 5 Measuring IPv6 support and latency 1 Try to load image from IPv6 host • If timeout or error, then no IPv6 support • If successful, then calculate latency and proceed 2 Try to load image from hostname that resolves only to IPv6 host • If timeout or error, then DNS server doesn’t support IPv6 • If successful, calculate latency Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 48
  • 51. 5 Measuring IPv6 support and latency Full code in boomerang’s IPv6 plugin Note, only run this if you know IPv6 is supported by the client Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 49
  • 52. 6 Other Stuff Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 50
  • 53. 6 Other Stuff We Measure • NavTiming – navtiming.js • navigation.connection.type – mobile.js • window.performance.memory – memory.js • Number of DOM nodes and byte size of HTML – memory.js Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 51
  • 54. And we try to do it fast Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 52
  • 55. .done() Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 53
  • 56. Code/References • http://lognormal.github.com/boomerang/doc/ (BSD Licensed) • www.lognormal.com Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 54
  • 57. • Philip Tellis • .com • philip@lognormal.com • @bluesmoon • geek paranoid speedfreak • http://bluesmoon.info/ Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 55
  • 58. Thank you Ask me about a discount code Boston #WebPerf Meetup / 2012-07-24 Abusing JavaScript to Measure Web Performance 56