SlideShare une entreprise Scribd logo
1  sur  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!

Contenu connexe

Tendances

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
James Pearce
 
Web前端性能分析工具导引
Web前端性能分析工具导引Web前端性能分析工具导引
Web前端性能分析工具导引
冰 郭
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web Performance
Eric ShangKuan
 
[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
Christopher Schmitt
 
08 session-tracking
08 session-tracking08 session-tracking
08 session-tracking
snopteck
 
Rest Security with JAX-RS
Rest Security with JAX-RSRest Security with JAX-RS
Rest Security with JAX-RS
Frank Kim
 
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
jward5519
 

Tendances (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
 

Similaire à 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 Pagecache
Ajax Experience 2009
 
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
SALT Lab @ UBC
 
High performance website
High performance websiteHigh performance website
High performance website
Chamnap Chhorn
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutions
woutervugt
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
George Ang
 

Similaire à 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
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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 Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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