Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Better Performance & Uptime Through Async

25e2ecf9b520e06d71e47ab083924300?s=47 xyu
May 14, 2016

Better Performance & Uptime Through Async

Asynchronous programming makes your site both faster and more reliable. Let’s peal back the covers of Jetpack Stats and steal some of the concepts that can make our site faster and more stable.

25e2ecf9b520e06d71e47ab083924300?s=128

xyu

May 14, 2016
Tweet

More Decks by xyu

Other Decks in Technology

Transcript

  1. @HypertextRanch me@xyu.io xyu.io xyu     Better Performance

    & Uptime Through Async WordCamp Maine 2016
  2.  Automattic — Data Infrastructure Team

  3. None
  4. None
  5.  22,000,000,000 Page Views 3,500,000,000 Uniques 110,000,000 Blogs

  6. None
  7. 1 MILLION MODULES 1 MILLION MODULES

  8. None
  9. None
  10. 22 Billion Views × 100ms = 69 Person Years

  11. Asynchronous Programing

  12. B A C

  13. B A C

  14. C A B

  15. C A B

  16. C A B

  17. C A B

  18.  Don’t Block The Critical Path

  19. C A B

  20. C A B D

  21. C A B D

  22. C A B E D

  23. https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp

  24. https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp

  25. Load Jetpack & WordPress.com Stats Async

  26. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  27. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  28. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  29. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  30. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  31. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  32. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  33. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  34. <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq =

    window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script> <script type='text/javascript' src='https://stats.wp.com/e-201618.js' async defer> </script> <script type='text/javascript'> _stq = window._stq || []; _stq.push( [ 'view', { v:'ext', j:'1:4.0.2', blog:'105573785', post:'0', tz:'-5', srv:'2016.maine.wordcamp.org' } ] ); </script>
  35. None
  36. Asynchronous Processing

  37. C A B

  38. B A C

  39. Asynchronous Processing Queues

  40. C A B

  41. Counting Uniques — Naïve Approach

  42. B A C

  43. Counting Uniques — Actual Approach

  44. C A B

  45. None
  46. None
  47. Processing Pixels • Loggers • Aggregator & Preprocessor • Kafka

    Queue • ETL Pipeline • Hive Datastore • Counting Uniques • Export Results to MySQL
  48. WP Cron — Schedule Async Hooks

  49. <?php function some_action( $arg1, $arg2 ) { // do something

    } add_action( 'my_new_event', 'some_action', 10, 2 ); wp_schedule_single_event( time() + 10, // in 10 seconds 'my_new_event', array( $arg1, $arg2 ) );
  50. None
  51. B A C

  52. C A B

  53. @HypertextRanch me@xyu.io xyu.io xyu     Thanks!