64
TurboPress The Hih Performance Guide to WordPress

TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Embed Size (px)

DESCRIPTION

Jeff Waugh coaches WordCamp Sydney 2012 on turboboosting your WordPress site, and setting it up for Higher Performance #wcsyd

Citation preview

Page 1: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

TurboPressThe High Performance Guide to WordPress

Page 2: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Let’s start withsome theory.

Page 3: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

INTERWEBS AMIRITE?

Page 4: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser

Web Server

PHP

WordPress

MySQL

shovelling

shovelling

shovelling

shovelling

Page 5: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

0. The Browser

Page 6: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org ”

“ 70 . 85 . 31 . 216 “

1. DNS

DNS Host

Page 7: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org ”

“ 70 . 85 . 31 . 216 “

1. DNS

DNS Host

10 ms 160 ms

210 ms

Page 8: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org ”

“ 70 . 85 . 31 . 216 “

1. DNS

Google’s web performance team calculate the average DNS query takes 130ms!

DNS Host

10 ms 160 ms

210 ms

Page 9: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org “

“ 70 . 85 . 31 . 216 “

2. HTTP

10 ms 160 ms

DNS Host210 ms

Web Server70 . 85 . 31 . 216 : 80

Page 10: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org “

“ 70 . 85 . 31 . 216 “

2. HTTP

10 ms 160 ms

DNS Host210 ms

Web Server70 . 85 . 31 . 216 : 80

220 ms

Page 11: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org “

“ 70 . 85 . 31 . 216 “

3. PHP

10 ms 160 ms

Web Server70 . 85 . 31 . 216 : 80

220 ms

PHP

DNS Host210 ms

Page 12: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org “

“ 70 . 85 . 31 . 216 “

3. PHP

10 ms 160 ms

Web Server70 . 85 . 31 . 216 : 80

220 ms

PHP

DNS Host210 ms

650 ms

Page 13: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser Router ISP DNS“ bethesignal.org “

“ 70 . 85 . 31 . 216 “

4. MySQL

10 ms 160 ms

MySQLWeb Server70 . 85 . 31 . 216 : 80

220 ms

PHP

DNS Host210 ms

Page 14: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

5. Back to the browser!

Page 15: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser

Web Server

PHP

WordPress

MySQL

shovelling

shovelling

shovelling

shovelling

Page 16: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Some gory detail…

Page 17: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

GET / HTTP/1.1Host: bethesignal.orgConnection: keep-aliveUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Encoding: gzip,deflate,sdchAccept-Language: en-AU,en;q=0.8,en-US;q=0.6Accept-Charset: UTF-8,*;q=0.5Cookie: wordpress_logged_in_...=jdub...If-Modified-Since: Thu, 12 Jul 2012 21:27:06 GMT

HTTP/1.1 200 OKServer: nginx/1.2.1Date: Fri, 20 Jul 2012 23:48:04 GMTContent-Type: text/html; charset=UTF-8Transfer-Encoding: chunkedConnection: keep-aliveVary: Accept-EncodingVary: CookieX-Pingback: http://bethesignal.org/xmlrpc.phpExpires: Wed, 11 Jan 1984 05:00:00 GMTLast-Modified: Fri, 20 Jul 2012 23:48:03 GMTCache-Control: no-cache, must-revalidate, max-age=0Pragma: no-cacheContent-Encoding: gzip

Page 18: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

10:32:16.084565 * About to connect() to bethesignal.org port 80 (#0)10:32:16.084768 * Trying 70.85.31.216... TCP_NODELAY set10:32:16.283247 * connected10:32:16.283376 * Connected to bethesignal.org (70.85.31.216) port 80 (#0)10:32:16.283528 > GET / HTTP/1.110:32:16.283528 > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/...10:32:16.283528 > Host: bethesignal.org10:32:16.283528 > Accept: */*10:32:16.283528 > Accept-Encoding: deflate, gzip10:32:16.283528 > Cookie: wordpress_logged_in_...=jdub...10:32:16.283528 > 10:32:16.995103 < HTTP/1.1 200 OK10:32:16.995216 < Server: nginx/1.2.110:32:16.995240 < Date: Sat, 21 Jul 2012 00:32:16 GMT10:32:16.995295 < Content-Type: text/html; charset=UTF-810:32:16.995374 < Transfer-Encoding: chunked10:32:16.995412 < Connection: keep-alive10:32:16.995447 < Vary: Accept-Encoding10:32:16.995482 < Vary: Cookie10:32:16.995515 < X-Pingback: http://bethesignal.org/xmlrpc.php10:32:16.995548 < Expires: Wed, 11 Jan 1984 05:00:00 GMT10:32:16.995601 < Last-Modified: Sat, 21 Jul 2012 00:32:16 GMT10:32:16.995642 < Cache-Control: no-cache, must-revalidate, max-age=010:32:16.995680 < Pragma: no-cache10:32:16.995717 < Content-Encoding: gzip10:32:16.995759 < 10:32:16.995794 { [data not shown]10:32:17.393072 * Connection #0 to host bethesignal.org left intact10:32:17.393170 * Closing connection #0

Page 19: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Now you havesome <html> …

Page 20: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

GET /wp-content/uploads/2011/04/strange-days.jpg HTTP/1.1Host: bethesignal.orgConnection: keep-aliveCache-Control: no-cachePragma: no-cacheUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Referer: http://bethesignal.org/Accept-Encoding: gzip,deflate,sdchAccept-Language: en-AU,en;q=0.8,en-US;q=0.6Accept-Charset: UTF-8,*;q=0.5Cookie: wordpress_logged_in_...=jdub...

HTTP/1.1 200 OKServer: nginx/1.2.1Date: Fri, 20 Jul 2012 23:50:50 GMTContent-Type: image/jpegContent-Length: 180112Last-Modified: Fri, 08 Apr 2011 14:25:27 GMTConnection: keep-aliveExpires: Wed, 19 Jul 2017 23:50:50 GMTCache-Control: max-age=157680000Accept-Ranges: bytes

Page 21: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

10:34:05.051972 * About to connect() to bethesignal.org port 80 (#0)10:34:05.052162 * Trying 70.85.31.216... TCP_NODELAY set10:34:05.251898 * connected10:34:05.251989 * Connected to bethesignal.org (70.85.31.216) port 80 (#0)10:34:05.252123 > GET /wp-content/uploads/2011/04/strange-days.jpg HTTP/1.110:34:05.252123 > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/...10:34:05.252123 > Host: bethesignal.org10:34:05.252123 > Accept: */*10:34:05.252123 > Accept-Encoding: deflate, gzip10:34:05.252123 > Cookie: wordpress_logged_in_...=jdub...10:34:05.252123 > 10:34:05.448816 < HTTP/1.1 200 OK10:34:05.448981 < Server: nginx/1.2.110:34:05.449045 < Date: Sat, 21 Jul 2012 00:34:05 GMT10:34:05.449091 < Content-Type: image/jpeg10:34:05.449131 < Content-Length: 18011210:34:05.449170 < Last-Modified: Fri, 08 Apr 2011 14:25:27 GMT10:34:05.449211 < Connection: keep-alive10:34:05.449250 < Expires: Thu, 20 Jul 2017 00:34:05 GMT10:34:05.449290 < Cache-Control: max-age=15768000010:34:05.449331 < Accept-Ranges: bytes10:34:05.449382 < 10:34:05.449440 { [data not shown]10:34:06.443613 * Connection #0 to host bethesignal.org left intact10:34:06.443714 * Closing connection #0

Page 22: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

webpagetest.orgSydney ADSL

Page 23: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

webpagetest.orgLos An!eles Fibre

Page 24: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

webpagetest.orgLos An!eles Fibre

Page 25: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

The Network

Page 26: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Host DNS and web services close to your

primary audience.

Page 27: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

(This is one reason why global web sites use CDNs,

particularly for static content.)

Page 28: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

The Web Server

Page 29: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Apache

mpm_prefork

mod_php

*.php

shovelling

shovelling

shovelling...����������� ������������������  and����������� ������������������  back����������� ������������������  again!

Page 30: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Apache

mpm_prefork

mod_php

*.png

shovelling

shovelling

shovelling...����������� ������������������  and����������� ������������������  back����������� ������������������  again!

Page 31: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

1 process per request

10-100MB per process (or more)

Page 32: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Ri!ht now, web servers around the planet are wastin! !obs of memory

servin! static files.

Page 33: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Try a differentprocess model.

Page 34: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

You could use mpm_worker…

Page 35: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

MASSIVE PHP FAIL

Page 36: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

nginx

Page 37: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

1 process per core

request overhead measured in kilobytes

Page 38: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

nginx

php-fastcgi

[worker]

*.php

shovelling

shovelling

shovelling...����������� ������������������  and����������� ������������������  back����������� ������������������  again!

Page 39: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

nginx

*.pngshovelling

...����������� ������������������  and����������� ������������������  back����������� ������������������  again!

Page 40: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Apache and nginx

Netcraft Surveyto May 2012

Page 41: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

PHP

Page 42: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

“There are only two hard things in Computing Science: cache

invalidation and naming things.”

- Phil Karlton

Page 43: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

It’s turtles allthe way down.

Page 44: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Opcode cachingDon’t let PHP do the same work twice.

Page 45: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

APC

Page 46: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

APCeverywhere!

Page 47: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

WordPress

Page 48: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Object cachingDon’t talk to the database if you don’t have to.

Page 49: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

APC or memcachewp-content/object-cache.php

Page 50: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Output or page cachingAvoid PHP entirely…?

Page 51: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

WP Super Cache

Page 52: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

nginx

*.pngshovelling

...����������� ������������������  and����������� ������������������  back����������� ������������������  again!

Page 53: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Batcache

Page 54: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Reverse proxy cache, such as nginx, Varnish

Page 55: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

MySQL

Page 56: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Query (or results) cacheDon’t let MySQL do the same work twice.

Page 57: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Schema, index and behavioural optimisation

Don’t tell MySQL do stupid work in the first place.

Page 58: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Browser

Page 59: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Raw performancevs.

Perception of performance

Page 60: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

Measure twice, cut once.

Page 61: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012
Page 62: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012
Page 63: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012
Page 64: TurboPress: The High Performance Guide to WordPress - Jeff Waugh - WordCamp Sydney 2012

“totes����������� ������������������  insan����������� ������������������  hosting����������� ������������������  guys!”-����������� ������������������  Peter