SlideShare uma empresa Scribd logo
1 de 70
(c) 2010 Facebook, Inc. or its licensors. "Facebook" is a registered trademark of Facebook, Inc.. All rights reserved. 1.0
Ajaxifying, Caching and Pipelining
Facebook Website

                                 Changhao
                                 Jiang
 The Velocity Conference
 Dec 7th, 2010, Beijing, China
The beginning - 2004
Today
Mission
Give people the power to
share and make the world
more open and connected
500M Users
             500
              M
Today’s reality
Average hours per month per user!
Site speed is critical to Facebook!
What do we measure?




                      Facebook




                        CDN
What do we measure?
                                            server time



client/render time
                                    Facebook
                     network time




                                      CDN
Time-to-Interact (TTI)
Time-to-Interact (TTI)
Time-to-Interact (TTI)
Three frontend optimizations at Facebook


 Quickling    transparently ajaxifies the whole web site

 PageCache    caches user-visited pages in browser

 BigPipe       pipelines Facebook website
Quickling: Ajaxify the Facebook site
Motivation: remove redundant work
Motivation: remove redundant work
Remove redundant work via Ajax
              Full page load


                   Page 1          Page 2          Page 3          Page 4

Use session      load   unload   load   unload   load   unload   load   unload




                 Ajax call

                   Page 1          Page 2          Page 3          Page 4


Use session      load                                                   unload
How Quickling works?
                                       1. User clicks a link or back/forward button

                                               2. Quickling sends an ajax to server

                                                      3. Response arrives




4. Quickling blanks the content area

        5. Download javascript/CSS

                6. Show new content
Implementation details
•  Link Controller

•  HistoryManager

•  Bootloader

•  Busy Indicator

•  CSS Unloading

•  Permanent link support

•  Resetting timer functions
User perceived latency (TTI) reduction
3000

2500

2000

1500                                                        Full pageload
                                                            Quickling
1000

 500

   0
       /home.php   /profile.php   /photo.php   /album.php

           10% ~ 30% reduction in TTI
Server page generation time reduction
2000
1800
1600
1400
1200
1000                                                        Full pageload
 800                                                        Quickling
 600
 400
 200
   0
       /home.php   /profile.php   /photo.php   /album.php

Quickling requests are 20% ~ 30%
45% of page hits are Quickling requests




                                  Quickling

                                  Full pageload
Quickling conclusion:



•  Reduce user perceived latency by more than
   10%

•  Save 10% of Facebook’s data center cost!
PageCache: Cache visited pages at client side
Motivation – temporal locality

•  Some pages are likely to be revisited soon
  ▪    E.g. home page (re)visited every 3 page hits:
               -> profile -> photo ->       -> notes ->   -> photo ->
       photo

•  Cache them!
How PageCache works?
                                       1. User clicks a link or back button

                                               2. Quickling sends ajax to server
                                                  Find Page in the cache

                                                       3. Response arrives

                                                                3.5 Save response in cache



4. Quickling blanks the content area

        5. Download javascript/CSS

                6. Show new content
Challenges


•  Real time updates
  ▪    Page content needs to be as fresh as possible

•  Cache consistency
  ▪    Cached page should be consistent after state-modifying operations
Issue(1): Incremental updates




    Cached version              Restored version
Issue(1): Incremental updates
Poll server for incremental updates via AJAX calls
 ▪    Provides an ‘onpagecacheRegister’ API to developers:
      ▪    Invoked when a page is restored from cache.
      ▪    Used to send AJAX to server for incremental updates, refresh ads, etc.
      ▪    Blank the content area before incremental updates arrive to avoid flash of
           stale contents.
Issue(2): In-page writes




      Cached version       Restored version
Issue(2): In-page writes
Record and replay
 ▪    Automatically record all state-changing operations in a cached page
      ▪    All AJAX calls using ‘POST’ method, or those explicitly specified
           ‘replayable’ will be added to cached content.
 ▪    Automatically replay those operations when cached page is restored.
      ▪    Cached AJAX handler callback functions already contain all the
           contextual information about the recorded operations due to JavaScript
           closure.
Issue(3): Cross-page writes




  Cached version   State-changing op   Restored version
Issue(3): Cross-page writes
Server side invalidation
 ▪    Instrument server-side database API, whenever a write operation is
      detected, send a signal to the client to invalidate the cache.
 ▪    The signal (a.k.a. cache invalidation message) contain information
      about what persistent data has changed.
 ▪    Upon receiving cache messages, the client side can flush the whole
      cache or refresh only those affected page components via AJAX.
User perceived latency (TTI) redunction
     2500



     2000



     1500                   Full pageload
                            Quickling
     1000                   PageCache

      500




   10x faster in user perceived latency
        0
Server cost redunction

           20%




    ~20% savings on page hits to home page
PageCache conclusion:



•  10X speedup in user perceived speed!

•  Save 2% of Facebook’s data center cost!
BigPipe: pipeline Facebook website
Facebook page
User perceived latency




Page generation
                  Network Latency   Page rendering (in browser)
  (in server)
Pagelets
User perceived latency




                                                   Pagelet 1:
Page generation
                  Network Latency   Page rendering (in browser)
  (in server)

                                                   Pagelet 2:


                                                   Pagelet 3:
TTI improvement
                                     Traditional model     BigPipe
                2500

                2000
  Millisecond




                1500

                1000

                 500

                   0
                       Firefox 3.6         IE 8          Safari 4.0   Chrome 4.1

  2X improvement in user perceived latency for almost all browsers.
BigPipe first response
                 <html>
                 <head> <script src=“<big pipe js>” />…</
                 head>
                 <body>
                 …
                 <div id=“left_column”>
                 <div id=“pagelet_navigation”></div>
                 </div>
                 <div id=“middle_column”>
                  <div id=“pagelet_composer></div>
                  </div>
                 …
Pagelet response 1

                 <script type=“text/javascript”>
                   big_pipe.onPageletArrive({
                      “id” : “pagelet_navigation”,
                      “css” : [ <list of css resources>],
                      “js” : [ <list of JavaScript resources>],
                      “content” : <html>
                      “onload”: [JavaScript init code]
                      …
                 });
                 </script>
Pagelet response 2

                 <script type=“text/javascript”>
                   big_pipe.onPageletArrive({
                      “id” : “pagelet_composer”,
                      “css” : [ <list of css resources>],
                      “js” : [ <list of JavaScript resources>],
                      “content” : <html>
                      “onload”: [JavaScript init code]
                      …
                 });
                 </script>
Pagelet example
      class AdsPagelet extends PageletResponse
     {
         public function init () {
           // initialize pagelet
         }

         public function prepare() {
           // data fetching
         }

         public render() {
           // generate pagelet response.
         }
     }
Pagelet programming model
•  Self contained
 ▪    HTML, JavaScript, CSS, onloadRegister

•  Advanced features:
      ▪    Pagelet hierarchy
      ▪    Phased rendering
      ▪    Cross-pagelet dependencies
              ▪    data dependency
              ▪    display dependency
              ▪    JavaScript dependency
BigPipe programming model
          // Step 1: create BigPipe instance

         $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE);

          // Step 2: Specify page layout and pagelet place holders.

         $big_pipe->setPage(
             ‘<div id=“left_column”>
                <div id=“pagelet_navigation”></div>
               </div>
               <div id=“middle_column”>
                 <div id=“paglet_composer”></div>
                 <div id=“pagelet_stream”></div>
               </div>’);

         // Step 3: add pagelets to the pipe

         $big_pipe->addPagelet(
             new UIPagelet()
                   ->setSrc(‘/pagelet/composer.php’)
                   ->setWrapperId(‘pagelet_composer’));
         …

         // Step 4: generate pagelets flush them out.

         echo $big_pipe->render();
BigPipe programming model
                 // Step 1: create BigPipe instance

                 $big_pipe = BigPipe::getInstance
                 (BigPipeType::PIPELINE);
                 // Step 2: Specify page layout and pagelet place holders.

                 $big_pipe->setPage(
                     ‘<div id=“left_column”>
  // Step 1: create BigPipe instance
                        <div id=“pagelet_navigation”></div>
                       </div>
                       <div id=“middle_column”>
                         <div id=“paglet_composer”></div>
  $big_pipe = BigPipe::getInstance
                         <div id=“pagelet_stream”></div>
                       </div>’);
  (BigPipeType::PIPELINE);the pipe
              // Step 3: add pagelets to

                 $big_pipe->addPagelet(
                     new UIPagelet()
                           ->setSrc(‘/pagelet/composer.php’)
                           ->setWrapperId(‘pagelet_composer’));
                 …

                 // Step 4: generate pagelets flush them out.

                 echo $big_pipe->render();
BigPipe programming model
                  // Step 1: create BigPipe instance

                  $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE);
   // Step 2: Specify page layout and pagelet place
   holders. // Step 2: Specify page layout and pagelet place holders.
                  $big_pipe->setPage(
                      ‘<div id=“left_column”>
   $big_pipe->setPage(   <div id=“pagelet_navigation”></div>
                        </div>
       ‘<div id=“left_column”>
                        <div id=“middle_column”>
                          <div id=“paglet_composer”></div>
          <div id=“pagelet_navigation”></div>
                          <div id=“pagelet_stream”></div>
                        </div>’);
         </div>// Step 3: add pagelets to the pipe
         <div id=“middle_column”>
               $big_pipe->addPagelet(
                    new UIPagelet()
           <div id=“paglet_composer”></div>
                           ->setSrc(‘/pagelet/composer.php’)
                           ->setWrapperId(‘pagelet_composer’));
           <div id=“pagelet_stream”></div>
               …

         </div>’); 4: generate pagelets flush them out.
               // Step

                  echo $big_pipe->render();
BigPipe programming model
           // Step 1: create BigPipe instance

           $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE);

           // Step 2: Specify page layout and pagelet place holders.
      // Step 3: add pagelets to the pipe
            $big_pipe->setPage(
               ‘<div id=“left_column”>
                  <div id=“pagelet_navigation”></div>
      $big_pipe->addPagelet(
                 </div>
                 <div id=“middle_column”>
          new UIPagelet()
                   <div id=“paglet_composer”></div>
                   <div id=“pagelet_stream”></div>
           ->setSrc(‘/pagelet/composer.php’)
                 </div>’);

           ->setWrapperId(‘pagelet_composer’));
           // Step 3: add pagelets to the pipe


      … $big_pipe->addPagelet(
                new UIPagelet()
                      ->setSrc(‘/pagelet/composer.php’)
                      ->setWrapperId(‘pagelet_composer’));
           …

           // Step 4: generate pagelets flush them out.

           echo $big_pipe->render();
BigPipe programming model
            // Step 1: create BigPipe instance

            $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE);

            // Step 2: Specify page layout and pagelet place holders.

            $big_pipe->setPage(
                ‘<div id=“left_column”>
                   <div id=“pagelet_navigation”></div>
      // Step 4: generate pagelets flush them out.
                  </div>
                  <div id=“middle_column”>
                    <div id=“paglet_composer”></div>
                    <div id=“pagelet_stream”></div>
      echo $big_pipe->render();
                  </div>’);

            // Step 3: add pagelets to the pipe

            $big_pipe->addPagelet(
                new UIPagelet()
                      ->setSrc(‘/pagelet/composer.php’)
                      ->setWrapperId(‘pagelet_composer’));
            …

            // Step 4: generate pagelets flush them out.

            echo $big_pipe->render();
BigPipe generation modes

•  Single flush mode
 ▪    Support search-engine crawlers
 ▪    Support clients without JavaScript

•  Pipeline mode
 ▪    Generate and flush pagelets sequentially (default mode)

•  Parallel mode
 ▪    Generate pagelets in parallel and flush them out-of-order
BigPipe programming model

•  Encapsulation
 ▪    Hide implementation details

•  Intuitive
 ▪    Easy to understand mental model for developers

•  Flexible
 ▪    Different modes good for different use case.
BigPipe advanced features

•  AjaxPipe
 ▪    Use iframe to pipeline Ajax response
 ▪    Used by Facebook home page’s dashboards (photo, groups, etc)

•  WidgetPipe
 ▪    Pipeline multiple widgets (“like” button) on third party websites
Thank you!

Mais conteúdo relacionado

Mais procurados

S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyLuciano Resende
 
distributing over the web
distributing over the webdistributing over the web
distributing over the webNicola Baldi
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1James Pearce
 
Web前端性能分析工具导引
Web前端性能分析工具导引Web前端性能分析工具导引
Web前端性能分析工具导引冰 郭
 
Analysis of Google Page Speed Insight
Analysis of Google Page Speed InsightAnalysis of Google Page Speed Insight
Analysis of Google Page Speed InsightSarvesh Sonawane
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web PerformanceEric ShangKuan
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsBastian Hofmann
 
[cssdevconf] Adaptive Images in Responsive Web Design
[cssdevconf] Adaptive Images in Responsive Web Design[cssdevconf] Adaptive Images in Responsive Web Design
[cssdevconf] Adaptive Images in Responsive Web DesignChristopher Schmitt
 
Back to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOABack to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOASage Computing Services
 
08 session-tracking
08 session-tracking08 session-tracking
08 session-trackingsnopteck
 
Rest Security with JAX-RS
Rest Security with JAX-RSRest Security with JAX-RS
Rest Security with JAX-RSFrank Kim
 
The mobile-web-at-a-snails-pace
The mobile-web-at-a-snails-paceThe mobile-web-at-a-snails-pace
The mobile-web-at-a-snails-paceMarcel Kalveram
 
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011Peter Moskovits
 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesDeeptiJava
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax ApplicationsSiarhei Barysiuk
 
Creating Semantic Mashups Bridging Web 2 0 And The Semantic Web Presentation 1
Creating Semantic Mashups  Bridging Web 2 0 And The Semantic Web Presentation 1Creating Semantic Mashups  Bridging Web 2 0 And The Semantic Web Presentation 1
Creating Semantic Mashups Bridging Web 2 0 And The Semantic Web Presentation 1jward5519
 

Mais procurados (17)

S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
 
distributing over the web
distributing over the webdistributing over the web
distributing over the web
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
 
Web前端性能分析工具导引
Web前端性能分析工具导引Web前端性能分析工具导引
Web前端性能分析工具导引
 
Analysis of Google Page Speed Insight
Analysis of Google Page Speed InsightAnalysis of Google Page Speed Insight
Analysis of Google Page Speed Insight
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web Performance
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
[cssdevconf] Adaptive Images in Responsive Web Design
[cssdevconf] Adaptive Images in Responsive Web Design[cssdevconf] Adaptive Images in Responsive Web Design
[cssdevconf] Adaptive Images in Responsive Web Design
 
Back to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOABack to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOA
 
08 session-tracking
08 session-tracking08 session-tracking
08 session-tracking
 
Rest Security with JAX-RS
Rest Security with JAX-RSRest Security with JAX-RS
Rest Security with JAX-RS
 
The mobile-web-at-a-snails-pace
The mobile-web-at-a-snails-paceThe mobile-web-at-a-snails-pace
The mobile-web-at-a-snails-pace
 
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
 
Nick harris-sic-2011
Nick harris-sic-2011Nick harris-sic-2011
Nick harris-sic-2011
 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status Codes
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
Creating Semantic Mashups Bridging Web 2 0 And The Semantic Web Presentation 1
Creating Semantic Mashups  Bridging Web 2 0 And The Semantic Web Presentation 1Creating Semantic Mashups  Bridging Web 2 0 And The Semantic Web Presentation 1
Creating Semantic Mashups Bridging Web 2 0 And The Semantic Web Presentation 1
 

Semelhante a Changhao jiang facebook

Chanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheChanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheAjax Experience 2009
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuAppUniverz Org
 
Enough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasEnough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasKubide
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!Nicholas Zakas
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! HomepageNicholas Zakas
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo  homepage presentationBuilding performance into the new yahoo  homepage presentation
Building performance into the new yahoo homepage presentationmasudakram
 
Hidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical StudyHidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical StudySALT Lab @ UBC
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Timothy Fisher
 
High performance website
High performance websiteHigh performance website
High performance websiteChamnap Chhorn
 
High Performance Websites
High Performance WebsitesHigh Performance Websites
High Performance WebsitesParham
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutionswoutervugt
 
WebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer ConferenceWebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer ConferenceAllFacebook.de
 
Template tuning for high performance
Template tuning for high performanceTemplate tuning for high performance
Template tuning for high performanceChris Davenport
 
Build Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićBuild Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićMeetMagentoNY2014
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站George Ang
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsSarvesh Kushwaha
 
Web performance optimization for modern web applications
Web performance optimization for modern web applicationsWeb performance optimization for modern web applications
Web performance optimization for modern web applicationsChris Love
 

Semelhante a Changhao jiang facebook (20)

Chanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheChanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling Pagecache
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
Cache is King
Cache is KingCache is King
Cache is King
 
Enough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasEnough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas Zakas
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo  homepage presentationBuilding performance into the new yahoo  homepage presentation
Building performance into the new yahoo homepage presentation
 
Hidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical StudyHidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical Study
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
High performance website
High performance websiteHigh performance website
High performance website
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
High Performance Websites
High Performance WebsitesHigh Performance Websites
High Performance Websites
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutions
 
Making the web faster
Making the web fasterMaking the web faster
Making the web faster
 
WebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer ConferenceWebApp / SPA @ AllFacebook Developer Conference
WebApp / SPA @ AllFacebook Developer Conference
 
Template tuning for high performance
Template tuning for high performanceTemplate tuning for high performance
Template tuning for high performance
 
Build Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićBuild Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje Jurišić
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
Web performance optimization for modern web applications
Web performance optimization for modern web applicationsWeb performance optimization for modern web applications
Web performance optimization for modern web applications
 

Último

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Changhao jiang facebook

  • 1. (c) 2010 Facebook, Inc. or its licensors. "Facebook" is a registered trademark of Facebook, Inc.. All rights reserved. 1.0
  • 2. Ajaxifying, Caching and Pipelining Facebook Website Changhao Jiang The Velocity Conference Dec 7th, 2010, Beijing, China
  • 5. Mission Give people the power to share and make the world more open and connected
  • 6. 500M Users 500 M
  • 8. Average hours per month per user!
  • 9. Site speed is critical to Facebook!
  • 10. What do we measure? Facebook CDN
  • 11. What do we measure? server time client/render time Facebook network time CDN
  • 15. Three frontend optimizations at Facebook Quickling transparently ajaxifies the whole web site PageCache caches user-visited pages in browser BigPipe pipelines Facebook website
  • 16. Quickling: Ajaxify the Facebook site
  • 19. Remove redundant work via Ajax Full page load Page 1 Page 2 Page 3 Page 4 Use session load unload load unload load unload load unload Ajax call Page 1 Page 2 Page 3 Page 4 Use session load unload
  • 20. How Quickling works? 1. User clicks a link or back/forward button 2. Quickling sends an ajax to server 3. Response arrives 4. Quickling blanks the content area 5. Download javascript/CSS 6. Show new content
  • 21. Implementation details •  Link Controller •  HistoryManager •  Bootloader •  Busy Indicator •  CSS Unloading •  Permanent link support •  Resetting timer functions
  • 22. User perceived latency (TTI) reduction 3000 2500 2000 1500 Full pageload Quickling 1000 500 0 /home.php /profile.php /photo.php /album.php 10% ~ 30% reduction in TTI
  • 23. Server page generation time reduction 2000 1800 1600 1400 1200 1000 Full pageload 800 Quickling 600 400 200 0 /home.php /profile.php /photo.php /album.php Quickling requests are 20% ~ 30%
  • 24. 45% of page hits are Quickling requests Quickling Full pageload
  • 25. Quickling conclusion: •  Reduce user perceived latency by more than 10% •  Save 10% of Facebook’s data center cost!
  • 26. PageCache: Cache visited pages at client side
  • 27. Motivation – temporal locality •  Some pages are likely to be revisited soon ▪  E.g. home page (re)visited every 3 page hits: -> profile -> photo -> -> notes -> -> photo -> photo •  Cache them!
  • 28. How PageCache works? 1. User clicks a link or back button 2. Quickling sends ajax to server Find Page in the cache 3. Response arrives 3.5 Save response in cache 4. Quickling blanks the content area 5. Download javascript/CSS 6. Show new content
  • 29. Challenges •  Real time updates ▪  Page content needs to be as fresh as possible •  Cache consistency ▪  Cached page should be consistent after state-modifying operations
  • 30. Issue(1): Incremental updates Cached version Restored version
  • 31. Issue(1): Incremental updates Poll server for incremental updates via AJAX calls ▪  Provides an ‘onpagecacheRegister’ API to developers: ▪  Invoked when a page is restored from cache. ▪  Used to send AJAX to server for incremental updates, refresh ads, etc. ▪  Blank the content area before incremental updates arrive to avoid flash of stale contents.
  • 32. Issue(2): In-page writes Cached version Restored version
  • 33. Issue(2): In-page writes Record and replay ▪  Automatically record all state-changing operations in a cached page ▪  All AJAX calls using ‘POST’ method, or those explicitly specified ‘replayable’ will be added to cached content. ▪  Automatically replay those operations when cached page is restored. ▪  Cached AJAX handler callback functions already contain all the contextual information about the recorded operations due to JavaScript closure.
  • 34. Issue(3): Cross-page writes Cached version State-changing op Restored version
  • 35. Issue(3): Cross-page writes Server side invalidation ▪  Instrument server-side database API, whenever a write operation is detected, send a signal to the client to invalidate the cache. ▪  The signal (a.k.a. cache invalidation message) contain information about what persistent data has changed. ▪  Upon receiving cache messages, the client side can flush the whole cache or refresh only those affected page components via AJAX.
  • 36. User perceived latency (TTI) redunction 2500 2000 1500 Full pageload Quickling 1000 PageCache 500 10x faster in user perceived latency 0
  • 37. Server cost redunction 20% ~20% savings on page hits to home page
  • 38. PageCache conclusion: •  10X speedup in user perceived speed! •  Save 2% of Facebook’s data center cost!
  • 41. User perceived latency Page generation Network Latency Page rendering (in browser) (in server)
  • 43. User perceived latency Pagelet 1: Page generation Network Latency Page rendering (in browser) (in server) Pagelet 2: Pagelet 3:
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56. TTI improvement Traditional model BigPipe 2500 2000 Millisecond 1500 1000 500 0 Firefox 3.6 IE 8 Safari 4.0 Chrome 4.1 2X improvement in user perceived latency for almost all browsers.
  • 57. BigPipe first response <html> <head> <script src=“<big pipe js>” />…</ head> <body> … <div id=“left_column”> <div id=“pagelet_navigation”></div> </div> <div id=“middle_column”> <div id=“pagelet_composer></div> </div> …
  • 58. Pagelet response 1 <script type=“text/javascript”> big_pipe.onPageletArrive({ “id” : “pagelet_navigation”, “css” : [ <list of css resources>], “js” : [ <list of JavaScript resources>], “content” : <html> “onload”: [JavaScript init code] … }); </script>
  • 59. Pagelet response 2 <script type=“text/javascript”> big_pipe.onPageletArrive({ “id” : “pagelet_composer”, “css” : [ <list of css resources>], “js” : [ <list of JavaScript resources>], “content” : <html> “onload”: [JavaScript init code] … }); </script>
  • 60. Pagelet example class AdsPagelet extends PageletResponse { public function init () { // initialize pagelet } public function prepare() { // data fetching } public render() { // generate pagelet response. } }
  • 61. Pagelet programming model •  Self contained ▪  HTML, JavaScript, CSS, onloadRegister •  Advanced features: ▪  Pagelet hierarchy ▪  Phased rendering ▪  Cross-pagelet dependencies ▪  data dependency ▪  display dependency ▪  JavaScript dependency
  • 62. BigPipe programming model // Step 1: create BigPipe instance $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE); // Step 2: Specify page layout and pagelet place holders. $big_pipe->setPage( ‘<div id=“left_column”> <div id=“pagelet_navigation”></div> </div> <div id=“middle_column”> <div id=“paglet_composer”></div> <div id=“pagelet_stream”></div> </div>’); // Step 3: add pagelets to the pipe $big_pipe->addPagelet( new UIPagelet() ->setSrc(‘/pagelet/composer.php’) ->setWrapperId(‘pagelet_composer’)); … // Step 4: generate pagelets flush them out. echo $big_pipe->render();
  • 63. BigPipe programming model // Step 1: create BigPipe instance $big_pipe = BigPipe::getInstance (BigPipeType::PIPELINE); // Step 2: Specify page layout and pagelet place holders. $big_pipe->setPage( ‘<div id=“left_column”> // Step 1: create BigPipe instance <div id=“pagelet_navigation”></div> </div> <div id=“middle_column”> <div id=“paglet_composer”></div> $big_pipe = BigPipe::getInstance <div id=“pagelet_stream”></div> </div>’); (BigPipeType::PIPELINE);the pipe // Step 3: add pagelets to $big_pipe->addPagelet( new UIPagelet() ->setSrc(‘/pagelet/composer.php’) ->setWrapperId(‘pagelet_composer’)); … // Step 4: generate pagelets flush them out. echo $big_pipe->render();
  • 64. BigPipe programming model // Step 1: create BigPipe instance $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE); // Step 2: Specify page layout and pagelet place holders. // Step 2: Specify page layout and pagelet place holders. $big_pipe->setPage( ‘<div id=“left_column”> $big_pipe->setPage( <div id=“pagelet_navigation”></div> </div> ‘<div id=“left_column”> <div id=“middle_column”> <div id=“paglet_composer”></div> <div id=“pagelet_navigation”></div> <div id=“pagelet_stream”></div> </div>’); </div>// Step 3: add pagelets to the pipe <div id=“middle_column”> $big_pipe->addPagelet( new UIPagelet() <div id=“paglet_composer”></div> ->setSrc(‘/pagelet/composer.php’) ->setWrapperId(‘pagelet_composer’)); <div id=“pagelet_stream”></div> … </div>’); 4: generate pagelets flush them out. // Step echo $big_pipe->render();
  • 65. BigPipe programming model // Step 1: create BigPipe instance $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE); // Step 2: Specify page layout and pagelet place holders. // Step 3: add pagelets to the pipe $big_pipe->setPage( ‘<div id=“left_column”> <div id=“pagelet_navigation”></div> $big_pipe->addPagelet( </div> <div id=“middle_column”> new UIPagelet() <div id=“paglet_composer”></div> <div id=“pagelet_stream”></div> ->setSrc(‘/pagelet/composer.php’) </div>’); ->setWrapperId(‘pagelet_composer’)); // Step 3: add pagelets to the pipe … $big_pipe->addPagelet( new UIPagelet() ->setSrc(‘/pagelet/composer.php’) ->setWrapperId(‘pagelet_composer’)); … // Step 4: generate pagelets flush them out. echo $big_pipe->render();
  • 66. BigPipe programming model // Step 1: create BigPipe instance $big_pipe = BigPipe::getInstance(BigPipeType::PIPELINE); // Step 2: Specify page layout and pagelet place holders. $big_pipe->setPage( ‘<div id=“left_column”> <div id=“pagelet_navigation”></div> // Step 4: generate pagelets flush them out. </div> <div id=“middle_column”> <div id=“paglet_composer”></div> <div id=“pagelet_stream”></div> echo $big_pipe->render(); </div>’); // Step 3: add pagelets to the pipe $big_pipe->addPagelet( new UIPagelet() ->setSrc(‘/pagelet/composer.php’) ->setWrapperId(‘pagelet_composer’)); … // Step 4: generate pagelets flush them out. echo $big_pipe->render();
  • 67. BigPipe generation modes •  Single flush mode ▪  Support search-engine crawlers ▪  Support clients without JavaScript •  Pipeline mode ▪  Generate and flush pagelets sequentially (default mode) •  Parallel mode ▪  Generate pagelets in parallel and flush them out-of-order
  • 68. BigPipe programming model •  Encapsulation ▪  Hide implementation details •  Intuitive ▪  Easy to understand mental model for developers •  Flexible ▪  Different modes good for different use case.
  • 69. BigPipe advanced features •  AjaxPipe ▪  Use iframe to pipeline Ajax response ▪  Used by Facebook home page’s dashboards (photo, groups, etc) •  WidgetPipe ▪  Pipeline multiple widgets (“like” button) on third party websites