A look at the modern WordPress server stack
by
Carl Alexander
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
A look at the modern WordPress server stack
Slide 2
Slide 2 text
Carl Alexander
Slide 3
Slide 3 text
@twigpress
Slide 4
Slide 4 text
carlalexander.ca
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
Story time
Slide 7
Slide 7 text
A fast WordPress server: Linux + Apache + MySQL + PHP Once upon a time…
Slide 8
Slide 8 text
Those were the “good ol’ days”! Once upon a time…
Slide 9
Slide 9 text
Things were simpler then… Once upon a time…
Slide 10
Slide 10 text
Everything has to load fast! Nowadays…
Slide 11
Slide 11 text
Nowadays… Or there are consequences…
Slide 12
Slide 12 text
Nowadays… So the WordPress server evolved
Slide 13
Slide 13 text
The stack Nowadays…
Slide 14
Slide 14 text
Request Response
Slide 15
Slide 15 text
Request / Response Request / Response
Slide 16
Slide 16 text
Request / Response HTTP Request Web Server Browser
Slide 17
Slide 17 text
Request / Response HTTP Response Web Server Browser
Slide 18
Slide 18 text
Request / Response First HTTP response: Always HTML content
Slide 19
Slide 19 text
Request / Response Follow up HTTP requests: Required files (e.g. CSS, JS, images)
Slide 20
Slide 20 text
Request / Response Cycle continues until browser can render the page
Slide 21
Slide 21 text
Request / Response The faster it happens, the faster your website loads
Slide 22
Slide 22 text
Optimizing the cycle
Slide 23
Slide 23 text
Optimizing the cycle Can't just make a web server faster
Slide 24
Slide 24 text
Optimizing the cycle Web server is also a dispatcher
Slide 25
Slide 25 text
Optimizing the cycle Forwards requests to other services (like PHP)
Slide 26
Slide 26 text
Optimizing the cycle We need to receive as few requests as possible
Slide 27
Slide 27 text
Optimizing the cycle We need to forward as few requests as possible
Slide 28
Slide 28 text
Cycle stack elements
Slide 29
Slide 29 text
Web server
Slide 30
Slide 30 text
Web server
Slide 31
Slide 31 text
Web server Three players. 90% market share.
Slide 32
Slide 32 text
Apache: The old guard Web server
Slide 33
Slide 33 text
IIS: The Microsoft solution Web server (You can ignore this one!)
Slide 34
Slide 34 text
nginx: The new kid Web server
Slide 35
Slide 35 text
Used by Automattic since 2008 Web server
Slide 36
Slide 36 text
Used by top hosting companies Web server
Slide 37
Slide 37 text
Used by high-end WordPress agencies Web server
Slide 38
Slide 38 text
Built to handle a lot of traffic Web server
Slide 39
Slide 39 text
HTTP cache
Slide 40
Slide 40 text
HTTP cache
Slide 41
Slide 41 text
Most important element of the stack HTTP cache
Slide 42
Slide 42 text
A web server is pretty dumb HTTP cache (Well, by default)
Slide 43
Slide 43 text
Always forwards requests to PHP HTTP cache
Slide 44
Slide 44 text
PHP often generates the same response HTTP cache
Slide 45
Slide 45 text
That’s terrible! HTTP cache (PHP is our bottleneck)
Slide 46
Slide 46 text
HTTP cache solves this problem HTTP cache
Slide 47
Slide 47 text
Caches responses from PHP HTTP cache
Slide 48
Slide 48 text
Drastic reduction in cycle time HTTP cache
Slide 49
Slide 49 text
Has the widest range of options HTTP cache
Slide 50
Slide 50 text
Easiest option: Install a page caching plugin HTTP cache
Slide 51
Slide 51 text
HTTP cache • Batcache • Hyper Cache • WP Rocket • WP Super Cache • W3 Total Cache
Slide 52
Slide 52 text
Middle option: Have the web server do it HTTP cache
Slide 53
Slide 53 text
Hardest option: Add Varnish to the stack HTTP cache
Slide 54
Slide 54 text
Questions
Slide 55
Slide 55 text
Optimizing PHP
Slide 56
Slide 56 text
Optimizing PHP
Slide 57
Slide 57 text
No cached response to send back Optimizing PHP
Slide 58
Slide 58 text
Time for WordPress to do its thing Optimizing PHP
Slide 59
Slide 59 text
Turns our request into a response Optimizing PHP
Slide 60
Slide 60 text
PHP is the bottleneck Optimizing PHP
Slide 61
Slide 61 text
Latest PHP version
Slide 62
Slide 62 text
Minimum requirement: PHP 5.2 PHP version
Slide 63
Slide 63 text
Almost 10 years old! (No support since 2011) PHP version
Slide 64
Slide 64 text
PHP team hasn't been sitting idle PHP version
Slide 65
Slide 65 text
Largest improvement was from 5.3 to 5.4 (Ignoring PHP 7) PHP version
Slide 66
Slide 66 text
Opcode caching
Slide 67
Slide 67 text
PHP compiles a script each time it executes it Opcode caching
Slide 68
Slide 68 text
Caches compiled PHP code Opcode caching
Slide 69
Slide 69 text
Not bundled with PHP before 5.5 Opcode caching
Slide 70
Slide 70 text
Next generation PHP
Slide 71
Slide 71 text
Two new PHP compilers: HHVM and PHP 7 WordPress
Slide 72
Slide 72 text
Both built from the ground up WordPress
Slide 73
Slide 73 text
Incredible performance gains WordPress
Slide 74
Slide 74 text
Good news: WordPress 100% compatible WordPress
Slide 75
Slide 75 text
Bad news: Not all plugins or themes are WordPress
Slide 76
Slide 76 text
Always have a fallback to PHP 5 WordPress
Slide 77
Slide 77 text
Questions
Slide 78
Slide 78 text
Query Result
Slide 79
Slide 79 text
Query / Result Query / Result
Slide 80
Slide 80 text
PHP files don't contain any data Query / Result
Slide 81
Slide 81 text
WordPress stores all its data in a MySQL database Query / Result
Slide 82
Slide 82 text
Query / Result Query Database Server WordPress (PHP)
Slide 83
Slide 83 text
Query / Result Result Database Server WordPress (PHP)
Slide 84
Slide 84 text
Can happen a few dozen times to a few hundred times Query / Result (Talk with your developer(s) if it's the latter!)
Slide 85
Slide 85 text
Optimizing the cycle
Slide 86
Slide 86 text
Database queries take time Optimizing the cycle
Slide 87
Slide 87 text
Slows down PHP execution Optimizing the cycle
Slide 88
Slide 88 text
Can’t always control how many queries WordPress needs to do Optimizing the cycle
Slide 89
Slide 89 text
We need to make PHP wait as little as possible Optimizing the cycle
Slide 90
Slide 90 text
Cycle stack elements
Slide 91
Slide 91 text
Database server
Slide 92
Slide 92 text
Database server
Slide 93
Slide 93 text
MySQL database != MySQL server Database server
Slide 94
Slide 94 text
Multiple forked versions now Database server
Slide 95
Slide 95 text
No performance difference between versions Database server
Slide 96
Slide 96 text
Storage engines are what impact performance Database server
Slide 97
Slide 97 text
They control data management Database server
Slide 98
Slide 98 text
WordPress default: MyISAM Database server
Slide 99
Slide 99 text
Better choice: InnoDB Database server
Slide 100
Slide 100 text
Object cache
Slide 101
Slide 101 text
Object cache
Slide 102
Slide 102 text
Stores fetched or generated data Object cache
Slide 103
Slide 103 text
WordPress uses it a lot Object cache
Slide 104
Slide 104 text
Less database queries Object cache
Slide 105
Slide 105 text
But data doesn’t persist by default Object cache
Slide 106
Slide 106 text
Data can stay valid for a long time Object cache
Slide 107
Slide 107 text
Use a persistent object cache Object cache
Slide 108
Slide 108 text
Connects the object cache to a persistent data store Object cache
Slide 109
Slide 109 text
Two popular data store options Object cache
Slide 110
Slide 110 text
Memcached: The old favourite Object cache
Slide 111
Slide 111 text
Redis: The new hotness Object cache
Slide 112
Slide 112 text
Doing it yourself
Slide 113
Slide 113 text
DebOps for WordPress Doing it yourself • HHVM • MariaDB • nginx • Redis • Varnish
Slide 114
Slide 114 text
EasyEngine Doing it yourself • MariaDB • nginx • Various object cache options • Various HTTP cache options • Various PHP options
Slide 115
Slide 115 text
Trellis Doing it yourself • MariaDB • Memcached • nginx • nginx HTTP cache (optional) • PHP 7
Slide 116
Slide 116 text
Questions
Slide 117
Slide 117 text
Thank you!