Scaling WordPress

Post on 14-Dec-2014

6.695 views 2 download

Tags:

description

Sca

Transcript of Scaling WordPress

Scaling WordPress

Joseph Scotthttp://josephscott.org

Lessons FromWordPress.com

Reading on WordPress.com

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

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

Publishing on WordPress.com

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

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

Start Small

Layers

Network

Server Hardware

Operating System

Layers

Network

Server Hardware

Operating System

HTTP PHP MySQL

Layers

Network

Server Hardware

Operating System

HTTP PHP MySQL

WordPress

Layers

Network

Server Hardware

Operating System

HTTP PHP MySQL

WordPress

HTTP - Apache

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

HTTP

Try Nginx

http://nginx.org/

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

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

MySQL

Not Just MySQL Any More

MySQL

WordPress

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

Front End Performance

stevesouders.com

Track Performance

Forget about averages

Track Performance

Forget about averages

Average

s Lie!

Making Things Better

First, Know Your Limits

First, Know Your Limits

Determine the theoretical best performancefor your setup

First, Know Your Limits

Determine the theoretical best performancefor your setup

What ever you come up with will be slower than that

Less Work > More Work

PHP - opcode caching

Read Parse Compile Execute Output

.php

PHP - opcode caching

Read Parse Compile Execute Output

.php

APC

Opcode Cache

PHP - opcode caching

Reduce time per request by 4x

Increase requests per second by 4x

Less work, for the same resultmeans more capacity

Memcached

Key / Value data storage

In memory only, won’t survive a reboot

http://memcached.org/

WordPress + Memcached

WordPress Object Cache,reduces the number of database queries

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

Layers

HTTP PHP MySQL

WordPress

Memcached

WordPress + Memcached+ Batcache

Stores & serve fully rendered pagesin Memcached

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

Layers

HTTP PHP MySQL

WordPress

Memcached

Batcache

Servers

MySQL, Nginx, PHP-FPM,Memcached

Servers

web

mysql

memcached

Servers

But my one database serverstill can’t keep up

MySQL Replication

Master / Slave

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

WordPress + HyperDB

Makes WordPress aware ofMySQL replication

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

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

Servers

web

mysql

memcached

mysql

writes

reads replication

MySQL Replication

Other Uses

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

Servers

loadbalancer

web1

memcached1

replication

web2

web3

mysql1 mysql2

memcached2

Servers

Imagine all of that with:

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

One More Thing

Asynchronous Jobs Queue

Lots of options

We built one for WordPress.com

Asynchronous Jobs Queue

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

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

All PHP + MySQL

Asynchronous Jobs Queue

Good for anything that isn’trequired for rendering a page

Questions?

Joseph Scott

http://josephscott.org/joseph@josephscott.org

@josephscott