Scaling WordPress

52
Scaling WordPress Joseph Scott http://josephscott.org

description

Sca

Transcript of Scaling WordPress

Page 1: Scaling WordPress

Scaling WordPress

Joseph Scotthttp://josephscott.org

Page 2: Scaling WordPress

Lessons FromWordPress.com

Page 4: Scaling WordPress

Reading on WordPress.com

Over 372 million people view more than 4.1 billion pages each month.

http://en.wordpress.com/stats/

Page 5: Scaling WordPress

Publishing on WordPress.com

about 49.3 million new posts and 50.7 million new comments each month

http://en.wordpress.com/stats/

Page 6: Scaling WordPress
Page 7: Scaling WordPress

Start Small

Page 8: Scaling WordPress

Layers

Network

Server Hardware

Operating System

Page 9: Scaling WordPress

Layers

Network

Server Hardware

Operating System

HTTP PHP MySQL

Page 10: Scaling WordPress

Layers

Network

Server Hardware

Operating System

HTTP PHP MySQL

WordPress

Page 11: Scaling WordPress

Layers

Network

Server Hardware

Operating System

HTTP PHP MySQL

WordPress

Page 12: Scaling WordPress

HTTP - Apache

‣Remove unused modules‣Turn off host name lookups‣Turn off .htaccess‣Turn on compression‣Tweak MaxClients

Page 13: Scaling WordPress

HTTP

Try Nginx

http://nginx.org/

Page 14: Scaling WordPress

PHP

๏ Use an opcode cache ( APC, Zend Opcache )๏ Use newer versions๏ Don’t use on static files๏ Be careful with preg_* functions๏ Profile your code ( Xdebug, VLD, XHProf )๏ Don’t re-invent native PHP functions

Page 15: Scaling WordPress

MySQL

๏ Use InnoDB, unless you have a good reason not to๏ Use the slow query log๏ Use EXPLAIN on queries, learn what the output means๏ Double Triple check your indexes๏ Learn about quirks

Page 16: Scaling WordPress

MySQL

Not Just MySQL Any More

Page 17: Scaling WordPress

MySQL

Page 18: Scaling WordPress

WordPress

๏ Turn off unused plugins๏ Use a caching plugin๏ Carefully vet themes and plugins they have great powers๏ Profile real life performance

Page 19: Scaling WordPress

Front End Performance

stevesouders.com

Page 20: Scaling WordPress

Track Performance

Forget about averages

Page 21: Scaling WordPress

Track Performance

Forget about averages

Average

s Lie!

Page 23: Scaling WordPress

Making Things Better

Page 24: Scaling WordPress

First, Know Your Limits

Page 25: Scaling WordPress

First, Know Your Limits

Determine the theoretical best performancefor your setup

Page 26: Scaling WordPress

First, Know Your Limits

Determine the theoretical best performancefor your setup

What ever you come up with will be slower than that

Page 27: Scaling WordPress

Less Work > More Work

Page 28: Scaling WordPress

PHP - opcode caching

Read Parse Compile Execute Output

.php

Page 29: Scaling WordPress

PHP - opcode caching

Read Parse Compile Execute Output

.php

APC

Opcode Cache

Page 30: Scaling WordPress

PHP - opcode caching

Reduce time per request by 4x

Increase requests per second by 4x

Page 31: Scaling WordPress

Less work, for the same resultmeans more capacity

Page 32: Scaling WordPress

Memcached

Key / Value data storage

In memory only, won’t survive a reboot

http://memcached.org/

Page 33: Scaling WordPress

WordPress + Memcached

WordPress Object Cache,reduces the number of database queries

http://wordpress.org/extend/plugins/memcached/

Page 34: Scaling WordPress

Layers

HTTP PHP MySQL

WordPress

Memcached

Page 35: Scaling WordPress

WordPress + Memcached+ Batcache

Stores & serve fully rendered pagesin Memcached

http://wordpress.org/extend/plugins/batcache/

Page 36: Scaling WordPress

Layers

HTTP PHP MySQL

WordPress

Memcached

Batcache

Page 37: Scaling WordPress

Servers

MySQL, Nginx, PHP-FPM,Memcached

Page 38: Scaling WordPress

Servers

web

mysql

memcached

Page 39: Scaling WordPress

Servers

But my one database serverstill can’t keep up

Page 40: Scaling WordPress

MySQL Replication

Master / Slave

๏ One way, asynchronous๏ Writes to the master๏ Reads to the slave๏ Multiple slaves & chaining

Page 41: Scaling WordPress

WordPress + HyperDB

Makes WordPress aware ofMySQL replication

http://wordpress.org/extend/plugins/hyperdb/

Page 42: Scaling WordPress

WordPress + HyperDB

๏ Read & write servers๏ Priority for reads & writes๏ Local and remote data centers๏ Private and public networks๏ Per table granularity๏ Smart post-write master reads

Page 43: Scaling WordPress

Servers

web

mysql

memcached

mysql

writes

reads replication

Page 44: Scaling WordPress

MySQL Replication

Other Uses

๏ Slave just for backups๏ Multiple data centers๏ Task specific web servers

Page 45: Scaling WordPress

Servers

loadbalancer

web1

memcached1

replication

web2

web3

mysql1 mysql2

memcached2

Page 46: Scaling WordPress

Servers

Imagine all of that with:

๏ Multiple load balancers๏ Multiple networks ( public / private )๏ Multiple data centers

Page 47: Scaling WordPress

One More Thing

Page 48: Scaling WordPress

Asynchronous Jobs Queue

Lots of options

We built one for WordPress.com

Page 49: Scaling WordPress

Asynchronous Jobs Queue

http://code.trac.wordpress.org/browser/jobs

http://code.trac.wordpress.org/wiki/JobsDocs

All PHP + MySQL

Page 50: Scaling WordPress

Asynchronous Jobs Queue

Good for anything that isn’trequired for rendering a page

Page 51: Scaling WordPress

Questions?

Page 52: Scaling WordPress

Joseph Scott

http://josephscott.org/[email protected]

@josephscott