52
WordPress Performance and Scalability Joseph Scott http://joseph.randomnetworks.com / Thursday 28 August 2008 Utah Open Source Conference

WordPress Performance & Scalability

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: WordPress Performance & Scalability

WordPress Performance and Scalability

Joseph Scotthttp://joseph.randomnetworks.com/

Thursday 28 August 2008Utah Open Source Conference

Page 2: WordPress Performance & Scalability

WordCamp Utah

http://utah.wordcamp.org

Saturday 27 September 2008Provo, Utah (Novell)

Page 3: WordPress Performance & Scalability

Minimize Context Switches

Ask on topic questions (clarification)as we go along

Page 4: WordPress Performance & Scalability
Page 5: WordPress Performance & Scalability

No, Seriously,Backup First

Page 6: WordPress Performance & Scalability

Performance

How fast is a single request?

Page 7: WordPress Performance & Scalability

ScalabilityDealing with many requests at the same time

Page 8: WordPress Performance & Scalability

It’s Like An Onion

• WordPress

• MySQL / Memcache

• PHP

• Web server

• Network / Operating System

Page 9: WordPress Performance & Scalability

Network /Operating System

Tweak for your traffic

Look at TCP buffers and kernel enhancements(kqueue/epoll)

Page 10: WordPress Performance & Scalability

Web ServerApache? There are others:

•lighttpd•nginx•LiteSpeed (free/commercial)•Zeus (commercial)

Page 11: WordPress Performance & Scalability

Apache

• Can be a pig, remove any modules you aren’t using

• Turn off host name lookups

• Do you use symlinks? (turn off FollowSymLinks)

• Serve static content from another server (not Apache?)

Page 12: WordPress Performance & Scalability

PHP

• Compiler Cache (APC)

• Output buffering

• Minimize system calls

• Be careful with preg_* functions

• Don’t use on static files (unless you really want to)

Page 13: WordPress Performance & Scalability

MySQL• Table types

• MyISAM - high writes or reads, not both

• InnoDB - efficient locking, better concurrency

• Double and triple check indexes

• Tune your config (key_buffer_size, innodb_buffer_pool_size, query_cache_size, thread_cache, table_cache, etc)

• Interesting quirks, get familiar with them

Page 14: WordPress Performance & Scalability

MemcacheIn memory object cache, learn it, love it, use it

But be careful

Page 15: WordPress Performance & Scalability

WordPress

• MySQL tables default to MyISAM, consider switching some to InnoDB (wp_comments)

• Serve static content from another server

• Add caching plugins and throw more hardware at the problem

Page 16: WordPress Performance & Scalability

Does WordPress Scale?http://wordpress.com/stats/traffic/

Page 17: WordPress Performance & Scalability

Lets start from the basics and work our way up

Page 18: WordPress Performance & Scalability

Test Environment

• FreeBSD 7

• Apache 2.2.8

• PHP 5.2.6

• MySQL 5.0.51a

• WordPress 2.6.1

Page 19: WordPress Performance & Scalability

Test “Hardware”

• Parallels VM on Mac Pro

• 1GB Ram

• 1 Xeon 2.66

Page 20: WordPress Performance & Scalability

ab - Apache HTTP server benchmarking tool

ab -n 150 -c 15 http://192.168.1.115/wp/2.6.1/archives/1

Only worried about the fastest results, we want to see what’s possible

Page 21: WordPress Performance & Scalability

The Base Line

Zero byte HTML file (null.html)1480 r/s

Page 22: WordPress Performance & Scalability

APCZero byte PHP file (null.php)

Without APC: 1290 r/sWith APC: 1359 r/s

We’ll see bigger differences later

Page 23: WordPress Performance & Scalability

Hi There!

helloworld.html (13 bytes) - 1382 r/s

helloworld.php (<?php print "Hello World!"; ?>)

Without APC: 1283 r/sWith APC: 1348 r/s

Page 24: WordPress Performance & Scalability

More Unrealistic Numbers

Static version of archives/1 (5147 bytes)1027 r/s

Page 25: WordPress Performance & Scalability

Fun With Math•1027 r/s•1027 * 86,400 = 88,732,800 r/d

Page 26: WordPress Performance & Scalability

Requests != Page Views

7 request-able objects in archives/1 88,732,800 / 7 = 12,676,114 pv/d

Real average number of objects is closer to 5088,732,800 / 50 = 1,774,656 pv/d

Page 27: WordPress Performance & Scalability

WordPress 2.6.1

Page 28: WordPress Performance & Scalability

WordPress 2.6.1

Default Template - archives/1 (Hello World! post with one comment)17 queries

Without APC: 8 r/s / ~0.130s per pageWith APC: 38 r/s / ~0.025s per page

Page 29: WordPress Performance & Scalability

Use a compiler cache, it’s like free money!

Page 30: WordPress Performance & Scalability

WP Super Cache

• Plugin by Donncha O Caoimh (WPMU lead developer)

• Uses the advanced caching capabilities of WP to store complete versions of pages to disk

• Requires the web server to have write access to wp-content/cache

• http://wordpress.org/extend/plugins/wp-super-cache/

Page 31: WordPress Performance & Scalability

APC + WP Super Cache

Default Template - archives/1 (Hello World! post with one comment)

APC + WP Super Cache: 338 r/swith compression: 459 r/s

Page 32: WordPress Performance & Scalability

Kind of like printing money

Page 33: WordPress Performance & Scalability

Memcache & WordPress

• Written by Ryan Boren (WP lead developer)

• Stores database results and WordPress objects in memcache

• Reduces the number of database queries

• http://ryan.wordpress.com/2005/12/23/memcached-backend/

Page 34: WordPress Performance & Scalability

APC + Memcache

Default Template - archives/1 (Hello World! post with one comment)4 queries

APC + Memcache: 41 r/s / ~0.022s per page

Page 35: WordPress Performance & Scalability

Batcache!

Page 36: WordPress Performance & Scalability

Batcache

• Written by Andy Skelton (WP contributing developer)

• Like WP Super Cache, only stores rendered pages in memcache instead of to disk

• Builds on top of Ryan’s memcache code

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

Page 37: WordPress Performance & Scalability

APC + Memcache/Batcache

Default Template - archives/1 (Hello World! post with one comment)

APC + Memcache/Batcache: 449 r/s

Page 38: WordPress Performance & Scalability

Let me 'splain ... No, there is too much. Let me sum up.

Extras Requests per second

Page Generation

TimeNone 8 ~0.12s

APC 38 ~0.025s

APC + WP Super Cache

338 N/A

APC + WP Super Cache

+Compression459 N/A

APC + Memcache 41 ~0.022s

APC + Memcache +

Batcache449 N/A

Page 39: WordPress Performance & Scalability

What does all of this mean in real life?

Page 40: WordPress Performance & Scalability

Phase 1

Page 41: WordPress Performance & Scalability

Phase 2

Page 42: WordPress Performance & Scalability

Phase 3

Page 43: WordPress Performance & Scalability

A Good Start.But Wait, There’s More!

Page 44: WordPress Performance & Scalability

MySQL Replication• Master/Slave - one-way asynchronous

replication

• Send writes to the master, reads to the slave

• Replication works with all tables types

• One master can support any number of slaves

• Fairly easy to setup

Page 45: WordPress Performance & Scalability

Enter HyperDB• Drop in replacement for the standard

WordPress database class

• Supports distributed read/writes (database replication - master/slave)

• Can partition data (helpful for large WPMU installs)

• Will failover to other database servers via multiple routes

• http://codex.wordpress.org/HyperDB

Page 46: WordPress Performance & Scalability

Phase 4

Page 47: WordPress Performance & Scalability

If You Call Now....

You’ll get web server load balancing too

Page 48: WordPress Performance & Scalability

Phase 5

Page 49: WordPress Performance & Scalability

Why This Works

No server side session storage

Page 50: WordPress Performance & Scalability

Variations on a Theme

• Master/Relay/Slaves

• Slave just for backups

• Multiple data centers

• Multiple Memcache servers

• Separate web servers for front end and back end

Page 51: WordPress Performance & Scalability

Things Start To Get Interesting

WordPress as an application platform

Page 52: WordPress Performance & Scalability

Questions?