SlideShare una empresa de 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!

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar a Facebook Website Optimization: Ajaxifying, Caching and Pipelining

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
 

Similar a Facebook Website Optimization: Ajaxifying, Caching and Pipelining (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

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
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
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
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
 
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
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesSanjay Willie
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
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
 
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
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Facebook Website Optimization: Ajaxifying, Caching and Pipelining

  • 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