A look at the modern WordPress server stack

A look at the modern WordPress server stack

These are the slides from a talk given at WordCamp San Diego 2016.

Do you remember when you could run a "fast" WordPress site with just an Apache server and PHP? Yeah, those were days! Things were a lot less complicated then.

Now, everything has to load lightning fast! Visitors don't have the same expectations about loading times as they used to. A slow site can have serious implications for you or your client.

You just can't have a site that feels fast to your visitors without adding a few more gears to your server engine.

During this talk, you'll learn what makes up the modern WordPress server stack. You'll see how the various pieces fit together to make your WordPress site fast. You'll leave knowing what your next steps are to get your own modern WordPress server stack.

You can read the companion article at: https://carlalexander.ca/modern-wordpress-server-stack/

5a4758faa5ba6c1322bdfb0f6ebcf56c?s=128

Carl Alexander

April 23, 2016
Tweet

Transcript

  1. A look at the modern WordPress server stack

  2. Carl Alexander

  3. @twigpress

  4. carlalexander.ca

  5. None
  6. Story time

  7. A fast WordPress server: Linux + Apache + MySQL +

    PHP Once upon a time…
  8. Those were the “good ol’ days”! Once upon a time…

  9. Things were simpler then… Once upon a time…

  10. Everything has to load fast! Nowadays…

  11. Nowadays… Or there are consequences…

  12. Nowadays… So the WordPress server evolved

  13. The stack Nowadays…

  14. Request Response

  15. Request / Response Request / Response

  16. Request / Response HTTP Request Web Server Browser

  17. Request / Response HTTP Response Web Server Browser

  18. Request / Response First HTTP response: Always HTML content

  19. Request / Response Follow up HTTP requests: Required files (e.g.

    CSS, JS, images)
  20. Request / Response Cycle continues until browser can render the

    page
  21. Request / Response The faster it happens, the faster your

    website loads
  22. Optimizing the cycle

  23. Optimizing the cycle Can't just make a web server faster

  24. Optimizing the cycle Web server is also a dispatcher

  25. Optimizing the cycle Forwards requests to other services (like PHP)

  26. Optimizing the cycle We need to receive as few requests

    as possible
  27. Optimizing the cycle We need to forward as few requests

    as possible
  28. Cycle stack elements

  29. Web server

  30. Web server

  31. Web server Three players. 90% market share.

  32. Apache: The old guard Web server

  33. IIS: The Microsoft solution Web server (You can ignore this

    one!)
  34. nginx: The new kid Web server

  35. Used by Automattic since 2008 Web server

  36. Used by top hosting companies Web server

  37. Used by high-end WordPress agencies Web server

  38. Built to handle a lot of traffic Web server

  39. HTTP cache

  40. HTTP cache

  41. Most important element of the stack HTTP cache

  42. A web server is pretty dumb HTTP cache (Well, by

    default)
  43. Always forwards requests to PHP HTTP cache

  44. PHP often generates the same response HTTP cache

  45. That’s terrible! HTTP cache (PHP is our bottleneck)

  46. HTTP cache solves this problem HTTP cache

  47. Caches responses from PHP HTTP cache

  48. Drastic reduction in cycle time HTTP cache

  49. Has the widest range of options HTTP cache

  50. Easiest option: Install a page caching plugin HTTP cache

  51. HTTP cache • Batcache • Hyper Cache • WP Rocket

    • WP Super Cache • W3 Total Cache
  52. Middle option: Have the web server do it HTTP cache

  53. Hardest option: Add Varnish to the stack HTTP cache

  54. Questions

  55. Optimizing PHP

  56. Optimizing PHP

  57. No cached response to send back Optimizing PHP

  58. Time for WordPress to do its thing Optimizing PHP

  59. Turns our request into a response Optimizing PHP

  60. PHP is the bottleneck Optimizing PHP

  61. Latest PHP version

  62. Minimum requirement: PHP 5.2 PHP version

  63. Almost 10 years old! (No support since 2011) PHP version

  64. PHP team hasn't been sitting idle PHP version

  65. Largest improvement was from 5.3 to 5.4 (Ignoring PHP 7)

    PHP version
  66. Opcode caching

  67. PHP compiles a script each time it executes it Opcode

    caching
  68. Caches compiled PHP code Opcode caching

  69. Not bundled with PHP before 5.5 Opcode caching

  70. Next generation PHP

  71. Two new PHP compilers: HHVM and PHP 7 WordPress

  72. Both built from the ground up WordPress

  73. Incredible performance gains WordPress

  74. Good news: WordPress 100% compatible WordPress

  75. Bad news: Not all plugins or themes are WordPress

  76. Always have a fallback to PHP 5 WordPress

  77. Questions

  78. Query Result

  79. Query / Result Query / Result

  80. PHP files don't contain any data Query / Result

  81. WordPress stores all its data in a MySQL database Query

    / Result
  82. Query / Result Query Database Server WordPress (PHP)

  83. Query / Result Result Database Server WordPress (PHP)

  84. Can happen a few dozen times to a few hundred

    times Query / Result (Talk with your developer(s) if it's the latter!)
  85. Optimizing the cycle

  86. Database queries take time Optimizing the cycle

  87. Slows down PHP execution Optimizing the cycle

  88. Can’t always control how many queries WordPress needs to do

    Optimizing the cycle
  89. We need to make PHP wait as little as possible

    Optimizing the cycle
  90. Cycle stack elements

  91. Database server

  92. Database server

  93. MySQL database != MySQL server Database server

  94. Multiple forked versions now Database server

  95. No performance difference between versions Database server

  96. Storage engines are what impact performance Database server

  97. They control data management Database server

  98. WordPress default: MyISAM Database server

  99. Better choice: InnoDB Database server

  100. Object cache

  101. Object cache

  102. Stores fetched or generated data Object cache

  103. WordPress uses it a lot Object cache

  104. Less database queries Object cache

  105. But data doesn’t persist by default Object cache

  106. Data can stay valid for a long time Object cache

  107. Use a persistent object cache Object cache

  108. Connects the object cache to a persistent data store Object

    cache
  109. Two popular data store options Object cache

  110. Memcached: The old favourite Object cache

  111. Redis: The new hotness Object cache

  112. Doing it yourself

  113. DebOps for WordPress Doing it yourself • HHVM • MariaDB

    • nginx • Redis • Varnish
  114. EasyEngine Doing it yourself • MariaDB • nginx • Various

    object cache options • Various HTTP cache options • Various PHP options
  115. Trellis Doing it yourself • MariaDB • Memcached • nginx

    • nginx HTTP cache (optional) • PHP 7
  116. Questions

  117. Thank you!